nixos/config/nix-channel: Factor out root channel initialization

This commit is contained in:
Robert Hensing 2023-07-05 13:53:25 +02:00
parent 1c772cd857
commit 5c0c96a828
4 changed files with 36 additions and 12 deletions

View File

@ -0,0 +1,35 @@
{ config, lib, ... }:
let
inherit (lib)
mkIf
mkOption
stringAfter
types
;
cfg = config.nix;
in
{
options = {
system = {
defaultChannel = mkOption {
internal = true;
type = types.str;
default = "https://nixos.org/channels/nixos-unstable";
description = lib.mdDoc "Default NixOS channel to which the root user is subscribed.";
};
};
};
config = mkIf cfg.enable {
system.activationScripts.nix-channel = stringAfter [ "etc" "users" ]
''
# Subscribe the root user to the NixOS channel by default.
if [ ! -e "/root/.nix-channels" ]; then
echo "${config.system.defaultChannel} nixos" > "/root/.nix-channels"
fi
'';
};
}

View File

@ -140,13 +140,6 @@ in
'';
};
defaultChannel = mkOption {
internal = true;
type = types.str;
default = "https://nixos.org/channels/nixos-unstable";
description = lib.mdDoc "Default NixOS channel to which the root user is subscribed.";
};
configurationRevision = mkOption {
type = types.nullOr types.str;
default = null;

View File

@ -18,6 +18,7 @@
./config/mysql.nix
./config/networking.nix
./config/nix.nix
./config/nix-channel.nix
./config/nix-remote-build.nix
./config/no-x-libs.nix
./config/nsswitch.nix

View File

@ -263,11 +263,6 @@ in
system.activationScripts.nix = stringAfter [ "etc" "users" ]
''
install -m 0755 -d /nix/var/nix/{gcroots,profiles}/per-user
# Subscribe the root user to the NixOS channel by default.
if [ ! -e "/root/.nix-channels" ]; then
echo "${config.system.defaultChannel} nixos" > "/root/.nix-channels"
fi
'';
# Legacy configuration conversion.