Skip to content

Commit

Permalink
fix(nix-compat): support Deriver: unknown-deriver NARInfos
Browse files Browse the repository at this point in the history
According to NixOS/nix@c60715e,
these were produced by a legacy tool and should be considered as if
Deriver was not passed at all.

See: kalbasit/ncps#171
Reported-In: nix-community/go-nix#128
Change-Id: If285a11c3275cb3c857c68782bd13473c46f04bf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12940
Reviewed-by: edef <[email protected]>
Autosubmit: flokli <[email protected]>
Tested-by: BuildkiteCI
  • Loading branch information
flokli authored and clbot committed Jan 1, 2025
1 parent 461c38b commit eba78b6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion nix-compat/src/narinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ bitflags! {
// Format quirks encountered in the cache.nixos.org dataset
const REFERENCES_OUT_OF_ORDER = 1 << 2;
const NAR_HASH_HEX = 1 << 3;

/// Deriver: unknown-deriver, produced by a legacy tool
const EXPLICIT_UNKNOWN_DERIVER = 1 << 4;
}
}

Expand Down Expand Up @@ -241,7 +244,11 @@ impl<'a> NarInfo<'a> {
}
}
None => {
return Err(Error::InvalidDeriverStorePathMissingSuffix);
if val == "unknown-deriver" {
flags |= Flags::EXPLICIT_UNKNOWN_DERIVER;
} else {
return Err(Error::InvalidDeriverStorePathMissingSuffix);
}
}
};
}
Expand Down Expand Up @@ -525,6 +532,27 @@ Sig: cache.nixos.org-1:92fl0i5q7EyegCj5Yf4L0bENkWuVAtgveiRcTEEUH0P6HvCE1xFcPbz/0
assert_eq!(parsed.compression, Some("bzip2"));
}

#[test]
fn explicit_unknown_deriver() {
// This is a NARInfo "produced by a legacy tool" according to Nix commit
// c60715e937e3773bbb8a114fc9b9c6577f8c5cb5
let parsed = NarInfo::parse(r#"StorePath: /nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432
URL: nar/1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d.nar.xz
Compression: xz
FileHash: sha256:1094wph9z4nwlgvsd53abfz8i117ykiv5dwnq9nnhz846s7xqd7d
FileSize: 114980
NarHash: sha256:0lxjvvpr59c2mdram7ympy5ay741f180kv3349hvfc3f8nrmbqf6
NarSize: 464152
References: 7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27
Deriver: unknown-deriver
Sig: cache.nixos.org-1:sn5s/RrqEI+YG6/PjwdbPjcAC7rcta7sJU4mFOawGvJBLsWkyLtBrT2EuFt/LJjWkTZ+ZWOI9NTtjo/woMdvAg==
Sig: hydra.other.net-1:JXQ3Z/PXf0EZSFkFioa4FbyYpbbTbHlFBtZf4VqU0tuMTWzhMD7p9Q7acJjLn3jofOtilAAwRILKIfVuyrbjAA==
"#).expect("should parse");

assert!(parsed.flags.contains(Flags::EXPLICIT_UNKNOWN_DERIVER));
assert!(parsed.deriver.is_none());
}

#[test]
fn nar_hash_hex() {
let parsed = NarInfo::parse(r#"StorePath: /nix/store/0vpqfxbkx0ffrnhbws6g9qwhmliksz7f-perl-HTTP-Cookies-6.01
Expand Down

0 comments on commit eba78b6

Please sign in to comment.