From c8b8ab81552ad9a12cb574f74daec6d1444b85e6 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 8 Nov 2023 23:42:19 +0100 Subject: nix: Add fallback paths check to tests --- pkgs/tools/package-management/nix/default.nix | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/pkgs/tools/package-management/nix/default.nix b/pkgs/tools/package-management/nix/default.nix index 0b80cd531d43..08318d6f488d 100644 --- a/pkgs/tools/package-management/nix/default.nix +++ b/pkgs/tools/package-management/nix/default.nix @@ -7,6 +7,7 @@ , fetchurl , fetchpatch , fetchpatch2 +, runCommand , Security , storeDir ? "/nix/store" @@ -112,6 +113,41 @@ let hash = "sha256-s1ybRFCjQaSGj7LKu0Z5g7UiHqdJGeD+iPoQL0vaiS0="; }; + # Intentionally does not support overrideAttrs etc + # Use only for tests that are about the package relation to `pkgs` and/or NixOS. + addTestsShallowly = tests: pkg: pkg // { + tests = pkg.tests // tests; + # In case someone reads the wrong attribute + passthru.tests = pkg.tests // tests; + }; + + addFallbackPathsCheck = pkg: addTestsShallowly + { nix-fallback-paths = + runCommand "test-nix-fallback-paths-version-equals-nix-stable" { + paths = lib.concatStringsSep "\n" (builtins.attrValues (import ../../../../nixos/modules/installer/tools/nix-fallback-paths.nix)); + } '' + # From nix test suite + grepQuietInverse() { + ! grep "$@" > /dev/null + } + if [[ "" != $(grep -v 'nix-${pkg.version}$' <<< "$paths") ]]; then + echo "nix-fallback-paths not up to date with nixVersions.stable (nix-${pkg.version})" + echo "The following paths are not up to date:" + grep -v 'nix-${pkg.version}$' <<< "$paths" + echo + echo "Fix it by running in nixpkgs:" + echo + echo "curl https://releases.nixos.org/nix/nix-${pkg.version}/fallback-paths.nix >nixos/modules/installer/tools/nix-fallback-paths.nix" + echo + exit 1 + else + echo "nix-fallback-paths versions up to date" + touch $out + fi + ''; + } + pkg; + in lib.makeExtensible (self: ({ nix_2_3 = (common rec { version = "2.3.16"; @@ -203,7 +239,7 @@ in lib.makeExtensible (self: ({ else nix; - stable = self.nix_2_18; + stable = addFallbackPathsCheck self.nix_2_18; unstable = self.nix_2_18; } // lib.optionalAttrs config.allowAliases { -- cgit v1.2.3 From 4105d387f4ea4c166713107d4373f9a7903dff79 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 10 Nov 2023 20:13:42 +0100 Subject: nix.tests: Remove dead code Co-authored-by: Artturi --- pkgs/tools/package-management/nix/default.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkgs/tools/package-management/nix/default.nix b/pkgs/tools/package-management/nix/default.nix index 08318d6f488d..2bf354fbc69f 100644 --- a/pkgs/tools/package-management/nix/default.nix +++ b/pkgs/tools/package-management/nix/default.nix @@ -126,10 +126,6 @@ let runCommand "test-nix-fallback-paths-version-equals-nix-stable" { paths = lib.concatStringsSep "\n" (builtins.attrValues (import ../../../../nixos/modules/installer/tools/nix-fallback-paths.nix)); } '' - # From nix test suite - grepQuietInverse() { - ! grep "$@" > /dev/null - } if [[ "" != $(grep -v 'nix-${pkg.version}$' <<< "$paths") ]]; then echo "nix-fallback-paths not up to date with nixVersions.stable (nix-${pkg.version})" echo "The following paths are not up to date:" -- cgit v1.2.3