From bd73dff0bfd03a411c27193487bdeebf987ccbc7 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 1 Jan 2025 16:41:21 +0100 Subject: [PATCH] fix(nix-compat): support Deriver: unknown-deriver NARInfos According to https://github.com/NixOS/nix/commit/c60715e937e3773bbb8a114fc9b9c6577f8c5cb5, these were produced by a legacy tool and should be considered as if Deriver was not passed at all. See: https://github.com/kalbasit/ncps/issues/171 Reported-In: https://github.com/nix-community/go-nix/pull/128 Change-Id: If285a11c3275cb3c857c68782bd13473c46f04bf Reviewed-on: https://cl.tvl.fyi/c/depot/+/12940 Reviewed-by: edef Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/narinfo/mod.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tvix/nix-compat/src/narinfo/mod.rs b/tvix/nix-compat/src/narinfo/mod.rs index 35146a927..151fbdcff 100644 --- a/tvix/nix-compat/src/narinfo/mod.rs +++ b/tvix/nix-compat/src/narinfo/mod.rs @@ -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; } } @@ -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); + } } }; } @@ -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