Skip to content

Commit

Permalink
Merge pull request #1026 from thecaralice/nochan
Browse files Browse the repository at this point in the history
Allow disabling channels
  • Loading branch information
Enzime authored Aug 17, 2024
2 parents 91010a5 + 5afa71b commit 076b9a9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 28 deletions.
25 changes: 17 additions & 8 deletions modules/environment/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ let
in

{
imports = [
(mkRenamedOptionModule ["environment" "postBuild"] ["environment" "extraSetup"])
];

options = {
environment.systemPackages = mkOption {
type = types.listOf types.package;
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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" ''
Expand All @@ -205,6 +215,5 @@ in
system.build.setAliases = pkgs.writeText "set-aliases" ''
${concatStringsSep "\n" aliasCommands}
'';

};
}
59 changes: 41 additions & 18 deletions modules/nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -744,35 +768,34 @@ 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
# Nix daemon.
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));

Expand Down
2 changes: 1 addition & 1 deletion modules/programs/info/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/system/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
};

Expand Down

0 comments on commit 076b9a9

Please sign in to comment.