to using a cloned nixpkgs git repo as my nixos channel.
This is mainly because the channel workflow makes some things problematic:
After I sudo nix-channel --update and start nixos-rebuild boot, I sometimes notice that now I don’t have the time to finish the upgrade. So I Ctrl-C it. But then my channel is already changed, and I can no longer edit configuration.nix and apply some simple, instantaneous changes, because any subsequent nixos-rebuild switch will use the updated channel and thus take a long time. Channels do not seem to have local history, so I cannot undo my nix-channel --update if I did not write down what the previous version was.
I would like to keep track of all NixOS versions I ever ran, even past GC. A git reflog would make that every easy.
Unfortunately, I cannot seem to add a directory as a channel:
importing a specific revision inside configuration.nix is also not a good option for me, because it seems configuration.nix is just a nixos module (loaded from where?) and it does not even refer to the <nixos> import, so that probably is not as complete as changing the channel.
I could write NIX_PATH=... in front of every command I run, but that is easy to forget.
nix-channel doesn’t have any kind of support for this that I know of. You’ll need to use -I nixpkgs=./nixpkgs on the command line (I use a wrapper script for this), and you’ll probably want to set nix.nixPath = ["nixpkgs=${./nixpkgs}"]; in your config. Interestingly, this combination will make every generation’s NIX_PATH point <nixpkgs> to the exact version of nixpkgs that the generation was built with. Personally I rather like that.
import ing a specific revision inside configuration.nix is also not a good option for me, because it seems configuration.nix is just a nixos module (loaded from where?) and it does not even refer to the <nixos> import, so that probably is not as complete as changing the channel.
That is, in configuration.nix, I pinned the nixpkgs repo and set the nixpkgs reference in NIX_PATH to point to that version. This way it’s declarative (rollbacks and all) and I could remove all channels for the root user. I also cleared the channel list for my own user, and do nix-env -f '<nixpkgs>' for user environment stuff. As stated in the post, the only caveat is that when changing the nixpkgs version, I need to rebuild twice (or supply a -I nixpkgs=...), since NIX_PATH is set as a result of evaluating configuration.nix (and not the other way around, I assume).
Just tried it out the other day and no problems so far. If there’s a better way go about this I’d love to hear about it. In the long run I think Nix flakes was made for addressing these things.