Useful Nix(OS) Commands
Some utility commands that I've found useful in my time using Nix(OS).
- Building a VM from a configuration
nix run .#nixosConfigurations.HOSTNAME.config.system.build.vm
- Cleaning up unused imports in Nix code
Prerequisites:
- Have
pkgs.deadnixinstalled - Commit all changes before running the command in case of accidents
deadnix -eq **/*.nix
- What depends on a package?
`nix why-depends /run/current-system nixpkgs#package-name'
- Only update a specific flake input
nix flake update --update-input <input-name>
- Cleaning up unused containers (usually used after disabling a server module that utilises oci-containers)
sudo podman system prune --all --volumes
- To quickly open a port in the firewall:
sudo iptables -I INPUT -p tcp --dport 1234 -j ACCEPT
And to close it again:
sudo iptables -D INPUT -p tcp --dport 1234 -j ACCEPT.