Skip to content

lib.fileset.gitTracked does not work with --store #283843

@PigeonF

Description

@PigeonF

Describe the bug

When using lib.fileset.gitTracked in combination with --store, the build fails with lib.fileset.gitTracked: Expected the argument (/tmp/nix-store/nix/store/8a5a320f0h66jh066qabxkm67msvbcql-source) to point to a local working tree of a Git repository, but it's not.

Steps To Reproduce

  1. Create a new git repository

  2. Add the following flake.nix

    {
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
      };
    
      outputs = {nixpkgs, ...}: {
        packages.x86_64-linux.default = let
          pkgs = nixpkgs.legacyPackages.x86_64-linux;
          fs = pkgs.lib.fileset;
        in
          pkgs.stdenvNoCC.mkDerivation {
            name = "gitTrackedBug";
    
            src = fs.toSource {
              root = ./.;
              fileset = fs.gitTracked ./.;
            };
    
            buildPhase = "touch $out";
          };
      };
    }
  3. Build with nix build (works as expected)

  4. Build with nix build --store /tmp/nix-store/ (this fails)

Additional context

I'm pretty sure this is the same underlying issue as #269283. I think the issue is that the hasStorePathPrefix check fails when it should trigger in the chroot-ed nix store

else if hasStorePathPrefix path then

hasStorePathPrefix has a note about usage with other filesystem roots, which seems relevant

# This function likely breaks or needs adjustment if used with other filesystem roots, if they ever get implemented.
# Let's try to error nicely in such a case, though it's unclear how an implementation would work even and whether this could be detected.
# See also https://github.com/NixOS/nix/pull/6530#discussion_r1422843117
(deconstructed.root == /. && toString deconstructed.root == "/")
"lib.path.hasStorePathPrefix: Argument has a filesystem root (${toString deconstructed.root}) that's not /, which is currently not supported.";

but I don't know enough about how the actual --store implemention works under the hood to comment further.

Notify maintainers

@infinisil


Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions