nix copy fully evaluates installable argument (and build/substitutes it into the local store) before validating that --from or --to are present #687

Open
opened 2025-02-21 16:28:32 +00:00 by lunaphied · 1 comment
Owner

This causes pointless wastes of time for users that haven't correctly input the command

This causes pointless wastes of time for users that haven't correctly input the command
Member

I worked a bit on this bug, I don't have the fix, but here is a reproducer:

{
  pkgs ? import <nixpkgs> {}
}:
derivation {
  name = "hello";
  builder = "/bin/sh";
  system = builtins.currentSystem;
  args = [
    "-c"
    "${pkgs.coreutils}/bin/sleep 100000 && echo hello > $out"
  ];
}

then nix copy --file reproduce.nix will be enough to trigger this behaviour.

From my (naive) understanding of the code, the issue seems to be that

I do not know a good way to fix this.
The inheritance monster has the last laugh again.

I worked a bit on this bug, I don't have the fix, but here is a reproducer: ```nix { pkgs ? import <nixpkgs> {} }: derivation { name = "hello"; builder = "/bin/sh"; system = builtins.currentSystem; args = [ "-c" "${pkgs.coreutils}/bin/sleep 100000 && echo hello > $out" ]; } ``` then `nix copy --file reproduce.nix` will be enough to trigger this behaviour. From my (naive) understanding of the code, the issue seems to be that * [`CmdCopy`](https://git.lix.systems/lix-project/lix/src/commit/708f1ea34257c81bed3f161f2547bb898f5479a8/lix/nix/copy.cc#L7) is a [`BuiltPathsCommand`](https://git.lix.systems/lix-project/lix/src/commit/708f1ea34257c81bed3f161f2547bb898f5479a8/lix/libcmd/command.cc#L128), * which will in turn call [`Installable::toBuiltPaths`](https://git.lix.systems/lix-project/lix/src/commit/708f1ea34257c81bed3f161f2547bb898f5479a8/lix/libcmd/installables.cc#L703) [in its own `run()`](https://git.lix.systems/lix-project/lix/src/commit/708f1ea34257c81bed3f161f2547bb898f5479a8/lix/libcmd/command.cc#L165) * which calls `Installable::build` * and this all runs before `CopyCmd` can ever validate its own arguments in [`CopyCommand::getDstStore`](https://git.lix.systems/lix-project/lix/src/commit/708f1ea34257c81bed3f161f2547bb898f5479a8/lix/libcmd/command.cc#L74). I do not know a good way to fix this. The inheritance monster has the last laugh again.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#687
No description provided.