lix/tests/nixos/nix-upgrade-nix.nix
Pierre Bourdon f7b6552699 [resubmit] flake: update nixpkgs pin 23.11->24.05 (+ boehmgc compat changes)
-- message from cl/1418 --

The boehmgc changes are bundled into this commit because doing otherwise
would require an annoying dance of "adding compatibility for < 8.2.6 and
>= 8.2.6" then updating the pin then removing the (now unneeded)
compatibility. It doesn't seem worth the trouble to me given the low
complexity of said changes.

Rebased coroutine-sp-fallback.diff patch taken from https://github.com/NixOS/nixpkgs/pull/317227

-- jade resubmit changes --

This is a resubmission of https://gerrit.lix.systems/c/lix/+/1418, which
was reverted in https://gerrit.lix.systems/c/lix/+/1432 for breaking CI
evaluation without being detected.

I have run `nix flake check -Lv` on this one before submission and it
passes on my machine and crucially without eval errors, so the CI result
should be accurate.

It seems like someone renamed forbiddenDependenciesRegex to
forbiddenDependenciesRegexes in nixpkgs and also changed the type
incompatibly. That's pretty silly, but at least it's just an eval error.

Also, `xonsh` regressed the availability of `xonsh-unwrapped`, but it
was fixed by us in https://github.com/NixOS/nixpkgs/pull/317636, which
is now in our channel, so we update nixpkgs compared to the original
iteration of this to simply get that.

We originally had a regression related to some reorganization of the
nixpkgs lib test suite in which there was broken parameter passing.
This, too, we got quickfixed in nixpkgs, so we don't need any changes
for it: https://github.com/NixOS/nixpkgs/pull/317772

Related: https://gerrit.lix.systems/c/lix/+/1428
Fixes: #385

Change-Id: I26d41ea826fec900ebcad0f82a727feb6bcd28f3
2024-06-12 15:34:22 -07:00

81 lines
2.8 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.nix;
lixVersion = lib.getVersion lix;
newNix = pkgs.nixVersions.latest;
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";
};
};
testScript = { nodes }: ''
# fmt: off
start_all()
machine.succeed("nix --version >&2")
# Install Lix into the default profile, overriding /run/current-system/sw/bin/nix,
# and thus making Lix think we're not on NixOS.
machine.succeed("nix-env --install '${lib.getBin lix}' --profile /nix/var/nix/profiles/default >&2")
# 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 "${lixVersion}" in default_profile_version, f"${lixVersion} not in {default_profile_version}"
# Upgrade to a different version of Nix, and make sure that also worked.
machine.succeed("nix upgrade-nix --store-path ${newNix} >&2")
default_profile_version = machine.succeed("nix --version")
print(default_profile_version)
assert "${newNixVersion}" in default_profile_version, f"${newNixVersion} 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}"
'';
}