TheMaxus

NixOS commands

Package management

Rebuild nixos from /etc/nixos/configure.nix

--upgrade flag to update channels
switch to switch to new configuration and make it default boot configuration
test to switch but not make it default boot configuration

nixos-rebuild <--update> <test/switch>

Start ephemeral shell with package installed

-I nixpkgs=nixpkgs-repo use external nixpkgs repo (in case you packaged something yourself)

nix-shell < -I nixpkgs=nixpkgs-repo> -p pkgname

Use tab-completion in nix repl

note: <>-characters are part of the command

nix repl
nix-repl> :l <nixpkgs>
nix-repl> pkgs.

Building package from local repo

Run from the root of nixpkgs

nix-build -A

Storage optimization

Delete older generations and unused derivations.

nix-collect-garbage -d

Note: this will not delete derivations if any result symlinks point to them, so delete any unused results symilnks before running

Optimize storage (Potentially legnthy operation)

nix-store --optimise