diff --git a/packaging/hydra.nix b/packaging/hydra.nix index 8bc9a7a7dc8..2c8859eb6eb 100644 --- a/packaging/hydra.nix +++ b/packaging/hydra.nix @@ -304,12 +304,14 @@ rec { system: let pkgs = nixpkgsFor.${system}.native; + nix-1_11 = pkgs.callPackage ./testing/nix-1.11.nix { }; in pkgs.runCommand "install-tests" { againstSelf = testNixVersions pkgs pkgs.nix; againstCurrentLatest = # FIXME: temporarily disable this on macOS because of #3605. if system == "x86_64-linux" then testNixVersions pkgs pkgs.nixVersions.latest else null; + against-1_11 = if system == "x86_64-linux" then testNixVersions pkgs nix-1_11 else null; # Disabled because the latest stable version doesn't handle # `NIX_DAEMON_SOCKET_PATH` which is required for the tests to work # againstLatestStable = testNixVersions pkgs pkgs.nixStable; diff --git a/packaging/testing/nix-1.11-socket-path.patch b/packaging/testing/nix-1.11-socket-path.patch new file mode 100644 index 00000000000..c38626bb8dd --- /dev/null +++ b/packaging/testing/nix-1.11-socket-path.patch @@ -0,0 +1,14 @@ +diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc +--- a/src/libstore/globals.cc ++++ b/src/libstore/globals.cc +@@ -77,7 +77,9 @@ void Settings::processEnvironment() + nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR)); + nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR)); + nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR)); +- nixDaemonSocketFile = canonPath(nixStateDir + DEFAULT_SOCKET_PATH); ++ nixDaemonSocketFile = canonPath( ++ getEnv("NIX_DAEMON_SOCKET_PATH", ++ nixStateDir + DEFAULT_SOCKET_PATH)); + + // should be set with the other config options, but depends on nixLibexecDir + #ifdef __APPLE__ diff --git a/packaging/testing/nix-1.11.nix b/packaging/testing/nix-1.11.nix new file mode 100644 index 00000000000..73c47e2c6ac --- /dev/null +++ b/packaging/testing/nix-1.11.nix @@ -0,0 +1,104 @@ +# Build Nix 1.11.x from the 1.11-maintenance branch for compatibility testing. +# Not directly exposed, for testing only. +# See .#checks.x86_64-linux.installTests.against-1_11 +{ + lib, + stdenv, + fetchFromGitHub, + autoreconfHook, + autoconf-archive, + bison, + flex, + curl, + perl, + perlPackages, + bzip2, + xz, + openssl, + pkg-config, + sqlite, + boehmgc, + libseccomp, + libsodium, +}: + +stdenv.mkDerivation { + pname = "nix"; + version = "1.11.16"; + + src = fetchFromGitHub { + owner = "NixOS"; + repo = "nix"; + rev = "c6e15c43222cbec54969322b863c9eb426f58499"; # 1.11.16 + hash = "sha256-hGZ/Dvm2s6QIQsyDLlxDetC7qGExxDwMkWYk5E2+oj8="; + }; + + nativeBuildInputs = [ + autoreconfHook + autoconf-archive + bison + flex + pkg-config + ]; + + buildInputs = [ + curl + perl + bzip2 + xz + openssl + sqlite + boehmgc + ] + ++ lib.optional stdenv.hostPlatform.isLinux libseccomp + ++ lib.optional (stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin) libsodium; + + configureFlags = [ + "--disable-init-state" + "--with-dbi=${perlPackages.DBI}/${perl.libPrefix}" + "--with-dbd-sqlite=${perlPackages.DBDSQLite}/${perl.libPrefix}" + "--with-www-curl=${perlPackages.WWWCurl}/${perl.libPrefix}" + "--enable-gc" + "--sysconfdir=${placeholder "out"}/etc" + ]; + + makeFlags = [ + "profiledir=$(out)/etc/profile.d" + ]; + + installFlags = [ + "sysconfdir=$(out)/etc" + ]; + + enableParallelBuilding = true; + + patches = [ + # Support NIX_DAEMON_SOCKET_PATH for compatibility tests + ./nix-1.11-socket-path.patch + ]; + + postPatch = '' + # -Wno-unneeded-internal-declaration and -Wno-deprecated-register are clang-only + sed -i 's/-Wno-unneeded-internal-declaration//' local.mk + sed -i 's/-Wno-deprecated-register//' src/libexpr/local.mk + # Missing for uint32_t/uint64_t (implicit headers changed in GCC 11+) + sed -i '1i #include ' src/libutil/serialise.hh src/libexpr/attr-set.hh + # Don't build docs (missing docbook dependencies) + sed -i '/doc\/manual/d' Makefile + ''; + # Shift-count-overflow warnings in serialise.hh (32-bit time_t code paths) + env.NIX_CFLAGS_COMPILE = "-Wno-error=shift-count-overflow"; + # bdw-gc C++ support (GC_throw_bad_alloc) is in separate library + env.NIX_LDFLAGS = "-lgccpp"; + + # Tests require a functional /nix/store + doCheck = false; + doInstallCheck = false; + + meta = { + description = "Nix 1.11.x for compatibility testing"; + homepage = "https://nixos.org/nix/"; + license = lib.licenses.lgpl21Plus; + platforms = lib.platforms.unix; + }; +} diff --git a/tests/functional/build.sh b/tests/functional/build.sh index 702783678b2..faee19619d2 100755 --- a/tests/functional/build.sh +++ b/tests/functional/build.sh @@ -198,6 +198,11 @@ elif isDaemonNewer "2.29pre"; then <<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'" <<<"$out" grepQuiet -E "Reason: 1 dependency failed." <<<"$out" grepQuiet -E "Build failed due to failed dependency" +elif ! isDaemonNewer "2.0"; then + # Observed with Nix 1.11.16: new client with very old daemon still produces new-style messages. + # TODO: if the `else` branch (2.0 to 2.29pre) also produces new-style messages, merge these branches. + <<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'" + <<<"$out" grepQuiet -E "Reason: 1 dependency failed." else <<<"$out" grepQuiet -E "error: 1 dependencies of derivation '.*-x4\\.drv' failed to build" fi @@ -211,6 +216,11 @@ test "$status" = 1 if isDaemonNewer "2.29pre"; then <<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'" <<<"$out" grepQuiet -E "Reason: 2 dependencies failed." +elif ! isDaemonNewer "2.0"; then + # Observed with Nix 1.11.16: new client with very old daemon still produces new-style messages. + # TODO: if the `else` branch (2.0 to 2.29pre) also produces new-style messages, merge these branches. + <<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'" + <<<"$out" grepQuiet -E "Reason: 2 dependencies failed." else <<<"$out" grepQuiet -E "error: 2 dependencies of derivation '.*-x4\\.drv' failed to build" fi diff --git a/tests/functional/common/functions.sh b/tests/functional/common/functions.sh index 771bbca785b..1acb653e097 100644 --- a/tests/functional/common/functions.sh +++ b/tests/functional/common/functions.sh @@ -135,7 +135,12 @@ isDaemonNewer () { [[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0 local requiredVersion="$1" local daemonVersion - daemonVersion=$("$NIX_DAEMON_PACKAGE/bin/nix" daemon --version | cut -d' ' -f3) + # Nix 2.4+ has unified 'nix' command; older versions only have nix-store etc. + if [[ -x "$NIX_DAEMON_PACKAGE/bin/nix" ]]; then + daemonVersion=$("$NIX_DAEMON_PACKAGE/bin/nix" daemon --version | cut -d' ' -f3) + else + daemonVersion=$("$NIX_DAEMON_PACKAGE/bin/nix-store" --version | cut -d' ' -f3) + fi [[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]] } diff --git a/tests/functional/common/init.sh b/tests/functional/common/init.sh index 66b44c76f69..0d73e5d5122 100755 --- a/tests/functional/common/init.sh +++ b/tests/functional/common/init.sh @@ -52,15 +52,27 @@ gc-reserved-space = 0 substituters = flake-registry = $TEST_ROOT/registry.json show-trace = true -include nix.conf.extra trusted-users = $(whoami) EOF -cat > "$NIX_CONF_DIR"/nix.conf.extra <> "$NIX_CONF_DIR"/nix.conf < "$NIX_CONF_DIR"/nix.conf.extra <> "$NIX_CONF_DIR"/nix.conf <