summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hoang <Enzime@users.noreply.github.com>2024-08-17 11:59:09 +1000
committerGitHub <noreply@github.com>2024-08-17 11:59:09 +1000
commit076b9a905af8a52b866c8db068d6da475839d97b (patch)
tree70bfe0ea3d52797674d5283782aa09cad6fdf793
parent91010a5613ffd7ee23ee9263213157a1c422b705 (diff)
parent5afa71b4131a97d72804a97a34bd4a916ea5e990 (diff)
Merge pull request #1026 from thecaralice/nochan
Allow disabling channels
-rw-r--r--modules/environment/default.nix25
-rw-r--r--modules/nix/default.nix59
-rw-r--r--modules/programs/info/default.nix2
-rw-r--r--modules/system/checks.nix2
4 files changed, 60 insertions, 28 deletions
diff --git a/modules/environment/default.nix b/modules/environment/default.nix
index 3b97a3e..00d58c0 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 b5ad114..14668a2 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>.
+ { 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>.
- { 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 cf857d9..d70e377 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 6d9b2cf..ce06e2f 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.";
};