Try out packages, change system settings then erase every change and revert by rebuild

Is this possible in NixOS?

I know about nix-shell but that is limited to the shell environment. I want something that will survive a restart (I may spend a few days trying out different software for example). Preserving home directory is nice but not essential.

Very newbie question I know but I am trying to decide if NixOS is good for me and worth the learning curve.

I still don’t know the right words to search the posts so sorry if this is a repeat question.

Thanks

Yeah, this should be super doable. For instance, the way I achieve this is by keeping my NixOS (and Home Manager) config in a Git repo. You can make a change to your config, commit to Git, run nixos-rebuild switch, then use it for some amount of time. If you don’t like it, you can just revert back to an earlier Git commit before you made those changes, then run nixos-rebuild switch again.

Have you used Git before? Let me know if more details would be helpful.

5 Likes

I think impermanance is what you are looking for. This is somethings a lot of people do to keep their machines clean. Here are some resources to look through. But take you’re time. It can be a bit daunting at first:

https://nixos.wiki/wiki/Impermanence

and this is a good blog post explaning stuff, and where I think the phrase erase your darlings started.

https://grahamc.com/blog/erase-your-darlings/

2 Likes

Thanks. So effectively I have to declare things I want to try then undeclare them when I want to get rid of them. There is no special command, right?

I haven’t used Git (maybe in the future!) but I think I can use a backup tool with versioning. Thanks for the suggestion.

Thanks for the links. I will check them out! :+1:

FWIW, preservation is an implementation of this that doesn’t rely on activation scripts, and therefore a fair bit more robust.

I’d call these things helpful in accomplishing the goal of clean configuration switching, but not necessary. Git is far more essential.

2 Likes

Maybe have a look at nixos-rebuild test too. It applies your configuration but doesn’t update your boot loader so if something’s not right you can just reboot. Doesn’t help with system state though.

1 Like