Cheatsheet: Difference between revisions
imported>Fadenb No edit summary |
imported>Fadenb No edit summary |
||
| Line 11: | Line 11: | ||
!|NixOS (system-wide and root) | !|NixOS (system-wide and root) | ||
!|NixOS (user) and Nix in general | !|NixOS (user) and Nix in general | ||
|- | |- | ||
| colspan="5" style="text-align:center"| Basic concepts | | colspan="5" style="text-align:center"| Basic concepts | ||
| Line 19: | Line 18: | ||
|This column will let you do everything you can with Ubuntu and more. | |This column will let you do everything you can with Ubuntu and more. | ||
|This column just isn't possible in Ubuntu. | |This column just isn't possible in Ubuntu. | ||
|- | |- | ||
|Who can install packages and who can run them? | |Who can install packages and who can run them? | ||
| Line 25: | Line 23: | ||
|Packages root installs are system-wide. It does so through through /etc/nixos/configuration.nix. If root installs packages the same way users do, through ~/.nixpkgs/config.nix, they are also global. Root's default profile is the system-wide default profile. | |Packages root installs are system-wide. It does so through through /etc/nixos/configuration.nix. If root installs packages the same way users do, through ~/.nixpkgs/config.nix, they are also global. Root's default profile is the system-wide default profile. | ||
|Users can install their own packages and have their own profiles (environments) through ~/.nixpkgs/config.nix | |Users can install their own packages and have their own profiles (environments) through ~/.nixpkgs/config.nix | ||
|- | |- | ||
|Package manager | |Package manager | ||
| Line 32: | Line 28: | ||
|nix, but many system-wide operations are provided by nixos packages. | |nix, but many system-wide operations are provided by nixos packages. | ||
|Just nix without the involvement of nixos. | |Just nix without the involvement of nixos. | ||
|- | |- | ||
|How do you select your official sources and major releases | |How do you select your official sources and major releases | ||
| Line 38: | Line 33: | ||
|At any time you select from a collection of channels. They're system-wide when set by root. You can roll back changes or switch channels with ease. | |At any time you select from a collection of channels. They're system-wide when set by root. You can roll back changes or switch channels with ease. | ||
|Channels are per-user if they're not set by root. | |Channels are per-user if they're not set by root. | ||
|- | |- | ||
|Where are packages installed? | |Where are packages installed? | ||
| Line 44: | Line 38: | ||
|System-wide packages are in /run/current-system/sw/ (these are installed because of /etc/nixos/configuration.nix) and /nix/var/nix/profiles/default/bin/ (this is the profile managed by root). Note that the files are just symlinks to the real packages managed by nix /nix/store/. | |System-wide packages are in /run/current-system/sw/ (these are installed because of /etc/nixos/configuration.nix) and /nix/var/nix/profiles/default/bin/ (this is the profile managed by root). Note that the files are just symlinks to the real packages managed by nix /nix/store/. | ||
|User packages are in ~/.nix-profile/. Note that the files are just symlinks to the real packages managed by nix in /nix/store/. | |User packages are in ~/.nix-profile/. Note that the files are just symlinks to the real packages managed by nix in /nix/store/. | ||
|- | |- | ||
|When changes take effect | |When changes take effect | ||
| Line 52: | Line 45: | ||
|Most of the time you apply changes with nix-env -i all | |Most of the time you apply changes with nix-env -i all | ||
TODO How does one get nix to do all the work for a switch and separate out the actual switching from fetching/building? | TODO How does one get nix to do all the work for a switch and separate out the actual switching from fetching/building? | ||
|- | |- | ||
|Packages | |Packages | ||
| Line 58: | Line 50: | ||
|Technically called "derivations" but everyone calls them packages. | |Technically called "derivations" but everyone calls them packages. | ||
|Technically called "derivations" but everyone calls them packages. | |Technically called "derivations" but everyone calls them packages. | ||
|- | |- | ||
| colspan="5" style="text-align:center"| Package management | | colspan="5" style="text-align:center"| Package management | ||
| Line 75: | Line 66: | ||
Or with collections, add the package to your ~/.nixpkgs/config.nix and run | Or with collections, add the package to your ~/.nixpkgs/config.nix and run | ||
<pre>nix-env -i all</pre> | <pre>nix-env -i all</pre> | ||
|- | |- | ||
|Uninstall a package | |Uninstall a package | ||
| Line 81: | Line 71: | ||
|remove from /etc/nixos/configuration.nix | |remove from /etc/nixos/configuration.nix | ||
<pre>sudo nixos-rebuild switch</pre> | <pre>sudo nixos-rebuild switch</pre> | ||
| | | | ||
|- | |- | ||
| Line 87: | Line 76: | ||
|<pre>apt-get purge emacs</pre> | |<pre>apt-get purge emacs</pre> | ||
|All configuration is in configuration.nix | |All configuration is in configuration.nix | ||
| | | | ||
|- | |- | ||
| Line 94: | Line 82: | ||
|<pre>sudo nix-channel --update</pre> | |<pre>sudo nix-channel --update</pre> | ||
|<pre>nix-channel --update</pre> | |<pre>nix-channel --update</pre> | ||
|- | |- | ||
|Upgrade packages | |Upgrade packages | ||
| Line 100: | Line 87: | ||
|<pre>sudo nixos-rebuild switch</pre> | |<pre>sudo nixos-rebuild switch</pre> | ||
|<pre>nix-env -u</pre> | |<pre>nix-env -u</pre> | ||
|- | |- | ||
|Check for broken dependencies | |Check for broken dependencies | ||
| Line 106: | Line 92: | ||
|<pre>nix-store --verify --check-contents</pre> | |<pre>nix-store --verify --check-contents</pre> | ||
|unneeded! | |unneeded! | ||
|- | |- | ||
|List package dependencies | |List package dependencies | ||
| Line 116: | Line 101: | ||
For installed packages: | For installed packages: | ||
<pre>nix-store --query --references $(which emacs)</pre> | <pre>nix-store --query --references $(which emacs)</pre> | ||
|- | |- | ||
|List which packages depend on this one (reverse dependencies) | |List which packages depend on this one (reverse dependencies) | ||
| Line 123: | Line 107: | ||
|For installed packages (only print reverse dependencies *which are already installed*): | |For installed packages (only print reverse dependencies *which are already installed*): | ||
<pre>nix-store --query --referrers $(which emacs)</pre> | <pre>nix-store --query --referrers $(which emacs)</pre> | ||
|- | |- | ||
|Verify all installed packages | |Verify all installed packages | ||
| Line 129: | Line 112: | ||
|<pre>sudo nix-store --verify --check-contents</pre> | |<pre>sudo nix-store --verify --check-contents</pre> | ||
|<pre>nix-store --verify --check-contents</pre> | |<pre>nix-store --verify --check-contents</pre> | ||
|- | |- | ||
|Fix packages with failed checksums | |Fix packages with failed checksums | ||
| Line 135: | Line 117: | ||
|<pre>sudo nix-store --verify --check-contents --repair</pre> | |<pre>sudo nix-store --verify --check-contents --repair</pre> | ||
|<pre>nix-store --verify --check-contents --repair</pre> | |<pre>nix-store --verify --check-contents --repair</pre> | ||
|- | |- | ||
|Select major version and stable/unstable | |Select major version and stable/unstable | ||
| Line 147: | Line 128: | ||
To show all installed channel. | To show all installed channel. | ||
|When run by a user channels work locally, when run by root they're used as the system-wide channels. | |When run by a user channels work locally, when run by root they're used as the system-wide channels. | ||
|- | |- | ||
|Private package repository | |Private package repository | ||
| Line 153: | Line 133: | ||
|Define your package tree as in the general column, and include it in configuration.nix, then list your packages in systemPackages to make them available system wide | |Define your package tree as in the general column, and include it in configuration.nix, then list your packages in systemPackages to make them available system wide | ||
|See [https://sandervanderburg.blogspot.de/2014/07/managing-private-nix-packages-outside.html] | |See [https://sandervanderburg.blogspot.de/2014/07/managing-private-nix-packages-outside.html] | ||
|- | |- | ||
|Install a particular version of a package | |Install a particular version of a package | ||
| | | | ||
| | | | ||
| Line 167: | Line 145: | ||
|edit /etc/nixos/configuration.nix | |edit /etc/nixos/configuration.nix | ||
|edit ~/.nixpkgs/config.nix TODO More details about how to edit | |edit ~/.nixpkgs/config.nix TODO More details about how to edit | ||
|- | |- | ||
|List package options | |List package options | ||
| | | | ||
| | | | ||
| Line 177: | Line 153: | ||
|Global package configuration | |Global package configuration | ||
|Modify configuration file in /etc/ | |Modify configuration file in /etc/ | ||
| | | | ||
| | | | ||
| Line 187: | Line 162: | ||
|<pre>nix-env -qaP '.*emacs.*'</pre> | |<pre>nix-env -qaP '.*emacs.*'</pre> | ||
|<pre>nix-env -qaP '.*emacs.*'</pre> | |<pre>nix-env -qaP '.*emacs.*'</pre> | ||
|- | |- | ||
|Show package description | |Show package description | ||
| Line 193: | Line 167: | ||
|<pre>nix-env -qa --description '.*emacs.*'</pre> | |<pre>nix-env -qa --description '.*emacs.*'</pre> | ||
|<pre>nix-env -qa --description '.*emacs.*'</pre> | |<pre>nix-env -qa --description '.*emacs.*'</pre> | ||
|- | |- | ||
|Show files installed by package | |Show files installed by package | ||
| Line 202: | Line 175: | ||
<pre>du -a /nix/store/ji06y4haijly0i0knmr986l2dajffv1p-emacs-24.4</pre> | <pre>du -a /nix/store/ji06y4haijly0i0knmr986l2dajffv1p-emacs-24.4</pre> | ||
|<pre></pre> | |<pre></pre> | ||
|- | |- | ||
|Show package for file | |Show package for file | ||
| Line 208: | Line 180: | ||
|follow the symlink | |follow the symlink | ||
|follow the symlink | |follow the symlink | ||
|- | |- | ||
| colspan="5" style="text-align:center"| Services | | colspan="5" style="text-align:center"| Services | ||
| Line 215: | Line 186: | ||
|<pre>sudo service apache start</pre> | |<pre>sudo service apache start</pre> | ||
|<pre>sudo systemctl start apache</pre> | |<pre>sudo systemctl start apache</pre> | ||
| | | | ||
|- | |- | ||
| Line 221: | Line 191: | ||
|<pre>sudo service apache stop</pre> | |<pre>sudo service apache stop</pre> | ||
|<pre>sudo systemctl stop apache</pre> | |<pre>sudo systemctl stop apache</pre> | ||
| | | | ||
|- | |- | ||
| Line 228: | Line 197: | ||
|System-wide packages /var/log/ | |System-wide packages /var/log/ | ||
|User packages ~/.nix-profile/var/log/ | |User packages ~/.nix-profile/var/log/ | ||
|- | |- | ||
|Adding a user | |Adding a user | ||
| Line 240: | Line 208: | ||
[ "ssh-dss AAAAB3Nza... alice@foobar" ]; | [ "ssh-dss AAAAB3Nza... alice@foobar" ]; | ||
};</pre> to to /etc/nixos/configuration.nix and then call <pre>nixos-rebuild switch</pre> | };</pre> to to /etc/nixos/configuration.nix and then call <pre>nixos-rebuild switch</pre> | ||
| | | | ||
|- | |- | ||
| Line 250: | Line 217: | ||
ls /nix/var/nix/profiles/default/bin/</pre> | ls /nix/var/nix/profiles/default/bin/</pre> | ||
|<pre>ls ~/.nix-profile/bin</pre> | |<pre>ls ~/.nix-profile/bin</pre> | ||
|- | |- | ||
|Get the current version number | |Get the current version number | ||
| Line 256: | Line 222: | ||
|<pre>nixos-version</pre> | |<pre>nixos-version</pre> | ||
|<pre>nixos-version</pre> | |<pre>nixos-version</pre> | ||
|- | |- | ||
|Get sources for a package | |Get sources for a package | ||
| Line 267: | Line 232: | ||
The patched source is usually not a derivation itself, but can be produced for most packages with the following command: <pre>nix-shell '<nixpkgs>' -A emacs\ | The patched source is usually not a derivation itself, but can be produced for most packages with the following command: <pre>nix-shell '<nixpkgs>' -A emacs\ | ||
--command 'unpackPhase; patchPhase'</pre> | --command 'unpackPhase; patchPhase'</pre> | ||
|- | |- | ||
|Compile & install a package from source | |Compile & install a package from source | ||
| Line 280: | Line 244: | ||
EOF | EOF | ||
nix-build</pre> | nix-build</pre> | ||
|- | |- | ||
|Install a binary package | |Install a binary package | ||
| | | | ||
| | | | ||
| Line 292: | Line 254: | ||
| | | | ||
|Install dpkg with Nix, then <pre>dpkg -i package.deb</pre> | |Install dpkg with Nix, then <pre>dpkg -i package.deb</pre> | ||
|} | |} | ||