Why Does Nothing Work, 2024 ▶ NixOS Tutorials - Basic Maintenance
Basic NixOS skills to maintain your machine.
Tldr
After watching this I added automatic garbage collection, nix store optimization, and automatic upgrades to my nix config.
Timestamps
- YT=00:00 - Start of video
Notes
I dont feel like taking much notes since i can just write the code into my configuration and reference it later. i should still take some notes tho.
Updates
Updating packages, channels, etc.
Manual
you can rebuild your system to upgrade the inputs: doas nixos-rebuild switch --flake ~/.dotfiles/#ThinkPad
Scheduled
system.autoUpgrade = {
enable = true;
flake = inputs.self.outPath; # for flake based systems
flags = [
"--update-input"
"nixpkgs"
"-L"
];
dates = "09:00";
randomizedDelaySec = "45min";
};to check the upgrade status run: systemctl status nixos-upgrade.service
Rollbacks (Generations)
Rollbacks can roll back to a working generation but it doesnt roll back:
- Config files
- documents
- etc
Commands:
- List generations & current generation:
nixos-rebuild list-generations - Rollback (without reboot):
nix-env --switch-generation 60 -p /nix/var/nix/profiles/system- Rollback (with reboot): reboot then pick a generation to boot into.
- set current generation to default boot:
/run/current-system/bin.switch-to-configuration boot
roll back by rebooting and choosing a generation. you can make this the default generation to boot from by running: /run/current-system/bin.switch-to-configuration boot
Another way to check which generation you are running:
- run
ls /var/run/*system -lahwhich will return generations and hashes. - run
ls -lah /nix/var/nix/profiles/|grep HASHreplacing HASH with the hash you are checking.
Garbage Collection
Manual
- run the gc:
nix-collect-garbage --delete-older-than 10d
Scheduled
nix.gc = {
automatic = true;
dates = "02:05";
randomizedDelaySec = "45min";
options = "--delete-older-than 365d";
};Nix Store Optimization
Manual
- to optimize: “
Scheduled
nix.optimise = {
automatic = true;
dates = [ "01:05" ];
};