Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using dirty git checkouts as flakes #3231

Closed
Ma27 opened this issue Nov 16, 2019 · 2 comments
Closed

Using dirty git checkouts as flakes #3231

Ma27 opened this issue Nov 16, 2019 · 2 comments
Labels

Comments

@Ma27
Copy link
Member

Ma27 commented Nov 16, 2019

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

@Ma27
Copy link
Member Author

Ma27 commented Feb 20, 2020

@edolstra just wondering - would it make sense to add a fetcher now which simply retrieves local file-paths for flake inputs?

@Ma27
Copy link
Member Author

Ma27 commented Apr 16, 2020

After rechecking it should be possible like this:

{
  /* ... */
  inputs.mypkgs = {
    type = "git";
    uri = "file:///path/to/local/nixpkgs";
  };
}

Additionally, local changes should be staged to take effect AFAICS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants