Skip to content

Using dirty git checkouts as flakes #3231

@Ma27

Description

@Ma27

Note: after digging through the Nix-codebase with flake-support I consider this a question/bugreport about the implementation and not necessarily about flake's design. In case I'm wrong, feel free to close this :)


After the cleanup[1] the RFC states that it's possible to use a "A Git repository or dirty local working tree."[2] as input which is something I consider pretty important when hacking on a change that affects several flakes (in other words, I want to change stuff in several local checkouts of flakes without having commit changes or update lockfiles). I tried to do this by using a locally built version of Nix (8d2eb1f to be precise):

nix build --impure on a dirty working tree

When using the git type (as described in the RFC) I get an error like this when evaluating the expression (with nix build --impure):

error: flake input 'snens' has an unsupported attribute 'type', at /nix/store/rykmw3pkfh0g43qwr0wkncl2kbxnhixz-source/flake.nix:8:5

Am I missing something or is this just not implemented yet? (In case I have sufficient time, I'd be happy to file a patch for this as well :))

After that I tried to simply fetch the tree (input.test.uri = "/path/to/dirty/git-repo?") which caused the following warnings:

warning: will not write lock file of flake '/home/ma27/Projects/flake-tests/test' because it has a dirty input
fatal: not a tree object: 0000000000000000000000000000000000000000
error: program 'git' failed with exit code 128

The affected repo has one commit (which incorporates flake.nix), unfortunately I'm not 100% sure why I get this revision, however this seems to be related to fetchGit which always tries to create an "archive" from a given rev[3], but we might want to use a ref for dirty trees.

fiddling around in flake.lock

After that I tried to import the dirty flake using flake.lock, precisely nix flake update --impure and nix flake pin <flake-with-dirty-path> --impure, but those attempts failed and caused the following warning:

warning: will not write lock file of flake '/home/ma27/Projects/flake-tests/test' because it has a dirty input

As far as I understand the code, it's simply impossible to add a "dirty" flake to flake.lock[4].

Summary

To summarize, I simply didn't find a way to use a dirty tree of a flake as input for a different flake when developing locally which leads me to the following questions:

  • Did I miss anything (obvious)? Or is it completely unintended to allow this (and I just misinterpreted the part of the RFC I quoted above)?
  • Should builtins.fetchGit on a dirty tree be able to use the dirty tree (if --impure is set)?
  • I assume that flake.lock shouldn't be modified, even in case of --impure, right? (If a flake.lock exists and a flake is pinned to a local path on a given rev, uncommited changes are completely ignored, so how should this be detected?)
  • Slightly OT, but how should we deal with untracked files? When running nix flake init, the flake.nix is untracked and therefore not part of the path fetched by fetchGit as files are filtered with git ls-files[5]

[1] NixOS/rfcs@c24dca8
[2] https://github.com/tweag/rfcs/blob/dd6c657e5c8c684445ad52cd1836b2665e85e779/rfcs/0049-flakes.md#flake-inputs
[3] https://github.com/NixOS/nix/blob/flakes/src/libexpr/primops/fetchGit.cc#L259
[4] https://github.com/NixOS/nix/blob/flakes/src/libexpr/flake/flake.cc#L463-L465
[5] https://github.com/NixOS/nix/blob/flakes/src/libexpr/primops/fetchGit.cc#L129-L145

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