diff options
| author | Daiderd Jordan <daiderd@gmail.com> | 2018-10-26 15:49:24 +0100 |
|---|---|---|
| committer | Daiderd Jordan <daiderd@gmail.com> | 2018-10-26 15:49:24 +0100 |
| commit | 95fb1cb2aa1781b239db074dcc9b15089b55e118 (patch) | |
| tree | 1057761c2f704778ca0d4cfe90054c4f8f916e39 /modules | |
| parent | 79d356909bd34ca52e44d44f279db784247b46d2 (diff) | |
nix: make channel entries for NIX_PATH dynamic
This avoids warnings like this if the root or user channel profiles
don't exist.
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/nix/default.nix | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/modules/nix/default.nix b/modules/nix/default.nix index 6ad33ba..30c1694 100644 --- a/modules/nix/default.nix +++ b/modules/nix/default.nix @@ -315,13 +315,23 @@ in default = [ # Include default path <darwin-config>. "darwin-config=${config.environment.darwinConfig}" - "/nix/var/nix/profiles/per-user/root/channels" - "$HOME/.nix-defexpr/channels" ]; description = '' The default Nix expression search path, used by the Nix evaluator to look up paths enclosed in angle brackets - (e.g. <literal><nixpkgs></literal>). + (e.g. <literal><nixpkgs></literal>). This value gets + extended with user and/or root channels if those exist and + nix.enableChannels isn't disabled. + ''; + }; + + nix.enableChannels = mkOption { + type = types.bool; + default = true; + description = '' + Whether to extend <envar>NIX_PATH</envar> with <filename>~/.nix-defexpr/channels</filename> + and <filename>/nix/var/nix/profiles/per-user/root/channels</filename> + if they exist. ''; }; }; @@ -394,6 +404,14 @@ in if [ ! -w /nix/var/nix/db ]; then export NIX_REMOTE=daemon fi + '' + optionalString cfg.enableChannels '' + # Set up NIX_PATH with root and/or user channels. + if [ -d "$HOME/.nix-defexpr/channels" ]; then + export NIX_PATH="''${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels" + fi + if [ -d /nix/var/nix/profiles/per-user/root/channels ]; then + export NIX_PATH="''${NIX_PATH:+$NIX_PATH:}/nix/var/nix/profiles/per-user/root/channels" + fi ''; # Set up the environment variables for running Nix. |
