-
-
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
Add --inputs-only
to nix copy
#8806
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
Thank you @iFreilicht for working on this. I'd like to document how this new feature may work. CLI example how it might work
nix build --no-link --print-out-paths .#nixosConfigurations.foobar.config.system.build.toplevel
nix copy --inputs-only --to file:///tmp/file /nix/store/hbwb7jyvd91iqz6f8g7bfddq3xhjiss6-nixos-system-foobar-23.05.20230805.9607b91
# or
nix copy --inputs-only --to - /nix/store/hbwb7jyvd91iqz6f8g7bfddq3xhjiss6-nixos-system-foobar-23.05.20230805.9607b91 | gzip > /tmp/file.gz
nix copy --from file:///tmp/file
# or
gunzip --stdout /tmp/file.gz | nix copy --from -
nix build /nix/store/hbwb7jyvd91iqz6f8g7bfddq3xhjiss6-nixos-system-foobar-23.05.20230805.9607b91
/nix/store/hbwb7jyvd91iqz6f8g7bfddq3xhjiss6-nixos-system-foobar-23.05.20230805.9607b91/bin/switch-to-configuration boot
reboot Why to add such functionality
|
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
You can |
Ohhh it seems I was confused about system configurations not having a deriver because this is the case for profiles. I'll continue the discussion in the linked thread and close this if that is the solution. |
We finally found that the issue was caused by an outdated version of Nix. Like @Ericson2314 said, This means the functionality requested by this ticket is offered by the current version of nix. |
Is your feature request related to a problem? Please describe.
In this neverending saga of a thread, there is a seemingly simple objective: copy the closure of a NixOS system configuration to another machine, not via ssh, but via a file, and make that file as small as possible.
The best Nix can currently do is to copy the entire closure, including all outputs. You would think that either
nix-copy-closure
ornix copy
can do better than that, but no:nix-copy-closure
only copies inputs by default, but it can only copy via ssh, not to a local binary cache.nix copy
does support afile://
URL for the--to
and--from
arguments, but copies the entire closure with outputs by default, and--substitute-on-destination
is obviously only possible on ssh stores.nix-store --export
andnix-store --import
are ~enough to kind of do this, but you would basically have to build two big scripts around them that resolve dependency graphs themselves.--import
apparently also requires inputs to be signed, which is annoying and not documented in its manpage.nix-store -q -R
+nix derivation
+cp
+nix store add-path
are in a similar boat. You can probably build a big script that does this, but it's cumbersome.This is very dissatisfying. Nix should be very good at solving this problem efficiently and quickly, but currently the frontend offers no solution.
Describe the solution you'd like
Add an
--inputs-only
argument tonix copy
that will only copy the closure of all derivations and inputs required to build theinstallables
argument, no matter what type the--to
argument is.This would enable one to
nix copy --to file:///media/drive/cache --inputs-only
, zip that directory, bring it to another machine in any conceivable way,nix copy --from file:///media/drive/cache
, and thennix build
the toplevel derivation.There are some cases where this isn't possible. For example, the current implementation of profiles does not create a derivation in the store for every profile generation, so only copying the inputs is not possible.
Describe alternatives you've considered
It might be possible to add support for local binary caches to
nix-copy-closure
instead, which would solve the same problem.A separate tool (potentially called
nix copy-closure
) could also be written for this.nix copy
is currently a very thin wrapper around the store API, so it might not be desirable to extend its functionality too much. The advantage here might be that it can be dedicated to copying a closure to a directory, instead of requiring the somewhat surprisingfile://
prefix.Additional context
See the thread linked above.
I'm willing to attempt an implementation of this myself.
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: