tl;dr How to I combine nixstore addfixed
and nixstore addroot
to prevent garbage collection of manually added files?
I’ve installed Mathematica on my Nix installation which requires the manual insertion of the installer into the Nix store. To this end I am using
$ nixstore addfixed sha256 Mathematica_11.3.0_LINUX.sh
First of all this doesn’t work on my 2012 laptop because it runs out of memory and I use the technique outlined in the (old) NixOS wiki.

Find the right store path
$ nixhash type sha256 flat base32 Mathematica_11.3.0_LINUX.sh 03nimsayxj18740nq1jxkjyif2rphkdhpbz3gf749j7aq44f5kqg $ nixstore printfixedpath sha256 03nimsayxj18740nq1jxkjyif2rphkdhpbz3gf749j7aq44f5kqg Mathematica_11.3.0_LINUX.sh /nix/store/h9pljd50ha6b4bbrwp3riabh3g4i5bkpMathematica_11.3.0_LINUX.sh

Move (or copy) the file there as root
# mount o remount,rw /nix/store # mv Mathematica_11.3.0_LINUX.sh /nix/store/h9pljd50ha6b4bbrwp3riabh3g4i5bkpMathematica_11.3.0_LINUX.sh # mount o remount,ro /nix/store

Register the file (interactively, i.e. requires user input)
# nixstore registervalidity reregister /nix/store/h9pljd50ha6b4bbrwp3riabh3g4i5bkpMathematica_11.3.0_LINUX.sh <RET> <RET> 0 <RET> <Cd>
This method is surely not very elegant but seems to work fine. However, because the laptop is so old, it only has a small SSD and therefore I regularly garbage collect the Nix store. Unfortunately, this will eventually delete the Mathematica installer but I need this again when there is an update for curl or whatever and the Mathematica derivation has to be rebuilt. Hence I’m keeping around a second copy of the installer outside of the Nix store, just so that I can go through the process described above again, when it is needed.
I’ve went through the manpage of nixstore
and found the addroot
option to add a gcroot for a realization but I don’t know how to combine this with the above process. Can you please help me?
Just another side question: How do I change the syntax highlighting to not use Nix language highlighting, but either none or console session?