diff options
| author | Quentin Aristote <quentin@aristote.fr> | 2021-12-11 18:45:27 +0100 |
|---|---|---|
| committer | Quentin Aristote <quentin@aristote.fr> | 2021-12-11 18:45:27 +0100 |
| commit | e7f7acb536f827628316a16d5429fd2ff4331671 (patch) | |
| tree | 69c7327dcbf95ce79fafa8e7988c3aed2840e9f3 /modules | |
| parent | c2bbd32ad4f00316e19b3b3c045c159215e21942 (diff) | |
add pinDerivations option
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/default.nix | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/modules/default.nix b/modules/default.nix index a11fbda..da31602 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,8 +3,15 @@ with lib; let cfg = config; in { - imports = - [ ./coq.nix ./golang.nix ./latex.nix ./nix.nix ./python.nix ./ocaml.nix ./why3.nix ]; + imports = [ + ./coq.nix + ./golang.nix + ./latex.nix + ./nix.nix + ./python.nix + ./ocaml.nix + ./why3.nix + ]; options = { # Inputs @@ -81,7 +88,7 @@ in { .direnv/aliases. They may then take arguments. This also means that "recursive" aliases (e.g. ssh="export A=something ssh") will fail ; the executable in the definition should be called by its full path (e.g. - $\{pkgs.openssh\}/bin/ssh). + $\{pkgs.openssh\}/bin/ssh). ''; example = literalExample '' { zz = "ls -la"; }; @@ -90,7 +97,26 @@ in { # Misc ## Whether the shell is to be loaded by direnv - direnv.enable = mkEnableOption "direnv"; + direnv.enable = mkEnableOption "direnv" // { + description = '' + Whether the shell is to be loaded by direnv. + ''; + }; + pinDerivations = mkEnableOption "dependencies derivation pinning" // { + description = '' + Whether to pin the shell dependencies in a snapshot that will not be + garbage collected. + + From https://nixos.wiki/wiki/Storage_optimization#Pinning : + This will create a persistent snapshot of your shell.nix dependencies, + which then won't be garbage collected, as long as you have configured + keep-outputs = true (and haven't changed the default of + keep-derivations = true). This is useful if your project has a + dependency with no substitutes available, or you don't want to spend + time waiting to re-download your dependencies every time you enter the + shell. + ''; + }; # Hooks shellHook = mkOption { @@ -117,9 +143,10 @@ in { }; config.shellHook = concatStringsSep "\n" ( - # Environment variables are declared in a shell hook because simply adding the - # top-level arguments of pkgs.mkShell ovewrites the old values of the - # variables, which may be a problem, for example for PATH. + # envVars + ## Environment variables are declared in a shell hook because simply adding the + ## top-level arguments of pkgs.mkShell ovewrites the old values of the + ## variables, which may be a problem, for example for PATH. (let dollar = "$"; makeEnvVarCommand = name: @@ -129,11 +156,12 @@ in { optionalString (!reset) (''"${dollar}${name}":'') }"${value}"''; in (attrValues (mapAttrs makeEnvVarCommand cfg.envVars))) + # aliases ++ (if cfg.direnv.enable then (let aliasDir = ''"$PWD"/.direnv/aliases''; makeAliasCommand = name: value: - let target = ''${aliasDir}/${name}''; + let target = "${aliasDir}/${name}"; in '' echo '#!${pkgs.bash}/bin/bash -e' > "${target}" echo "${value}" >> "${target}" @@ -146,5 +174,10 @@ in { ''] ++ (attrValues (mapAttrs makeAliasCommand cfg.aliases)))) else (let makeAliasCommand = name: value: ''alias "${name}"="${value}"''; - in (attrValues (mapAttrs makeAliasCommand cfg.aliases))))); + in (attrValues (mapAttrs makeAliasCommand cfg.aliases)))) + # pinDerivations + ++ (optional cfg.pinDerivations '' + rm -rf .nix-gc-roots + ${pkgs.nix}/bin/nix-instantiate shell.nix --indirect --add-root ./.nix-gc-roots/shell.drv + '')); } |
