I am trying to generalize and make a shell script out of the instructions on this page, specifically here: https://nixos.org/wiki/How_to_add_files_to_the_nix-store#Large_files because of Nix's failure to handle a 4.5 GB file, I get out of memory errors.
Hence...
My current code is:
#!/usr/bin/env bash
function do_store {
if [ "$#" -lt 1 ]; then
printf "Must provide the Xcode_dmg\n"
exit 1
fi
unshare -m bash
local
sdk="$1"
name="$(basename $sdk)"
# Hack since the openssl sha and nix-store is super slow
hash="a08d555c4f3fd905c53ee67720d9e6ade01e1b0b"
store_path="$(nix-store --print-fixed-path sha1 $hash $name)"
mount -o remount,rw /nix/store
printf "$storepath\n\n0\n" | nix-store --register-validity --reregister
exit
# printf "name: %s, hash: %s, store_path: %s\n" "$name" "$hash" "$store_path"
}
do_store "$@"
...with the idea that it would be invoked with sudo -HE
And the problem is that unshare
immediately starts a new bash shell and the "parent" code stops running, which of course is bad for me since I need that logic to finish. Also I need to have my current user's environment preserved since I need the paths for nix-store
and such to still be valid, hence the sudo -HE
usage.