Skip to content

Init nixVersions.minimum and fix lib tests for all Nix versions#234070

Merged
roberth merged 5 commits intoNixOS:masterfrom
tweag:pathType-tests
Jun 1, 2023
Merged

Init nixVersions.minimum and fix lib tests for all Nix versions#234070
roberth merged 5 commits intoNixOS:masterfrom
tweag:pathType-tests

Conversation

@infinisil
Copy link
Member

@infinisil infinisil commented May 25, 2023

Description of changes

The lib.filesystem.pathType implementation now uses the new builtins.readFileType when available (in Nix 2.14) since #224834. But the tests introduced in that same PR weren't verified to work with 2.14, discovered in #233439, so this PR fixes that:

$ PATH=$(nix-build -A nixVersions.nix_2_14)/bin:"$PATH" lib/tests/filesystem.sh
test case failed:  lib.filesystem.pathType "/tmp/tmp.NXl2RIGW9m/non-existent" == error:
       … while calling the 'readFileType' builtin

         at «string»:1:46:

            1| { path }: let lib = import <nixpkgs/lib>; in lib.filesystem.pathType path
             |                                              ^

       error: getting status of '/tmp/tmp.NXl2RIGW9m/non-existent': No such file or directory, but error: evaluation aborted with the following error message: 'lib.filesystem.pathType: Path /tmp/tmp.NXl2RIGW9m/non-existent does not exist.' was expected

In addition, this PR fixes the tests for Nix version 2.3, since that's the minimum supported Nix version in Nixpkgs according to lib/minver.nix

And in order to ensure this doesn't happen again in the future, I created nixVersions.minimum to point to the Nix version from lib/minver.nix, and set up the lib tests to run with all of nixVersions.minimum, the default one, and nixVersions.unstable.

This work is sponsored by Antithesis

Things done
  • Ran the above command successfully

@infinisil infinisil requested a review from roberth May 25, 2023 20:47
@infinisil infinisil requested a review from edolstra as a code owner May 25, 2023 20:47
@infinisil infinisil mentioned this pull request May 25, 2023
12 tasks
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels May 25, 2023
@infinisil infinisil changed the title lib.filesystem.pathType: Fix tests for Nix >= 2.14 Init nixVersions.minimum and fix lib tests for all Nix versions May 26, 2023
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels May 26, 2023
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just recurseIntoAttrs would be nice. That way you can run all of them, or just the nix version you're interested in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't quite work without extra complexity because the part consuming this result uses it in buildInputs:

buildInputs = with pkgs; [ nix.out jq lib-tests brotli ];

which can't handle such recursive attribute sets:

$ nix-build pkgs/top-level/release.nix -A tarball
error: Dependency is not of a valid type: element 3 of buildInputs for nixpkgs-tarball-23.11pre1234.abcdef
(use '--show-trace' to show detailed location information)

(how have I never seen this error before :o)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this has something useful?

I can't believe that this is not a solved problem!

@infinisil infinisil requested a review from roberth May 31, 2023 20:09
Comment on lines +194 to +200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ! self ? ${attribute} then
throw "The minimum supported Nix version is ${minver} (declared in lib/minver.nix), but pkgs.nixVersions.${attribute} does not exist."
else
nix;
if self ? ${attribute} then
nix
else
throw "The minimum supported Nix version is ${minver} (declared in lib/minver.nix), but pkgs.nixVersions.${attribute} does not exist.";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for code that performs validation, it's good for the error case to be in the then, even if that leads to a negation.

Comment on lines +189 to +194
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
major = lib.versions.major minver;
minor = lib.versions.minor minver;
attribute = "nix_${major}_${minor}";
attribute = "nix_${lib.versions.major minver}_${lib.versions.minor minver}";

nit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# The minimum Nix version supported by Nixpkgs
# The minimum Nix version supported by Nixpkgs
# Note that some functionality *might* have been backported into this Nix version,
# making this package an inaccurate representation of what features are available
# in the actual lowest minver.nix *patch* version.

We generally don't backport a lot, and probably 2.3.0(1?) is not relevant anymore anyway, but testing against this may give a false sense of security correctness.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, ideally we'd pin the first supported Nix version somehow. Don't want to go into that for now though, I applied this suggestion :)

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the comment in the minimum version package. Otherwise lgtm.

@roberth roberth merged commit fb21e6d into NixOS:master Jun 1, 2023
@vcunat
Copy link
Member

vcunat commented Jun 22, 2023

Backport to 23.05 needed? It still won't pass with latest Nix version, which seems problematic, e.g. NixOS/nix#8569

@github-actions
Copy link
Contributor

Backport failed for release-23.05, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin release-23.05
git worktree add -d .worktree/backport-234070-to-release-23.05 origin/release-23.05
cd .worktree/backport-234070-to-release-23.05
git checkout -b backport-234070-to-release-23.05
ancref=$(git merge-base 7d9999f2c178882a4656283c12a7501243626bf7 013acf2396f451c73b6cd6b0148df21cbaa4c165)
git cherry-pick -x $ancref..013acf2396f451c73b6cd6b0148df21cbaa4c165

@vcunat
Copy link
Member

vcunat commented Jun 22, 2023

(Apparently, parts of this were already backported in the PR shown above.)

@vcunat
Copy link
Member

vcunat commented Jun 22, 2023

So at least this one?
#239188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants