From 5c0c96a8283de416891bb4f8fd67c6e5693ac1a2 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 5 Jul 2023 13:53:25 +0200 Subject: nixos/config/nix-channel: Factor out root channel initialization --- nixos/modules/config/nix-channel.nix | 35 ++++++++++++++++++++++++++++++ nixos/modules/misc/version.nix | 7 ------ nixos/modules/module-list.nix | 1 + nixos/modules/services/misc/nix-daemon.nix | 5 ----- 4 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 nixos/modules/config/nix-channel.nix diff --git a/nixos/modules/config/nix-channel.nix b/nixos/modules/config/nix-channel.nix new file mode 100644 index 00000000000..8e6061e4956 --- /dev/null +++ b/nixos/modules/config/nix-channel.nix @@ -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 + ''; + }; +} diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index 0f55ab8a09c..0a66eafe933 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -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; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 75b0e19d558..fea69935cc6 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -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 diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix index 94798dfb539..4e986b217ef 100644 --- a/nixos/modules/services/misc/nix-daemon.nix +++ b/nixos/modules/services/misc/nix-daemon.nix @@ -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. -- cgit 1.4.1