diff --git a/doc/manual/rl-next/git-lfs-support.md b/doc/manual/rl-next/git-lfs-support.md index 2990fc76c..4b6e0ca86 100644 --- a/doc/manual/rl-next/git-lfs-support.md +++ b/doc/manual/rl-next/git-lfs-support.md @@ -1,6 +1,6 @@ --- synopsis: "Git LFS support" -prs: [10153] +prs: [10153, 12468] --- The Git fetcher now supports Large File Storage (LFS). This can be enabled by passing the attribute `lfs = true` to the fetcher, e.g. @@ -8,4 +8,11 @@ The Git fetcher now supports Large File Storage (LFS). This can be enabled by pa nix flake prefetch 'git+ssh://git@github.com/Apress/repo-with-large-file-storage.git?lfs=1' ``` +A flake can also declare that it requires lfs to be enabled: +``` +{ + inputs.self.lfs = true; +} +``` + Author: [**@b-camacho**](https://github.com/b-camacho), [**@kip93**](https://github.com/kip93) diff --git a/src/libflake/flake/flake.cc b/src/libflake/flake/flake.cc index 443ad9a2a..ec0c8dde9 100644 --- a/src/libflake/flake/flake.cc +++ b/src/libflake/flake/flake.cc @@ -381,7 +381,7 @@ static FlakeRef applySelfAttrs( { auto newRef(ref); - std::set allowedAttrs{"submodules"}; + std::set allowedAttrs{"submodules", "lfs"}; for (auto & attr : flake.selfAttrs) { if (!allowedAttrs.contains(attr.first)) diff --git a/tests/nixos/fetch-git/test-cases/lfs/default.nix b/tests/nixos/fetch-git/test-cases/lfs/default.nix index a6b4fc77a..686796fcc 100644 --- a/tests/nixos/fetch-git/test-cases/lfs/default.nix +++ b/tests/nixos/fetch-git/test-cases/lfs/default.nix @@ -193,5 +193,36 @@ assert fetched_lfs == fetched_flake, \ f"fetching as flake input (store path {fetched_flake}) yielded a different result than using fetchGit (store path {fetched_lfs})" + + + with subtest("Check self.lfs"): + client.succeed(f""" + printf '{{ + inputs.self.lfs = true; + outputs = {{ self }}: {{ }}; + }}' >{repo.path}/flake.nix + """) + client.succeed(f"{repo.git} add : >&2") + client.succeed(f"{repo.git} commit -m 'add flake' >&2") + client.succeed(f"{repo.git} push origin main >&2") + + # memorize the revision + self_lfs_rev = client.succeed(f"{repo.git} rev-parse HEAD").strip() + + with TemporaryDirectory() as tempdir: + client.succeed(f"mkdir -p {tempdir}") + client.succeed(f""" + printf '{{ + inputs.foo = {{ + url = "git+{repo.remote}?ref=main&rev={self_lfs_rev}"; + }}; + outputs = {{ foo, self }}: {{ inherit (foo) outPath; }}; + }}' >{tempdir}/flake.nix + """) + fetched_self_lfs = client.succeed(f""" + nix eval --debug --raw {tempdir}#.outPath + """) + + client.succeed(f"cmp {repo.path}/beeg {fetched_self_lfs}/beeg >&2") ''; }