-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
nix flakes: flakes in subdirectories can access files in parent directories (breaking the implied seal of flake.nix) #4414
Comments
I always figured it was limited to the git repository, not necessarily the directory holding the |
@cole-h I'm sort of split-brained on this. After filing and sleeping on it, this functionality is potentially useful to me. I think the thing is when this is taken together with #4413. Consider Docker. Docker allows you to place the Dockerfile somewhere else in the repo, but the "build context" directory is still where the So, imagine this:
I would issue I also do acknowledge that Nix doesn't have to work exactly like Docker and that maybe this doesn't matter that much. |
Having access to the whole repo could potentially be useful in combination with #3978. Rust repositories for example often have a root crate depending on crates in subdirectories, which again may depend on other subdirectory crates not necessarily contained within their own folder. |
Breaking up inputs is a big step to achive substantially higher energy-efficiency. See #4217 (comment) As @Kha implied, a lot of repos out there are incorrectly structured, with crates accessing files in parent directories, because git has become the de-facto smallest unit of data, which is absurd since it enforces absolutely no logic on content. Treesitter does this. Nix is perfectly positionned to attack this widespread problem right at the spine, if it could break up any directory(repo) into components, or compose directories from components (git-submodules problem), without deep-cloning data. Here's a mock-up API: https://github.com/maisiliym/aidiyz/blob/9ccac4a716343724a453e14b631521eed1200ff9/mkSubModulesSrc.nix |
This is actually intended behaviour. A flake in a subdirectory is allowed to access other directories in the same input tree. (For instance, I have NixOS configurations in subdirectory flakes that access modules like This means that the flake reference |
Maybe we want an alternative attribute to |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/smoothing-the-flakes-learning-curve/11667/2 |
I marked this as stale due to inactivity. → More info |
I think |
It seems something like |
note that subdirectories can simply specify the parent directory as a flake input (or even a non-flake input) to break this isolation anyways. basically just take |
Describe the bug
This came up while thinking about #4413. I was looking at these commands:
And wondered if this meant that
nix
could be smart enough to only download a small subset of git objects as the VFSForGit progresses, and it could opt to only clone that specific subdirectory. This prompted me to think of edge cases and consider what that might break -- it would break any places that a flake in a subdirectory reached into a parent or sibling directory.And it seems that this is allowed, based on a test:
To me this seems a bit surprising. When I see a
flake.nix
I expect that it seals everything next to, and beneath it. This behavior violates that assumption.Steps To Reproduce
flake.nix
in each subdirbuiltins.readFile
somehow in one of the flakes to reach "up" and read the fileNote that it works.
Expected behavior
Somehow, nix is able to isolate the directory containing
flake.nix
to maintain the implied seal offlake.nix
nix-env --version
outputAdditional context
Alternatively, I could be entirely off the mark and this might intentionally be allowed, but it strikes me as sort of a pretty big mis-match of my expectations when I see a
flake.nix
.The text was updated successfully, but these errors were encountered: