Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flake lock references pointing to wrong nixpkgs #380

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hallettj
Copy link

@hallettj hallettj commented Jan 23, 2025

Hi! I think crate2nix is tremendously useful! I noticed that in addition to the caching benefits it provides there is less configuration required to use crate2nix compared to crane - especially when cross-compiling and statically-linking. I'm working on updating the git-workspaces branch in #298. (My work so far is here but there is a bit more for me to do.) While I was working I ran into some problems getting tests running that I wanted to submit PRs for. One problem has to do with references to inputs gotten from parsing flake.lock.

There a couple of nix expressions that read flake.lock to load nixpkgs:

  • crate2nix/default.nix
  • nix/nix-test-runner.nix

The problem is that flakeLock.nodes.nixpkgs does not refer to the intended nixpkgs version: it refers to the cachix input's nixpkgs input which is quite old. The version of nixpkgs locked at the flake root is flakeLock.nodes.nixpkgs_6.

Lock file node names are named somewhat arbitrarily. If the intention is to load the version of nixpkgs that is locked in flake.nix then it is necessary to:

  1. Read flakeLock.root to get the name of the root node. (The name is "root", but it's better not to assume.)
  2. Read flakeLock.nodes.${rootNodeName}.inputs.nixpkgs to get the name of the lock file node of the intended nixpkgs version.
  3. Read flakeLock.nodes.${nixpkgsNodeName}

nix/nix-test-runner.nix also gets the wrong version of nix-test-runner for the same reason.

This change introduces a function, flakeInput, that applies the steps above.

I wanted to be able to submit a PR with working tests, but the tests were not working so this PR also includes some test fixes. While I was at it I fixed clippy warnings.

There is another issue that is explained in a comment that I put in nix/nix-test-runner.nix. I have a fix for that which I will submit in another PR.

There a couple of nix expressions read flake.lock to load nixpkgs:

- crate2nix/default.nix
- nix/nix-test-runner.nix

The problem is that `flakeLock.nodes.nixpkgs` does not refer to the
intended nixpkgs version: it refers to the cachix input's nixpkgs input
which is quite old. The version of nixpkgs locked at the flake root is
`flakeLock.nodes.nixpkgs_6`.

Lock file node names are named somewhat
arbitrarily. If the intention is to load the version of nixpkgs that is
locked in flake.nix then it is necessary to:

1. Read `flakeLock.root` to get the name of the root node. (The name is
   "root", but it's better not to assume.)
2. Read `flakeLock.nodes.${rootNodeName}.inputs.nixpkgs` to get the name of the
   lock file node of the intended nixpkgs version.
3. Read `flakeLock.nodes.${nixpkgsNodeName}`

nix/nix-test-runner.nix also gets the wrong version of nix-test-runner
for the same reason.

This change introduces a function, `flakeInput`, that applies the steps
above.

I wanted to be able to submit a PR with working tests, but the tests
were not working so this PR also includes some test fixes. While I was
at it I fixed clippy warnings.

There is another issue that is explained in a comment that I put in
nix/nix-test-runner.nix. I have a fix for that which I will submit in
another PR.
@hallettj
Copy link
Author

hallettj commented Jan 23, 2025

The test fixes and lint warning fixes here are basically the same as in #375. If there is a preference for keeping the changes in each PR minimal I can remove the changes from this PR in favor of that one.

Edit: I went ahead and reverted those test and lint fixes to make this PR smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant