Files
lix/tests/nixos/nix-upgrade-nix.nix
T
Justin !andTom Hubrecht 32d7c02b96 nixpkgs: bump to 25.11
This bump nixpkgs input to 25.11 and fix the two warnings that were
coming with the update:

1. `pkgs.system` => `pkgs.stdenv.hostPlatform.system`
2. `runCommandNoCC` => `runCommand`

also:

1. remove cppnix 2.3 compat tests (cppnix 2.3 is officially dead now)
2. remove lowdown 1.3 compat tests (nixpkgs no longer carries it)

Co-authored-by: Tom Hubrecht <github@mail.hubrecht.ovh>

Change-Id: I78526b5d8992a6c63ecd7f0c7c1fa6346a6a6964
2025-12-17 20:59:59 +01:00

80 lines
2.7 KiB
Nix

{ lib, config, ... }:
/**
* Test that nix upgrade-nix works regardless of whether /nix/var/nix/profiles/default
* is a nix-env style profile or a nix profile style profile.
*/
let
pkgs = config.nodes.machine.nixpkgs.pkgs;
lix = pkgs.lixPackageSets.stable.lix;
lixVersion = lib.getVersion lix;
newNix = pkgs.nix;
newNixVersion = lib.getVersion newNix;
in {
name = "nix-upgrade-nix";
nodes = {
machine = { config, lib, pkgs, ... }: {
virtualisation.writableStore = true;
virtualisation.additionalPaths = [ pkgs.hello.drvPath newNix ];
nix.settings.substituters = lib.mkForce [ ];
nix.settings.experimental-features = [ "nix-command" "flakes" ];
services.getty.autologinUser = "root";
nix.package = lix;
};
};
testScript = { nodes }: ''
# fmt: off
start_all()
machine.succeed("nix --version >&2")
# Use Lix to install newNix into the default profile, overriding /run/current-system/sw/bin/nix
machine.succeed("nix-env --install '${lib.getBin newNix}' --profile /nix/var/nix/profiles/default")
# Make sure that correctly got inserted into our PATH.
default_profile_nix_path = machine.succeed("command -v nix")
print(default_profile_nix_path)
assert default_profile_nix_path.strip() == "/nix/var/nix/profiles/default/bin/nix", \
f"{default_profile_nix_path.strip()=} != /nix/var/nix/profiles/default/bin/nix"
# And that it's the Nix we specified
default_profile_version = machine.succeed("nix --version")
assert "${newNixVersion}" in default_profile_version, f"${newNixVersion} not in {default_profile_version}"
# Now upgrade to latest Lix, and make sure that worked.
machine.succeed("${lib.getExe lix} upgrade-nix --debug --store-path ${lix} 2>&1")
default_profile_version = machine.succeed("nix --version")
print(default_profile_version)
assert "${lixVersion}" in default_profile_version, f"${lixVersion} not in {default_profile_version}"
# Now 'break' this profile -- use nix profile on it so nix-env will no longer work on it.
machine.succeed(
"nix profile install --profile /nix/var/nix/profiles/default '${pkgs.hello.drvPath}^*' >&2"
)
# Confirm that nix-env is broken.
machine.fail(
"nix-env --query --installed --profile /nix/var/nix/profiles/default >&2"
)
# And use nix upgrade-nix one more time, on the `nix profile` style profile.
# (Specifying Lix by full path so we can use --store-path.)
machine.succeed(
"${lib.getBin lix}/bin/nix upgrade-nix --store-path '${lix}' >&2"
)
default_profile_version = machine.succeed("nix --version")
print(default_profile_version)
assert "${lixVersion}" in default_profile_version, f"${lixVersion} not in {default_profile_version}"
'';
}