summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-07-05 13:53:25 +0200
committerRobert Hensing <robert@roberthensing.nl>2023-07-05 14:54:29 +0200
commit5c0c96a8283de416891bb4f8fd67c6e5693ac1a2 (patch)
treef625b5594dcf53e58cfd959d8047cb1aa04a7872
parent1c772cd857b40f86105c99297d7e41d823428c95 (diff)
downloadnixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar
nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.gz
nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.bz2
nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.lz
nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.xz
nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.zst
nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.zip
nixos/config/nix-channel: Factor out root channel initialization
-rw-r--r--nixos/modules/config/nix-channel.nix35
-rw-r--r--nixos/modules/misc/version.nix7
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/misc/nix-daemon.nix5
4 files changed, 36 insertions, 12 deletions
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.