From 10e3158534d54947df2c53684d3d29bb268c09de Mon Sep 17 00:00:00 2001 From: doug-q <141026920+doug-q@users.noreply.github.com> Date: Tue, 14 May 2024 14:58:59 +0100 Subject: [PATCH] chore: add devenv option to not install git hooks (#1015) Tested with and without a `devenv.local.nix` with ``` { hugr.installGitHooks = false; } ``` --- devenv.nix | 85 ++++++++++++++++++++++++++++++------------------------ justfile | 3 +- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/devenv.nix b/devenv.nix index a37649f04..fab5a63cc 100644 --- a/devenv.nix +++ b/devenv.nix @@ -1,52 +1,61 @@ -{ pkgs, lib, inputs, ... }: +{ pkgs, lib, inputs, config, ... }: let pkgs-stable = import inputs.nixpkgs-stable { system = pkgs.stdenv.system; }; + cfg = config.hugr; in { - # https://devenv.sh/packages/ - # on macos frameworks have to be explicitly specified - # otherwise a linker error ocurs on rust packages - packages = [ - pkgs.just - pkgs.llvmPackages_16.libllvm - # cargo-llvm-cov is currently marked broken on nixpkgs unstable - pkgs-stable.cargo-llvm-cov - ] ++ lib.optionals - pkgs.stdenv.isDarwin - (with pkgs.darwin.apple_sdk; [ - frameworks.CoreServices - frameworks.CoreFoundation - # added for json schema validation tests - frameworks.SystemConfiguration - ]); + options.hugr = { + setupInShell = lib.mkEnableOption "setupInShell" // { + default = true; + description = "run `just setup` on entering shell"; + }; + }; - # https://devenv.sh/scripts/ - scripts.hello.exec = "echo Welcome to hugr dev shell!"; + config = { + # https://devenv.sh/packages/ + # on macos frameworks have to be explicitly specified + # otherwise a linker error ocurs on rust packages + packages = [ + pkgs.just + pkgs.llvmPackages_16.libllvm + # cargo-llvm-cov is currently marked broken on nixpkgs unstable + pkgs-stable.cargo-llvm-cov + ] ++ lib.optionals + pkgs.stdenv.isDarwin + (with pkgs.darwin.apple_sdk; [ + frameworks.CoreServices + frameworks.CoreFoundation + # added for json schema validation tests + frameworks.SystemConfiguration + ]); - enterShell = '' - hello - cargo --version - export LLVM_COV="${pkgs.llvmPackages_16.libllvm}/bin/llvm-cov" - export LLVM_PROFDATA="${pkgs.llvmPackages_16.libllvm}/bin/llvm-profdata" + # https://devenv.sh/scripts/ + scripts.hello.exec = "echo Welcome to hugr dev shell!"; - just setup - ''; + enterShell = '' + hello + cargo --version + export LLVM_COV="${pkgs.llvmPackages_16.libllvm}/bin/llvm-cov" + export LLVM_PROFDATA="${pkgs.llvmPackages_16.libllvm}/bin/llvm-profdata" + '' + lib.optionalString cfg.setupInShell '' + just setup + ''; - languages.python = { - enable = true; - poetry = { + languages.python = { enable = true; - activate.enable = true; + poetry = { + enable = true; + activate.enable = true; + }; }; - }; - # https://devenv.sh/languages/ - # https://devenv.sh/reference/options/#languagesrustversion - languages.rust = { - channel = "stable"; - enable = true; - components = [ "rustc" "cargo" "clippy" "rustfmt" "rust-analyzer" ]; + # https://devenv.sh/languages/ + # https://devenv.sh/reference/options/#languagesrustversion + languages.rust = { + channel = "stable"; + enable = true; + components = [ "rustc" "cargo" "clippy" "rustfmt" "rust-analyzer" ]; + }; }; - # See full reference at https://devenv.sh/reference/options/ } diff --git a/justfile b/justfile index 474ffc1c2..d1acff4c8 100644 --- a/justfile +++ b/justfile @@ -6,7 +6,8 @@ help: # setting up the pre-commit hooks. setup: poetry install - poetry run pre-commit install -t pre-commit + # setup git hooks unless environment variable HUGR_JUST_INHIBIT_GIT_HOOKS is non-empty + [[ -z $HUGR_JUST_INHIBIT_GIT_HOOKS ]] && poetry run pre-commit install -t pre-commit || true # Run the pre-commit checks. check: