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

env var to specify path/flake installable/flake-url #12656

Open
2 tasks done
mmlb opened this issue Mar 14, 2025 · 0 comments
Open
2 tasks done

env var to specify path/flake installable/flake-url #12656

mmlb opened this issue Mar 14, 2025 · 0 comments
Labels
feature Feature request or proposal

Comments

@mmlb
Copy link

mmlb commented Mar 14, 2025

Is your feature request related to a problem?

Not really.

I'd like to put flake.nix and co into a sub-dir of my git repo. This works fine but now I have to explicitly list the subdir when trying to use nix (flake check, develop, build, ...) and I'd rather not, not unlike if I was in a subdir and nix searches up for me already.

Proposed solution

Look into NIX_FLAKE_PATH env var and fall back to fs::current_path(). I have a quick patch that worked for nix flake check and nix flake show. I haven't tried to extend to nix develop or nix build (not sure how it could even work for nix build tbh). And so I thought to ask if there's an appetite for a PR for this.

diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index e2099c401..91919f189 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -54,7 +54,8 @@ public:

     FlakeRef getFlakeRef()
     {
-        return parseFlakeRef(fetchSettings, flakeUrl, fs::current_path().string()); //FIXME
+        auto path = getEnv("NIX_FLAKE_PATH").value_or(fs::current_path().string());
+        return parseFlakeRef(fetchSettings, flakeUrl, path); //FIXME
     }

     LockedFlake lockFlake()

Alternative solutions

Haven't thought of any except continuing with the status quo of using relative path in nix cli invocations.

Additional context

Checklist


Add 👍 to issues you find important.

@mmlb mmlb added the feature Feature request or proposal label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

1 participant