Skip to content

Flakes using paths do not infer git+file: despite documentation to that effect #5836

@lilyball

Description

@lilyball

Describe the bug

nix help flake explains that path:<path> flakes are equivalent to git+file://<path> flakes with an inferred dir parameter if the path or any of its parents is a git repository. This does not appear to be true in general. Paths without the path: prefix given to nix commands as arguments do infer the git+file type, but arguments with an explicit path: don't, nor do paths specified in the nix registry or given to builtins.getFlake.

So there's two issues here:

  1. The documentation says path:<path> and git+file://<path> are roughly equivalent, except they're not as the path: flake copies the entire referenced source directory whereas git+file: copies the git worktree. This means the former will include untracked files that the latter skips (including the .git directory itself), the metadata is different, and parameters like ?rev= don't work (see builtins.getFlake doesn’t use git+file protocol if available #5670).
  2. The documentation says that specifying just <path> by itself is the same as path:<path> (in that the specified URL form here is [path:]<path>(?<params>)?). This is true for builtins.getFlake and for the registry (and presumably for flake inputs but I haven't tested that variant), but is not true for arguments given on the command-line.

I do think that it's useful to have path: and git+file: behave differently for the same path, and so writing path:<path> explicitly should behave as it does now. But the bare absolute path form should infer git+file: everywhere instead of just when used as CLI arguments, and the documentation should be updated such that it does not claim that path:<path> is equivalent to git+file://<path>, does not list the path: prefix as optional, and includes explicit documentation about how bare paths are interpreted.

Steps To Reproduce

  1. Navigate to a directory on your local filesystem that contains a flake.
  2. Run nix flake metadata $PWD
  3. Run nix flake metadata path:$PWD
  4. Run nix flake metadata git+file://$PWD
  5. Run nix registry add foo $PWD && nix flake metadata foo
  6. Run nix repl
  7. In the repl, run builtins.getFlake "/path/to/current/dir"
  8. In the repl, run builtins.getFlake "path:/path/to/current/dir"
  9. In the repl, run builtins.getFlake "git+file:///path/to/current/dir"

Expected behavior

Every means of evaluating a flake using an unprefixed path should behave identically to evaluating the flake using the git+file:// prefix (including resolved and locked URLs and other metadata). The flake evaluations using an explicit path: prefix should evaluate differently.

nix --version output

nix (Nix) 2.5.1

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