1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-22 02:55:39 +03:00

Ignore non-flake file inputs

It's impossible to calculate their store paths currently.

Fixes #113
This commit is contained in:
oxalica 2023-11-27 12:04:48 +08:00
parent 440a3857cd
commit 1348b53085
3 changed files with 29 additions and 3 deletions

View File

@ -37,8 +37,13 @@ pub async fn resolve_flake_locked_inputs(
.context("Failed to resolve inputs from flake lock")?;
// Ignore the root node which is unlocked. This happens in cycle flake inputs.
// TODO: Should come up a way to correctly handle it in database.
inputs.retain(|&(_, node)| !std::ptr::eq(node, root_node));
// Workaround: It's currently impossible to calculate store paths of type="file" inputs
// given only `flake.lock`.
// Ref: https://github.com/oxalica/nil/issues/113
// and https://github.com/NixOS/nix/issues/9456
inputs.retain(|&(_, node)| {
!std::ptr::eq(node, root_node) && !matches!(&node.locked, Some(f) if f._type == "file")
});
let hashes = inputs
.iter()
@ -184,6 +189,8 @@ enum FlakeInput {
#[serde(rename_all = "camelCase")]
struct LockedFlakeRef {
nar_hash: String,
#[serde(rename = "type")]
_type: String,
// ...
}
@ -227,6 +234,8 @@ mod tests {
let got = resolve_flake_locked_inputs("nix".as_ref(), &lock_src)
.await
.unwrap();
// NB. This does not contain `non-flake-file`,
// see the comment in `resolve_flake_locked_inputs`.
let expect = HashMap::from_iter([
(
"nixpkgs".to_owned(),

View File

@ -33,10 +33,23 @@
"type": "github"
}
},
"non-flake-file": {
"flake": false,
"locked": {
"narHash": "sha256-D4N+MuIfbF+WogLprhLa5iQACL0tU1OKVqFhkQNf10A=",
"type": "file",
"url": "https://raw.githubusercontent.com/NixOS/nix/7304806241fe4f72c5f33a5a929d675c8342fabd/flake.nix"
},
"original": {
"type": "file",
"url": "https://raw.githubusercontent.com/NixOS/nix/7304806241fe4f72c5f33a5a929d675c8342fabd/flake.nix"
}
},
"root": {
"inputs": {
"nix": "nix",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"non-flake-file": "non-flake-file"
}
}
},

View File

@ -5,6 +5,10 @@
flake = false;
url = "github:NixOS/nix/2.13.3";
};
inputs.non-flake-file = {
flake = false;
url = "https://raw.githubusercontent.com/NixOS/nix/7304806241fe4f72c5f33a5a929d675c8342fabd/flake.nix";
};
outputs = { nixpkgs, ... }: let
inherit (nixpkgs) lib;