-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Expose the flake directory to commands #8034
Comments
This is a small change that could have a good impact on the usability of flakes. |
This is somewhat ambiguous, as in the case of a subflake, or really a flake in a subdirectory, either of two directories can be considered the root.
Although the semantics can be debated, I think it'd be helpful to differentiate the terminology regardless.
We may choose not to implement the latter until the core flake semantics are stabilized, ie after lazy trees, and after deciding/implementing on the feedback on the lock file and subflakes.
A The issue will be:
If we implement this in
So while I do think we should avoid this for |
Thanks for unrolling all your thoughts, it's interesting. To me, semantically speaking, the It's true that the command might not work if the folder is read-only in the Is the |
As a general rule, things haven't been blessed by the team unless it has an idea approved label or a comment with meeting notes. (As of early 2023; process may change in the future)
... so for a quick win, we might want to avoid |
I would prefer to have it applied across the board, so developers don't have to remember which command has the env var. Also because devshells can both be used locally and remotely as well (eg: I don't think introducing this would block the introduction of In order to move forward I propose that the nix team votes:
That seem to be the main choices in the decision tree. |
Nix should probably just set the current directory to the flake directory before running the formatter. That removes the need for an environment variable and makes execution more predictable. |
Consider the following scenario:
Assuming that If nix calls |
Another example is https://github.com/numtide/treefmt-nix, where the config requires a |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-06-02-nix-team-meeting-minutes-59/28666/1 |
I'd really wish for a |
@domenkozar I would think that knowing the path at evaluation time adds very little over knowing it at runtime. Is that a wrong assumption? What is something you could do with an eval-time path that you wouldn't be able to do at runtime instead? |
How do you generate a config file using Nix that requires an absolute path to let's say a stateful directory? |
You might be able to use a placeholder and then substitute that at the last moment, in a file that's not in the store, or in the store while rewriting to content addressed paths (but not part of the original build). That's a lot of extra complexity and fragility though, that you wouldn't have if you could take advantage of the Nix language to construct the right thing in the first place. I think the main objections about impurities relate to
Reproducibility of packages could still be guaranteed by evaluating By virtue of being an input, evaluation caching won't be a problem, because inputs are already part of the cache key. |
It gets very tricky if you depend on that config from another Nix build. We'd almost have to build this in as a placeholder feature into Nix.
That's why it would be an input, as Nix controls what inputs are "safe" and |
I quite like the impure directory location input idea. (not sure if we should make it cryptic like It would make for a good addition that would be able to implement the environment variable, but there's also merit to establishing a standard environment variable for this, so perhaps we should do both. |
|
My use case which requires something like I use logseq with git-annex for note keeping. I would like to have a flake file with my logseq environment and want to run logseq with the argument of the checked out flake. Referring to the read-only store is absolute useless for this task. I want to open the flake source folder with a program defined in the flake. This is a quite common case for any editorial work. If you want to package the tools with your project, you need to edit the project too. |
For those looking for a workaround: If you need this because you want to run some commands inside a
devShell =
pkgs.mkShell
{
buildInputs = with pkgs; [
python3
];
shellHook = ''
FLAKE_ROOT="$(git rev-parse --show-toplevel)"
(
cd "$FLAKE_ROOT"
if [ -d git-hooks ]; then
rm -f .git/hooks/*
cp git-hooks/* .git/hooks/
else
echo "Warning: Not running in expected repository, but in '$FLAKE_ROOT'!"
fi
)
'';
}; |
Is your feature request related to a problem? Please describe.
When running
nix fmt path:some/flake
, the formatter will likely try to format files in the current directory instead of starting from the root of the flake. There is no mechanism to inform the subprocess of the flake's root directory.Describe the solution you'd like
Introduce a new environment variable
FLAKE_ROOT
that points to the root of the flake directory (where theflake.nix
file lives). For path flakes, the value should point to the original path location, and for non-path flakes, it should point to the copy of the flake located in/nix/store
.Extend the
nix
CLI to set theFLAKE_ROOT
environment variable before invoking programs such asnix fmt
,nix run
andnix develop
.Describe alternatives you've considered
One alternative is to use
chdir
before invoking the command, but this requires translating relative path arguments passed to the program.Another option is to set FLAKE_URL/FLAKE_URI to resolve to path:/path/to/my/repo for local flakes and the original URL otherwise, but this is not directly usable by CLI tools.
Additional context
This proposal is a subset of #6241
Another example use case is for devenv, which depends on --impure to function correctly: https://discourse.nixos.org/t/change-devenv-root-path-for-devenv/26213
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: