summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2024-07-16 22:00:16 +0200
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2024-07-28 11:31:42 +0000
commit5c3491ba46526b9a5cc76411962bcbb1dabec781 (patch)
tree49e1f285b4786ea1fe1fef30bec7a39ab83e30ba
parentnixosTests.installer.switchToFlake: It is probably really stupid (diff)
downloadnixpkgs-origin/backport-323613-to-release-24.05.tar.gz
nixos/nix-channel.nix: shellcheck and fix the activation checkorigin/backport-323613-to-release-24.05
(cherry picked from commit 2d9a6864833e3cca4b05aa6bd4ef88c8813989ca)
-rw-r--r--nixos/modules/config/nix-channel.nix22
-rw-r--r--nixos/modules/config/nix-channel/activation-check.sh21
-rw-r--r--nixos/modules/config/nix-channel/test.nix19
-rw-r--r--nixos/tests/all-tests.nix1
4 files changed, 42 insertions, 21 deletions
diff --git a/nixos/modules/config/nix-channel.nix b/nixos/modules/config/nix-channel.nix
index 5cd7095c85b5..ff8eca01cac8 100644
--- a/nixos/modules/config/nix-channel.nix
+++ b/nixos/modules/config/nix-channel.nix
@@ -100,26 +100,6 @@ in
];
system.activationScripts.no-nix-channel = mkIf (!cfg.channel.enable)
- (stringAfter [ "etc" "users" ] ''
- explainChannelWarning=0
- if [ -e "/root/.nix-defexpr/channels" ]; then
- warn '/root/.nix-defexpr/channels exists, but channels have been disabled.'
- explainChannelWarning=1
- fi
- if [ -e "/nix/var/nix/profiles/per-user/root/channels" ]; then
- warn "/nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled."
- explainChannelWarning=1
- fi
- getent passwd | while IFS=: read -r _ _ _ _ _ home _ ; do
- if [ -n "$home" -a -e "$home/.nix-defexpr/channels" ]; then
- warn "$home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2
- explainChannelWarning=1
- fi
- done
- if [ $explainChannelWarning -eq 1 ]; then
- echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2
- echo "Delete the above directory or directories to prevent this." 1>&2
- fi
- '');
+ (stringAfter [ "etc" "users" ] (builtins.readFile ./nix-channel/activation-check.sh));
};
}
diff --git a/nixos/modules/config/nix-channel/activation-check.sh b/nixos/modules/config/nix-channel/activation-check.sh
new file mode 100644
index 000000000000..42b1b712d702
--- /dev/null
+++ b/nixos/modules/config/nix-channel/activation-check.sh
@@ -0,0 +1,21 @@
+# shellcheck shell=bash
+
+explainChannelWarning=0
+if [[ -e "/root/.nix-defexpr/channels" ]]; then
+ warn '/root/.nix-defexpr/channels exists, but channels have been disabled.'
+ explainChannelWarning=1
+fi
+if [[ -e "/nix/var/nix/profiles/per-user/root/channels" ]]; then
+ warn "/nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled."
+ explainChannelWarning=1
+fi
+while IFS=: read -r _ _ _ _ _ home _ ; do
+ if [[ -n "$home" && -e "$home/.nix-defexpr/channels" ]]; then
+ warn "$home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2
+ explainChannelWarning=1
+ fi
+done < <(getent passwd)
+if [[ $explainChannelWarning -eq 1 ]]; then
+ echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2
+ echo "Delete the above directory or directories to prevent this." 1>&2
+fi
diff --git a/nixos/modules/config/nix-channel/test.nix b/nixos/modules/config/nix-channel/test.nix
new file mode 100644
index 000000000000..4b00cf9db3c4
--- /dev/null
+++ b/nixos/modules/config/nix-channel/test.nix
@@ -0,0 +1,19 @@
+# Run:
+# nix-build -A nixosTests.nix-channel
+{ lib, testers }:
+let
+ inherit (lib) fileset;
+
+ runShellcheck = testers.shellcheck {
+ src = fileset.toSource {
+ root = ./.;
+ fileset = fileset.unions [
+ ./activation-check.sh
+ ];
+ };
+ };
+
+in
+lib.recurseIntoAttrs {
+ inherit runShellcheck;
+}
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 624fb6813517..f544210485fd 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -607,6 +607,7 @@ in {
nbd = handleTest ./nbd.nix {};
ncdns = handleTest ./ncdns.nix {};
ndppd = handleTest ./ndppd.nix {};
+ nix-channel = pkgs.callPackage ../modules/config/nix-channel/test.nix { };
nebula = handleTest ./nebula.nix {};
netbird = handleTest ./netbird.nix {};
nimdow = handleTest ./nimdow.nix {};