1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-16 13:28:16 +00:00

Merge pull request #1026 from thecaralice/nochan

Allow disabling channels
This commit is contained in:
Michael Hoang 2024-08-17 11:59:09 +10:00 committed by GitHub
commit 076b9a905a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 60 additions and 28 deletions

View file

@ -16,6 +16,10 @@ let
in in
{ {
imports = [
(mkRenamedOptionModule ["environment" "postBuild"] ["environment" "extraSetup"])
];
options = { options = {
environment.systemPackages = mkOption { environment.systemPackages = mkOption {
type = types.listOf types.package; type = types.listOf types.package;
@ -43,12 +47,6 @@ in
description = "A list of profiles used to setup the global environment."; 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 { environment.extraOutputsToInstall = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [];
@ -147,6 +145,17 @@ in
''; '';
type = types.lines; 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 = { config = {
@ -188,7 +197,8 @@ in
system.path = pkgs.buildEnv { system.path = pkgs.buildEnv {
name = "system-path"; name = "system-path";
paths = cfg.systemPackages; paths = cfg.systemPackages;
inherit (cfg) postBuild pathsToLink extraOutputsToInstall; postBuild = cfg.extraSetup;
inherit (cfg) pathsToLink extraOutputsToInstall;
}; };
system.build.setEnvironment = pkgs.writeText "set-environment" '' system.build.setEnvironment = pkgs.writeText "set-environment" ''
@ -205,6 +215,5 @@ in
system.build.setAliases = pkgs.writeText "set-aliases" '' system.build.setAliases = pkgs.writeText "set-aliases" ''
${concatStringsSep "\n" aliasCommands} ${concatStringsSep "\n" aliasCommands}
''; '';
}; };
} }

View file

@ -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 # Definition differs substantially from NixOS module
nixPath = mkOption { nixPath = mkOption {
type = nixPathType; 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>. # Include default path <darwin-config>.
{ darwin-config = "${config.environment.darwinConfig}"; } { darwin-config = "''${config.environment.darwinConfig}"; }
"/nix/var/nix/profiles/per-user/root/channels" "/nix/var/nix/profiles/per-user/root/channels"
]; ]
'';
description = '' description = ''
The default Nix expression search path, used by the Nix The default Nix expression search path, used by the Nix
evaluator to look up paths enclosed in angle brackets evaluator to look up paths enclosed in angle brackets
@ -744,27 +768,21 @@ in
]; ];
# Not in NixOS module # Not in NixOS module
nix.nixPath = mkMerge [ nix.nixPath = mkIf (config.system.stateVersion < 2) (mkDefault [
(mkIf (config.system.stateVersion < 2) (mkDefault "darwin=$HOME/.nix-defexpr/darwin"
[ "darwin=$HOME/.nix-defexpr/darwin" "darwin-config=$HOME/.nixpkgs/darwin-configuration.nix"
"darwin-config=$HOME/.nixpkgs/darwin-configuration.nix" "/nix/var/nix/profiles/per-user/root/channels"
"/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"
]))
];
# Set up the environment variables for running Nix. # Set up the environment variables for running Nix.
environment.variables = cfg.envVars // { NIX_PATH = cfg.nixPath; }; environment.variables = cfg.envVars // { NIX_PATH = cfg.nixPath; };
environment.extraInit = environment.extraInit = mkMerge [
'' (mkIf cfg.channel.enable ''
if [ -e "$HOME/.nix-defexpr/channels" ]; then if [ -e "$HOME/.nix-defexpr/channels" ]; then
export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}" export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}"
fi fi
'' + '')
# Not in NixOS module # Not in NixOS module
'' ''
# Set up secure multi-user builds: non-root users build through the # Set up secure multi-user builds: non-root users build through the
@ -772,7 +790,12 @@ in
if [ ! -w /nix/var/nix/db ]; then if [ ! -w /nix/var/nix/db ]; then
export NIX_REMOTE=daemon export NIX_REMOTE=daemon
fi 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)); nix.nrBuildUsers = mkDefault (max 32 (if cfg.settings.max-jobs == "auto" then 0 else cfg.settings.max-jobs));

View file

@ -22,7 +22,7 @@ in
environment.pathsToLink = [ "/info" "/share/info" ]; environment.pathsToLink = [ "/info" "/share/info" ];
environment.extraOutputsToInstall = [ "info" ]; environment.extraOutputsToInstall = [ "info" ];
environment.postBuild = '' environment.extraSetup = ''
if test -w $out/share/info; then if test -w $out/share/info; then
shopt -s nullglob shopt -s nullglob
for i in $out/share/info/*.info $out/share/info/*.info.gz; do for i in $out/share/info/*.info $out/share/info/*.info.gz; do

View file

@ -236,7 +236,7 @@ in
system.checks.verifyNixChannels = mkOption { system.checks.verifyNixChannels = mkOption {
type = types.bool; type = types.bool;
default = true; default = config.nix.channel.enable;
description = "Whether to run the nix-channels validation checks."; description = "Whether to run the nix-channels validation checks.";
}; };