Skip to content

Path coercion in Flakes causes files to be added to the store twice #9428

Open
@infinisil

Description

Describe the bug

When coercing paths to strings (which adds said paths into the Nix store) in Flakes, all files are added to the store twice, leading to doubled space usage.

I understand the underlying mechanism and why this happens, but this sounds like a bug to me.

Steps To Reproduce

Create this flake.nix:

{
  outputs = { ... }: {
    result = "${./.}";
  };
}

Then run:

$ nix eval .#result
"/nix/store/jmnphp5bc4m32y80jw6ms16s8gb5g1gy-x2xsp09mx900wf1h7pglh9xlwy3r1349-source"
$ cat /nix/store/jmnphp5bc4m32y80jw6ms16s8gb5g1gy-x2xsp09mx900wf1h7pglh9xlwy3r1349-source/flake.nix
{
  outputs = { ... }: {
    result = "${./.}";
  };
}
$ cat /nix/store/x2xsp09mx900wf1h7pglh9xlwy3r1349-source/flake.nix
{
  outputs = { ... }: {
    result = "${./.}";
  };
}

Notice how the flake.nix file was copied to two store paths.

Expected behavior

Only a single store path is used.

nix-env --version output

nix-env (Nix) 2.18.1

Additional context

This issue is sponsored by Antithesis

Priorities

Add 👍 to issues you find important.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions