Skip to content

Commit 52bda95

Browse files
committed
Make self attrs overridable
1 parent 5e17a3f commit 52bda95

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/libfetchers/git.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ struct GitInputScheme : InputScheme
251251
url.query.insert_or_assign("ref", *ref);
252252
if (getShallowAttr(input))
253253
url.query.insert_or_assign("shallow", "1");
254-
if (getLfsAttr(input))
255-
url.query.insert_or_assign("lfs", "1");
256-
if (getSubmodulesAttr(input))
257-
url.query.insert_or_assign("submodules", "1");
258254
if (maybeGetBoolAttr(input.attrs, "exportIgnore").value_or(false))
259255
url.query.insert_or_assign("exportIgnore", "1");
260256
if (maybeGetBoolAttr(input.attrs, "verifyCommit").value_or(false))
@@ -265,6 +261,11 @@ struct GitInputScheme : InputScheme
265261
url.query.insert_or_assign("publicKey", publicKeys.at(0).key);
266262
} else if (publicKeys.size() > 1)
267263
url.query.insert_or_assign("publicKeys", publicKeys_to_string(publicKeys));
264+
// These are allowed as self attrs, the explicit false is important
265+
if (auto lfs = maybeGetBoolAttr(input.attrs, "lfs"))
266+
url.query.insert_or_assign("lfs", *lfs ? "1" : "0");
267+
if (auto submodules = maybeGetBoolAttr(input.attrs, "submodules"))
268+
url.query.insert_or_assign("submodules", *submodules ? "1" : "0");
268269
return url;
269270
}
270271

@@ -884,8 +885,14 @@ struct GitInputScheme : InputScheme
884885
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
885886
{
886887
auto makeFingerprint = [&](const Hash & rev) {
887-
return rev.gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "")
888-
+ (getLfsAttr(input) ? ";l" : "");
888+
std::string modifiers = "";
889+
if (getExportIgnoreAttr(input))
890+
modifiers += ";e";
891+
if (auto lfs = maybeGetBoolAttr(input.attrs, "lfs"))
892+
modifiers += *lfs ? ";l1" : ";l0";
893+
if (auto submodules = maybeGetBoolAttr(input.attrs, "submodules"))
894+
modifiers += *submodules ? ";s1" : ";s0";
895+
return rev.gitRev() + modifiers;
889896
};
890897

891898
if (auto rev = input.getRev())

src/libflake/flake.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static FlakeRef applySelfAttrs(const FlakeRef & ref, const Flake & flake)
326326
for (auto & attr : flake.selfAttrs) {
327327
if (!allowedAttrs.contains(attr.first))
328328
throw Error("flake 'self' attribute '%s' is not supported", attr.first);
329-
newRef.input.attrs.insert_or_assign(attr.first, attr.second);
329+
newRef.input.attrs.try_emplace(attr.first, attr.second);
330330
}
331331

332332
return newRef;

tests/nixos/fetch-git/test-cases/lfs/default.nix

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
# memorize the revision
210210
self_lfs_rev = client.succeed(f"{repo.git} rev-parse HEAD").strip()
211211
212+
# Check that LFS is now enabled by default
212213
with TemporaryDirectory() as tempdir:
213214
client.succeed(f"mkdir -p {tempdir}")
214215
client.succeed(f"""
@@ -223,7 +224,24 @@
223224
nix eval --debug --raw {tempdir}#.outPath
224225
""")
225226
226-
client.succeed(f"cmp {repo.path}/beeg {fetched_self_lfs}/beeg >&2")
227+
client.succeed(f"cmp {repo.path}/beeg {fetched_self_lfs}/beeg >&2")
228+
229+
# Check that we can disable LFS enabled by default
230+
with TemporaryDirectory() as tempdir:
231+
client.succeed(f"mkdir -p {tempdir}")
232+
client.succeed(f"""
233+
printf '{{
234+
inputs.foo = {{
235+
url = "git+{repo.remote}?ref=main&rev={self_lfs_rev}&lfs=0";
236+
}};
237+
outputs = {{ foo, self }}: {{ inherit (foo) outPath; }};
238+
}}' >{tempdir}/flake.nix
239+
""")
240+
fetched_self_nolfs = client.succeed(f"""
241+
nix eval --debug --raw {tempdir}#.outPath
242+
""")
243+
244+
client.succeed(f"! cmp {fetched_self_lfs}/beeg {fetched_self_nolfs}/beeg >&2")
227245
228246
229247
with subtest("Ensure fetching with SSH generates the same output"):

0 commit comments

Comments
 (0)