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=${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. <nixpkgs>). + (e.g. <nixpkgs>). 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 NIX_PATH with ~/.nix-defexpr/channels + and /nix/var/nix/profiles/per-user/root/channels + 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.