From cb08d3dd72f51fd20d26c823204faa11d742cfe1 Mon Sep 17 00:00:00 2001 From: nikstur Date: Tue, 17 Oct 2023 21:39:51 +0200 Subject: [PATCH] nixos/nix-channel: replace activationScript via tmpfiles --- nixos/modules/config/nix-channel.nix | 11 ++++------- nixos/tests/activation/nix-channel.nix | 16 ++++++++++++++++ nixos/tests/all-tests.nix | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 nixos/tests/activation/nix-channel.nix diff --git a/nixos/modules/config/nix-channel.nix b/nixos/modules/config/nix-channel.nix index 3f8e088ede92..4abc846b0858 100644 --- a/nixos/modules/config/nix-channel.nix +++ b/nixos/modules/config/nix-channel.nix @@ -97,12 +97,9 @@ in nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault ""); - system.activationScripts.nix-channel = mkIf cfg.channel.enable - (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 - ''); + systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [ + "f /root/.nix-channels -" + ''w "/root/.nix-channels" - - - - "${config.system.defaultChannel} nixos\n"'' + ]; }; } diff --git a/nixos/tests/activation/nix-channel.nix b/nixos/tests/activation/nix-channel.nix new file mode 100644 index 000000000000..8416ff0347ac --- /dev/null +++ b/nixos/tests/activation/nix-channel.nix @@ -0,0 +1,16 @@ +{ lib, ... }: + +{ + + name = "activation-nix-channel"; + + meta.maintainers = with lib.maintainers; [ nikstur ]; + + nodes.machine = { + nix.channel.enable = true; + }; + + testScript = '' + print(machine.succeed("cat /root/.nix-channels")) + ''; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index c92acdebcc85..69f1b912d6b3 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -265,6 +265,7 @@ in { etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; }; activation = pkgs.callPackage ../modules/system/activation/test.nix { }; activation-var = runTest ./activation/var.nix; + activation-nix-channel = runTest ./activation/nix-channel.nix; etcd = handleTestOn ["x86_64-linux"] ./etcd.nix {}; etcd-cluster = handleTestOn ["x86_64-linux"] ./etcd-cluster.nix {}; etebase-server = handleTest ./etebase-server.nix {};