That’s one of the omissions @7c6f434c was talking about; there’s no inverse for nix store dump-path
.
I tried a few things:
I think it should be possible to just copy the derivation (not the output path) like so:
$ nix derivation show /nix/store/any5gh2i9yqbsafs0v6mbapa7412a2jw-nixos-system-foobar-23.05.20230723.ac1acba > foobar.drv.json
# move that file to the other machine
$ cat foobar.drv.json | nix derivation add
$ nix-store --realise /nix/store/any5gh2i9yqbsafs0v6mbapa7412a2jw-nixos-system-foobar-23.05.20230723.ac1acba
Unfortunately, when I tried this out on my machine with a simple package, the nix derivation add
step would fail with an assertion error. After writing a full-on bug-report on this, I found out that you have to transform that output of derivation show
to be able to pass it to derivation add
:
nix derivation show /nix/store/any5gh2i9yqbsafs0v6mbapa7412a2jw-nixos-system-foobar-23.05.20230723.ac1acba \
| jq '.[]' > foobar.drv.json
I also tried using nix-store --export
and nix-store --import
but that fails with a signature error.
The lowest-tech solution is also the one that works (here I’m using grep as an example):
$ nix-store --query --deriver /nix/store/rn59ig1q28l4i3cd1lzszkjmxpl6i1r0-gnugrep-3.7
/nix/store/y565239srnxvr85kw7kc61py1s3x982l-gnugrep-3.7.drv
$ cp /nix/store/y565239srnxvr85kw7kc61py1s3x982l-gnugrep-3.7.drv gnugrep-3.7.drv
# Now copy that derivation file to your other machine, in whatever way you want.
$ nix store add-file gnugrep-3.7.drv
/nix/store/2r4f3yx819gz1nwl27mx10ba2jszc23j-gnugrep-3.7.drv
$ nix-store --realise /nix/store/2r4f3yx819gz1nwl27mx10ba2jszc23j-gnugrep-3.7.drv
/nix/store/rn59ig1q28l4i3cd1lzszkjmxpl6i1r0-gnugrep-3.7
Note that the final output path is identical to the one we started with.
I think this should work perfectly fine in terms of getting all the packages. About how to activate it, I’m not sure you should just be able to call
$outPath/bin/switch-to-configuration
where $outPath
is whatever nix-store --realise
returned.
EDIT: Ok now after revising this answer multiple times I actually read your first post again and you specifically don’t want to evaluate the derivation again. I’m not sure if my solution will save you any time, but please try it out and report back.
If the evaluation still takes long, you can also copy the built configuration, all its dependencies are downloaded from the binary cache anyway.
So instead of using dump-path
, you could just zip or tar everything inside the output path, move the zip file over to the other machine, and then use nix store add-path
to add the whole directory to the nix store.