crate2nix icon indicating copy to clipboard operation
crate2nix copied to clipboard

fix flake lock references pointing to wrong nixpkgs

Open hallettj opened this issue 1 year ago • 1 comments

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.

hallettj avatar Jan 23 '25 08:01 hallettj

~~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.

hallettj avatar Jan 23 '25 08:01 hallettj