pkgs.path: Avoid copying when used via flake#153594
Conversation
|
we tried pretty much exactly this before giving up and copying subdirectories explicitly, since it doesn't seem to work: the only way to avoid having a redundant copy is to force the name of the resulting store path to be the same as the source store path (eg, the resulting drv for lazy-options starts like this: |
|
Was that without the flake? With the flake, it should use I've pushed a commit. It's really kind of a flake-only optimization now, unless someone cares to set |
|
yes, that was without flakes, we ran checked the flake case with your additional commit now though, and we still see a lot of copying happening: not sure there's a good way to solve this if |
This looks as expected for a non-flake eval. Without
That's kind of what's happening after my last commit here, except it errs on the safe side, rather than assuming pure eval is off for non-flake usage. It's not as good as we hoped, but at least it doesn't break and is more efficient for flake users. |
that was a flake eval though 🙁 |
|
test operations done to get to that conclusion: we've confirmed that the eval did use your repo, our current flake lock for the test system does not include the docs split yet |
|
|
pennae
left a comment
There was a problem hiding this comment.
works as intended now 😸 flakes use the existing store path, non-flakes filter parts over.
we've tried a bit whether we can tryEval (storePath ...), but that's not possible. what we can do though is getEnv "_" != "" and use storePath if so, because getEnv will not fail in pure or restricted mode but simply return an empty string. we couldn't falsely detect that storePath is available, only that it isn't. do you think it's worth going for that too?
|
we finally got around to checking whether diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix
index 2ecdf68293e..b850d5f9ab5 100644
--- a/nixos/modules/misc/documentation.nix
+++ b/nixos/modules/misc/documentation.nix
@@ -74,13 +74,18 @@ let
#
# We can only avoid copying when pkgs.path is already a string. A path
# value can not be converted to a store path without rehashing it.
- # builtins.storePath would be a solution but is currently off-limits
- # because of https://github.com/NixOS/nix/issues/1888
- # and https://github.com/NixOS/nix/issues/5868
- pull = dir:
- if builtins.typeOf pkgs.path == "string" && isStorePath pkgs.path
- then "${pkgs.path}/${dir}"
- else filter "${toString pkgs.path}/${dir}";
+ # builtins.storePath can only be used to avoid this when impure eval is
+ # allowed, which we approximate by getEnv returning something for a
+ # variable that should always be set.
+ # see https://github.com/NixOS/nix/issues/1888
+ # and https://github.com/NixOS/nix/issues/5868
+ pull =
+ if builtins.typeOf pkgs.path == "string" && isStorePath pkgs.path then
+ dir: "${pkgs.path}/${dir}"
+ else if builtins.getEnv "PATH" != "" && isStorePath pkgs.path then
+ dir: "${builtins.storePath pkgs.path}/${dir}"
+ else
+ dir: filter "${toString pkgs.path}/${dir}";
in
pkgs.runCommand "lazy-options.json" {
libPath = pull "lib"; |
This kind of reverts commit 893ffee.
…when already copied
dbc837a to
c1349dd
Compare
c1349dd to
5d29853
Compare
|
we like this a lot. thanks for caring and for writing the extremely comprehensive comments, they're superb :) |
|
tested it again, the copy elision seems to work fine, resulting json also looks good. |
|
Note that this makes nix-env produce a different evaluation result for a In general we should avoid the use of |
|
I agree that this is still not a great solution. Indeed this will produce one of two different derivations depending on how the NixOS/Nixpkgs invocation was made. Perhaps the |
|
I've reverted this PR, as it makes already fragile code like the installer tests even more fragile. |
Motivation for this change
pkgs.pathThings done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes