NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.6k stars 1.51k forks source link

Add `builtins.toDir` #3497

Open Ericson2314 opened 4 years ago

Ericson2314 commented 4 years ago

We have toFile, readFile, and readDir, this would complete the square. I suppose it would take a attrset of paths and return a store path. Maybe like filterSource, we would need some restriction on the input source in case they are a derivation output that needs to be built? (Though I really hope we can turn builtins.filterSource into contents-addresssed derivations when we need to delay them!)


This probably can be solved another way in the meantime, but I would use it move the setup hooks common to every stdenv to $out/nix-support/setup/hook, that we the awful part of stdenv that tries to source an input if it is just a single file can go away.

EDIT: mentioning toDirectory for discoverability. toDir is the consistent name.

edolstra commented 4 years ago

How does it differ from builtins.path?

Ericson2314 commented 4 years ago

Let me write an example of what I am thinking:

builtins.toDir "nix-support" {
  "setup-hook" = { 
      executable = false;
      contents = ./pkgs/buils-suport/setup-hooks/foo.sh;
   };
}

builtins.path can't do that, right?

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

roberth commented 1 year ago

Smells like a lazy tree.

edolstra commented 1 year ago

Yeah, this could be implemented as an InputAccessor, similar to PatchingInputAccessor , that would synthesize a source tree lazily.