From f96cb571507e3a2cfce53022977907ad1c94272c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 13 Feb 2024 15:22:31 -0500 Subject: [PATCH] Make `outputHashAlgo` accept `"nar"`, stay in sync Now that we have a few things identifying content address methods by name, we should be consistent about it. Move up the `parseHashAlgoOpt` for tidiness too. Discussed this change for consistency's sake as part of #8876 Co-authored-by: Eelco Dolstra --- .../src/language/advanced-attributes.md | 9 +++++++-- src/libexpr/primops.cc | 20 ++++++++++--------- tests/functional/fixed.nix | 4 +++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/doc/manual/src/language/advanced-attributes.md b/doc/manual/src/language/advanced-attributes.md index b3e3afe3b287..16dcc6ba972a 100644 --- a/doc/manual/src/language/advanced-attributes.md +++ b/doc/manual/src/language/advanced-attributes.md @@ -207,12 +207,17 @@ Derivations can declare some infrequently used optional attributes. This is the default. - - `"recursive"`\ - The hash is computed over the NAR archive dump of the output + - `"recursive"` or `"nar"`\ + The hash is computed over the [NAR archive](@docroot@/glossary.md#gloss-nar) dump of the output (i.e., the result of [`nix-store --dump`](@docroot@/command-ref/nix-store/dump.md)). In this case, the output can be anything, including a directory tree. + `"recursive"` is the traditional way of indicating this, + and is supported since 2005 (virtually the entire history of Nix). + `"nar"` is more clear, and consistent with other parts of Nix (such as the CLI), + however support for it is only added in Nix version 2.21. + - [`__contentAddressed`]{#adv-attr-__contentAddressed} > **Warning** > This attribute is part of an [experimental feature](@docroot@/contributing/experimental-features.md). diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 752176178bc6..ca384bf2c046 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1139,18 +1139,20 @@ drvName, Bindings * attrs, Value & v) vomit("processing attribute '%1%'", key); auto handleHashMode = [&](const std::string_view s) { - if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive; - else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat; - else if (s == "git") { - experimentalFeatureSettings.require(Xp::GitHashing); - ingestionMethod = FileIngestionMethod::Git; - } else if (s == "text") { - experimentalFeatureSettings.require(Xp::DynamicDerivations); - ingestionMethod = TextIngestionMethod {}; - } else + if (s == "recursive") { + // back compat, new name is "nar" + ingestionMethod = FileIngestionMethod::Recursive; + } else try { + ingestionMethod = ContentAddressMethod::parse(s); + } catch (UsageError &) { state.error( "invalid value '%s' for 'outputHashMode' attribute", s ).atPos(v).debugThrow(); + } + if (ingestionMethod == TextIngestionMethod {}) + experimentalFeatureSettings.require(Xp::DynamicDerivations); + if (ingestionMethod == FileIngestionMethod::Git) + experimentalFeatureSettings.require(Xp::GitHashing); }; auto handleOutputs = [&](const Strings & ss) { diff --git a/tests/functional/fixed.nix b/tests/functional/fixed.nix index 5bdf7933386a..d55869f34a8d 100644 --- a/tests/functional/fixed.nix +++ b/tests/functional/fixed.nix @@ -57,11 +57,13 @@ rec { outputHashMode = "flat"; }; - # Test for building two derivations in parallel that produce the + # Test for building derivations in parallel that produce the # same output path because they're fixed-output derivations. parallelSame = [ (f2 "foo" ./fixed.builder2.sh "recursive" "md5" "3670af73070fa14077ad74e0f5ea4e42") (f2 "bar" ./fixed.builder2.sh "recursive" "md5" "3670af73070fa14077ad74e0f5ea4e42") + (f2 "foo" ./fixed.builder2.sh "nar" "md5" "3670af73070fa14077ad74e0f5ea4e42") + (f2 "bar" ./fixed.builder2.sh "nar" "md5" "3670af73070fa14077ad74e0f5ea4e42") ]; }