nix-env
has the capability to operate on different profiles, and to switch between them. I admit I’ve never really understood the point of this given that switching profiles affects my entire user instead of the just the current shell.
But today I had a thought: is there any way to construct a single profile that layers several other profiles together?
I want to do this because I have a command nix-rebuild
set up that uses nix-env -i --remove-all
to replace all of my installed packages with a brand new set, to mimic nixos-rebuild
. But right now I’m struggling with the desire to manually build a tool using nix-shell
and then installing that in my profile (the reason being I want to install in-development versions of a tool). I could absolutely do that, except this custom build will be thrown away the next time I run nix-rebuild
. And I can’t just whip up a derivation for this unless I want to be constantly editing this derivation to point at new commits.
So I had the thought, if I could layer multiple profiles together, then I could have nix-rebuild
operate on a sort of “base” profile and then layer on top a separate “custom” profile that I can manipulate with nix-env
. This way I can continue to use nix-env
manually and nix-rebuild
won’t interfere.
But I’m not sure this is practical to do. It looks like nix-env -i
has a --from-profile
flag that lets me copy store paths from one profile to another, so in theory I could do something like nix-env -i --remove-all --from-profile /path/to/base/profile '.*' && nix-env -i --preserve-installed --from-profile /path/to/customized/profile '.*'
, but this is not atomic. I haven’t actually tested this to even figure out if it would work at all, but the fact that it’s not atomic is worrying.
Has anyone else tried to do something like this?