Skip to content

Commit 0159911

Browse files
committed
Add build-time-fetch-tree experimental feature
1 parent 943aaa4 commit 0159911

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

src/libfetchers/builtin.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace nix {
1212

1313
static void builtinFetchTree(const BuiltinBuilderContext & ctx)
1414
{
15+
experimentalFeatureSettings.require(Xp::BuildTimeFetchTree);
16+
1517
auto out = get(ctx.drv.outputs, "out");
1618
if (!out)
1719
throw Error("'builtin:fetch-tree' requires an 'out' output");

src/libflake/flake.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ static FlakeInput parseFlakeInput(
133133
} else if (attr.name == sBuildTime) {
134134
expectType(state, nBool, *attr.value, attr.pos);
135135
input.buildTime = attr.value->boolean();
136+
if (input.buildTime)
137+
experimentalFeatureSettings.require(Xp::BuildTimeFetchTree);
136138
} else if (attr.name == sInputs) {
137139
input.overrides =
138140
parseFlakeInputs(state, attr.value, attr.pos, lockRootAttrPath, flakeDir, false).first;

src/libutil/experimental-features.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ struct ExperimentalFeatureDetails
1616

1717
/**
1818
* If two different PRs both add an experimental feature, and we just
19-
* used a number for this, we *woudln't* get merge conflict and the
19+
* used a number for this, we *wouldn't* get merge conflict and the
2020
* counter will be incremented once instead of twice, causing a build
2121
* failure.
2222
*
2323
* By instead defining this instead as 1 + the bottom experimental
2424
* feature, we either have no issue at all if few features are not added
2525
* at the end of the list, or a proper merge conflict if they are.
2626
*/
27-
constexpr size_t numXpFeatures = 1 + static_cast<size_t>(Xp::BLAKE3Hashes);
27+
constexpr size_t numXpFeatures = 1 + static_cast<size_t>(Xp::BuildTimeFetchTree);
2828

2929
constexpr std::array<ExperimentalFeatureDetails, numXpFeatures> xpFeatureDetails = {{
3030
{
@@ -304,6 +304,14 @@ constexpr std::array<ExperimentalFeatureDetails, numXpFeatures> xpFeatureDetails
304304
)",
305305
.trackingUrl = "",
306306
},
307+
{
308+
.tag = Xp::BuildTimeFetchTree,
309+
.name = "build-time-fetch-tree",
310+
.description = R"(
311+
Enable the built-in derivation `builtin:fetch-tree`, as well as the flake input attribute `buildTime`.
312+
)",
313+
.trackingUrl = "",
314+
},
307315
}};
308316

309317
static_assert(

src/libutil/include/nix/util/experimental-features.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum struct ExperimentalFeature {
3636
PipeOperators,
3737
ExternalBuilders,
3838
BLAKE3Hashes,
39+
BuildTimeFetchTree,
3940
};
4041

4142
extern std::set<std::string> stabilizedFeatures;

tests/functional/flakes/build-time-flake-inputs.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ EOF
3535

3636
cp "${config_nix}" "$repo/"
3737
git -C "$repo" add flake.nix config.nix
38-
nix flake lock "$repo"
38+
nix flake lock --extra-experimental-features build-time-fetch-tree "$repo"
3939
git -C "$repo" add flake.lock
4040
git -C "$repo" commit -a -m foo
4141

4242
clearStore
4343

44-
nix build --out-link "$TEST_ROOT/result" -L "$repo"
44+
nix build --extra-experimental-features build-time-fetch-tree --out-link "$TEST_ROOT/result" -L "$repo"
4545
[[ $(cat "$TEST_ROOT/result") = world ]]
4646

4747
echo utrecht > "$lazy/who"
4848
git -C "$lazy" commit -a -m foo
4949

50-
nix flake update --flake "$repo"
50+
nix flake update --extra-experimental-features build-time-fetch-tree --flake "$repo"
5151

5252
clearStore
5353

54-
nix build --out-link "$TEST_ROOT/result" -L "$repo"
54+
nix build --extra-experimental-features build-time-fetch-tree --out-link "$TEST_ROOT/result" -L "$repo"
5555
[[ $(cat "$TEST_ROOT/result") = utrecht ]]
5656

5757
rm -rf "$lazy"
5858

5959
clearStore
6060

61-
expectStderr 1 nix build --out-link "$TEST_ROOT/result" -L "$repo" | grepQuiet "Cannot build.*source.drv"
61+
expectStderr 1 nix build --extra-experimental-features build-time-fetch-tree --out-link "$TEST_ROOT/result" -L "$repo" | grepQuiet "Cannot build.*source.drv"

0 commit comments

Comments
 (0)