diff --git a/modules/environment/default.nix b/modules/environment/default.nix index 3b97a3ec..00d58c09 100644 --- a/modules/environment/default.nix +++ b/modules/environment/default.nix @@ -16,6 +16,10 @@ let in { + imports = [ + (mkRenamedOptionModule ["environment" "postBuild"] ["environment" "extraSetup"]) + ]; + options = { environment.systemPackages = mkOption { type = types.listOf types.package; @@ -43,12 +47,6 @@ in description = "A list of profiles used to setup the global environment."; }; - environment.postBuild = mkOption { - type = types.lines; - default = ""; - description = "Commands to execute when building the global environment."; - }; - environment.extraOutputsToInstall = mkOption { type = types.listOf types.str; default = []; @@ -147,6 +145,17 @@ in ''; type = types.lines; }; + + environment.extraSetup = mkOption { + type = types.lines; + default = ""; + description = '' + Shell fragments to be run after the system environment has been created. + This should only be used for things that need to modify the internals + of the environment, e.g. generating MIME caches. + The environment being built can be accessed at $out. + ''; + }; }; config = { @@ -188,7 +197,8 @@ in system.path = pkgs.buildEnv { name = "system-path"; paths = cfg.systemPackages; - inherit (cfg) postBuild pathsToLink extraOutputsToInstall; + postBuild = cfg.extraSetup; + inherit (cfg) pathsToLink extraOutputsToInstall; }; system.build.setEnvironment = pkgs.writeText "set-environment" '' @@ -205,6 +215,5 @@ in system.build.setAliases = pkgs.writeText "set-aliases" '' ${concatStringsSep "\n" aliasCommands} ''; - }; } diff --git a/modules/nix/default.nix b/modules/nix/default.nix index b5ad1148..14668a23 100644 --- a/modules/nix/default.nix +++ b/modules/nix/default.nix @@ -380,14 +380,38 @@ in ''; }; + channel = { + enable = mkOption { + description = '' + Whether the `nix-channel` command and state files are made available on the machine. + + The following files are initialized when enabled: + - `/nix/var/nix/profiles/per-user/root/channels` + - `$HOME/.nix-defexpr/channels` (on login) + + Disabling this option will not remove the state files from the system. + ''; + type = types.bool; + default = true; + }; + }; + # Definition differs substantially from NixOS module nixPath = mkOption { type = nixPathType; - default = [ + default = lib.optionals cfg.channel.enable [ + # Include default path . + { darwin-config = "${config.environment.darwinConfig}"; } + "/nix/var/nix/profiles/per-user/root/channels" + ]; + + defaultText = lib.literalExpression '' + lib.optionals cfg.channel.enable [ # Include default path . - { darwin-config = "${config.environment.darwinConfig}"; } + { darwin-config = "''${config.environment.darwinConfig}"; } "/nix/var/nix/profiles/per-user/root/channels" - ]; + ] + ''; description = '' The default Nix expression search path, used by the Nix evaluator to look up paths enclosed in angle brackets @@ -744,27 +768,21 @@ in ]; # Not in NixOS module - nix.nixPath = mkMerge [ - (mkIf (config.system.stateVersion < 2) (mkDefault - [ "darwin=$HOME/.nix-defexpr/darwin" - "darwin-config=$HOME/.nixpkgs/darwin-configuration.nix" - "/nix/var/nix/profiles/per-user/root/channels" - ])) - (mkIf (config.system.stateVersion > 3) (mkOrder 1200 - [ { darwin-config = "${config.environment.darwinConfig}"; } - "/nix/var/nix/profiles/per-user/root/channels" - ])) - ]; + nix.nixPath = mkIf (config.system.stateVersion < 2) (mkDefault [ + "darwin=$HOME/.nix-defexpr/darwin" + "darwin-config=$HOME/.nixpkgs/darwin-configuration.nix" + "/nix/var/nix/profiles/per-user/root/channels" + ]); # Set up the environment variables for running Nix. environment.variables = cfg.envVars // { NIX_PATH = cfg.nixPath; }; - environment.extraInit = - '' + environment.extraInit = mkMerge [ + (mkIf cfg.channel.enable '' if [ -e "$HOME/.nix-defexpr/channels" ]; then export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}" fi - '' + + '') # Not in NixOS module '' # Set up secure multi-user builds: non-root users build through the @@ -772,7 +790,12 @@ in if [ ! -w /nix/var/nix/db ]; then export NIX_REMOTE=daemon fi - ''; + '' + ]; + + environment.extraSetup = mkIf (!cfg.channel.enable) '' + rm --force $out/bin/nix-channel + ''; nix.nrBuildUsers = mkDefault (max 32 (if cfg.settings.max-jobs == "auto" then 0 else cfg.settings.max-jobs)); diff --git a/modules/programs/info/default.nix b/modules/programs/info/default.nix index cf857d9f..d70e3770 100644 --- a/modules/programs/info/default.nix +++ b/modules/programs/info/default.nix @@ -22,7 +22,7 @@ in environment.pathsToLink = [ "/info" "/share/info" ]; environment.extraOutputsToInstall = [ "info" ]; - environment.postBuild = '' + environment.extraSetup = '' if test -w $out/share/info; then shopt -s nullglob for i in $out/share/info/*.info $out/share/info/*.info.gz; do diff --git a/modules/system/checks.nix b/modules/system/checks.nix index 6d9b2cfd..ce06e2fb 100644 --- a/modules/system/checks.nix +++ b/modules/system/checks.nix @@ -236,7 +236,7 @@ in system.checks.verifyNixChannels = mkOption { type = types.bool; - default = true; + default = config.nix.channel.enable; description = "Whether to run the nix-channels validation checks."; };