2

I have a USB disk with a nix store (to be more precise, the nix-store.squashfs file from the NixOS installation ISO) mounted at /mnt/foobar. So that when I do ls /mnt/foobar, I see the familiar subdirs, looking like:

kipnv4i3njqc3hjunp8nv23o2io3-somepackage-0.0.1
...etc...etc...

Now, (how) can I import stuff from that nix store into my regular /nix/store? (Ideally, with dependencies...) Or is this impossible?... :/ feels so close, but I really don't know what to do next... :( Tried e.g. NIX_STORE=/mnt/foobar nix-store -qR /mnt/foobar/*-somepackage-* but I'm getting an error. I'm afraid to just copy dirs between stores, because I don't know if that won't break something; also, no idea how to find out the dependencies then...

2
  • This sounds like it may be a good job for a shell script that goes through the contents of your /mnt/foobar directory, and then loops through and checks if the file exists in /nix/store. If it doesn't exist, it copies it over. I would use cp -i just to have that extra level of protection in case something does exist and you don't want to overwrite it. This does sound like it could get kind of dangerous, though. Make sure you have a backup in place before attempting this. If it's a VM, just take a snapshot. Nov 20, 2015 at 2:22
  • One of the problems is that I'm not sure if a dumb copy is enough for Nix system to properly recognize and accept the new directories as full packages. Another problem is that apparently the target filesystem is readonly, reportedly specifically to prevent copying stuff into there. Unfortunately, it's not as simple as just writing a bash script with a few cp calls.
    – akavel
    Nov 21, 2015 at 19:04

2 Answers 2

1

Hm; I've tried something based on the wiki (section "Large files"), i.e.:

sudo unshare -m bash
mount -o remount,rw /nix/store
cd /mnt/foobar
tar c kipnv4i3njqc3hjunp8nv23o2io3-somepackage-0.0.1 | tar x -C /nix/store
printf "kipnv4i3njqc3hjunp8nv23o2io3-somepackage-0.0.1\n\n0\n" | nix-store --register-validity --reregister
exit

and nix-env -qa now seems to show this package as -P- (this is installed? or not?); not 100% sure if that's all OK now though...

0

Nix v3 with the new cli now has nix copy

The syntax would be like so

nix copy --from /mnt/foobar /nix/store/kipnv4i3njqc3hjunp8nv23o2io3-somepackage-0.0.1

If you built the package yourself add --no-check-sigs.

Man page

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .