my system configurations ^-^
1# Nix cheat sheet 2 3> [!warning] 4> this is bad, improvements coming soon™ 5 6 7## `nix-env` package management 8 9| action | Ubuntu | Nix | notes | 10| :------------------ | :--------------------------- | :--------------------------- | :---------------------------------------------------------------------- | 11| update package list | `sudo apt update` | `sudo nix-channel --update` | | 12| search | `apt search <query>` | `nix search <query>` | also try [search.nixos.org/packages](https://search.nixos.org/packages) | 13| install | `sudo apt install <package>` | `nix-env -i <package>` | no root, atomic, per user | 14| upgrade installed | `sudo apt upgrade` | `nix-env -u` | no root, atomic, per user | 15| remove | `sudo apt remove <package>` | `nix-env -e <package>` | no root, atomic, per user | 16| undo last operation | ... | `nix-env --rollback` | no root, atomic, per user | 17| list installed | `dpkg -l` | `nix-env -q` | per user | 18| show generations | ... | `nix-env --list-generations` | | 19 20## `nix-shell` isolated build/dev/run environments 21 22Nix Reference Manual: [nix.dev](https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-shell) 23 24| command | result | 25| :------------------------ | :---------------------------------------------------------------------------- | 26| `nix-shell -p <packages>` | start shell in env with `<packages>` | 27| `nix-shell` | start shell in the env defined by `shell.nix` or `default.nix` in current dir | 28| `nix-shell --pure` | same, but outside env is inaccessible | 29 30## `nix run` run a nix application 31 32Nix Reference Manual: [nix.dev](https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-run) 33 34Examples: 35nix run nixpkgs#vim 36nix run nixpkgs#statix -- help 37nix run github:astro/deadnix -- -eq . 38 39## NixOS declarative operating system configuration management 40 41| command | result | notes | 42| :---------------------------------- | :-------------------------------------------------------------------- | :-------------------------------------------------------------------- | 43| edit `/etc/nixos/configuration.nix` | define new system configuration | running system is unaffected | 44| `nixos-rebuild switch` | switch to the configuration defined in `/etc/nixos/configuration.nix` | atomic\* | 45| `nixos-rebuild switch --rollback` | switch to previous configuration | atomic\* | 46| `nixos-option <option>` | show option value and documentation | also try [search.nixos.org/options](https://search.nixos.org/options) | 47 48\*services can fail to start 49 50## Useful linting commands 51 52### Alejandra 53 54[GitHub](https://github.com/kamadorueda/alejandra) 55 56### Deadnix 57 58[GitHub](https://github.com/astro/deadnix) 59 60#### Check 61 62```bash 63nix run github:astro/deadnix -- . 64``` 65 66#### Format 67 68Remember to commit/stage to git first, as this command will change files. 69 70```bash 71nix run github:astro/deadnix -- -eq . 72```