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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crate2nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Provided by callPackage or also directly usable via nix-build with defaults.
{ pkgs ? (
let
flakeLock = builtins.fromJSON (builtins.readFile ../flake.lock);
in
import "${builtins.fetchTree flakeLock.nodes.nixpkgs.locked}" { }
import (builtins.fetchTree (import ../nix/flakeInput.nix "nixpkgs")) { }
)
, stdenv ? pkgs.stdenv
, lib ? pkgs.lib
Expand Down
23 changes: 15 additions & 8 deletions docs/src/content/docs/00_guides/70_building_fetched_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ using the [tools.nix](./31_auto_generating) support:
# nix/nix-test-runner.nix
let
# Reuses the locked flake inputs.
flakeLock = builtins.fromJSON (builtins.readFile ../flake.lock);
flakeInput = import ./flakeInput.nix;
# Gets the locked sources.
src = builtins.fetchTree flakeLock.nodes.nix-test-runner.locked;
src = builtins.fetchTree (flakeInput "nix-test-runner");

# Use last pinned crate2nix packages and corresponding nixpkgs to build the
# test runner so that it works even if we have broken stuff!
crate2nix_stable = builtins.fetchTree (flakeInput "crate2nix_stable");
nixpkgs_stable = builtins.fetchTree (flakeInput "crate2nix_stable.nixpkgs");
in
{ pkgs ? import ./nixpkgs.nix { }
# Use last pinned crate2nix packages to build the test runner
# so that it works even if we have broken stuff!
, tools ? pkgs.callPackage "${builtins.fetchTree flakeLock.nodes.crate2nix_stable.locked}/tools.nix" { }
{
# A system must be specified if using default value for pkgs and calling this
# package from a pure evaluation context, such as from the flake devShell.
system ? builtins.currentSystem
, pkgs ? import nixpkgs_stable { inherit system; }
, tools ? pkgs.callPackage "${crate2nix_stable}/tools.nix" { }
}:
let
nixTestRunner = tools.appliedCargoNix {
Expand All @@ -38,9 +45,9 @@ nixTestRunner.rootCrate.build
```nix
# nix/nixpkgs.nix
let
flakeLock = builtins.fromJSON (builtins.readFile ../flake.lock);
flakeInput = import ./flakeInput.nix;
in
import "${builtins.fetchTree flakeLock.nodes.nixpkgs.locked}"
import (builtins.fetchTree (flakeInput "nixpkgs"))
```

```nix
Expand Down
2 changes: 1 addition & 1 deletion nix/devshell/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{ package = nix-prefetch-git; category = "nix"; }
{
name = "nix-test";
package = (import ../nix-test-runner.nix { inherit pkgs; });
package = (import ../nix-test-runner.nix { inherit (pkgs) system; });
category = "nix";
help = "nix test runner for unit tests.";
}
Expand Down
30 changes: 30 additions & 0 deletions nix/flakeInput.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Get a locked flake input value that can be given to `builtins.fetchTree` or to
# `builtins.getFlake`. For example,
#
# pkgs = import (builtins.fetchTree (flakeInput "nixpkgs")) { }
#
# This function can also be used to get inputs of inputs using dot-separated
# paths. For example,
#
# pkgs = import (builtins.fetchTree (flakeInput "crate2nix_stable.nixpkgs")) { }
#
# Gets the nixpkgs input of the crate2nix_stable input.

let
flakeLock = builtins.fromJSON (builtins.readFile ../flake.lock);
flakeInputNodeOf = parentNode: inputName:
let
inputNodeName = builtins.getAttr inputName parentNode.inputs;
in
builtins.getAttr inputNodeName flakeLock.nodes;
rootNode = let rootName = flakeLock.root; in builtins.getAttr rootName flakeLock.nodes;
in

name:
let
parts = builtins.split "[.]" name;
inputNames = builtins.filter builtins.isString parts;
flakeNode = builtins.foldl' flakeInputNodeOf rootNode inputNames;
in
flakeNode.locked

37 changes: 31 additions & 6 deletions nix/nix-test-runner.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
let
flakeLock = builtins.fromJSON (builtins.readFile ../flake.lock);
src = builtins.fetchTree flakeLock.nodes.nix-test-runner.locked;
flakeInput = import ./flakeInput.nix;
src = builtins.fetchTree (flakeInput "nix-test-runner");

# Use last pinned crate2nix packages and corresponding nixpkgs to build the
# test runner so that it works even if we have broken stuff!
crate2nix_stable = builtins.fetchTree (flakeInput "crate2nix_stable");

# For consistency we should use the locked version of nixpkgs from the
# crate2nix_stable release which would be,
#
# nixpkgs_stable = builtins.fetchTree (flakeInput "crate2nix_stable.nixpkgs");
#
# But nix-test-runner fails to build with the crate2nix_stable and the pinned
# nixpkgs from the same release. That's because "crate2nix_stable.nixpkgs"
# provides cargo v1.78 while "nixpkgs" provides cargo v1.78. Between those two
# cargo versions `cargo metadata` changed the format it uses for package ID
# strings which breaks checksum lookups in legacy V1 Cargo.toml files in
# crate2nix - and it happens that nix-test-runner uses a V1 Cargo.toml
# manifest.
#
# So for the time being it is necessary to use the current "nixpkgs" here
# which ended up on an older revision with an older cargo until there is
# a stable release of crate2nix that fixes V1 manifest parsing with the newer
# cargo, at which time this whole note may be removed.
nixpkgs_stable = builtins.fetchTree (flakeInput "nixpkgs");
in
{ pkgs ? import ./nixpkgs.nix { }
# Use last pinned crate2nix packages to build the test runner
# so that it works even if we have broken stuff!
, tools ? pkgs.callPackage "${builtins.fetchTree flakeLock.nodes.crate2nix_stable.locked}/tools.nix" { }
{
# A system must be specified if using default value for pkgs and calling this
# package from a pure evaluation context, such as from the flake devShell.
system ? builtins.currentSystem
, pkgs ? import nixpkgs_stable { inherit system; }
, tools ? pkgs.callPackage "${crate2nix_stable}/tools.nix" { }
}:
let
nixTestRunner = tools.appliedCargoNix {
Expand Down
Loading