Ubuntu vs. NixOS: Difference between revisions
see also added |
formatting and style fixes :-) |
||
| Line 88: | Line 88: | ||
|- | |- | ||
|Uninstall a package | |Uninstall a package | ||
|<syntaxhighlight lang=" | |<syntaxhighlight lang="console">$ sudo apt-get remove emacs</syntaxhighlight> | ||
|remove from /etc/nixos/configuration.nix | |remove from /etc/nixos/configuration.nix | ||
<syntaxhighlight lang="console">$ sudo nixos-rebuild switch</syntaxhighlight> | <syntaxhighlight lang="console">$ sudo nixos-rebuild switch</syntaxhighlight> | ||
| Line 121: | Line 121: | ||
<syntaxhighlight lang="console">$ nix-store -q --tree /nix/var/nix/profiles/system</syntaxhighlight> | <syntaxhighlight lang="console">$ nix-store -q --tree /nix/var/nix/profiles/system</syntaxhighlight> | ||
(/run/current-system and /nix/var/nix/profiles/system are symbolic links that eventually end up at the same place.) | (/run/current-system and /nix/var/nix/profiles/system are symbolic links that eventually end up at the same place.) | ||
|<syntaxhighlight lang="console">$ nix-store --query --references\ | |<syntaxhighlight lang="console">$ nix-store --query --references \ | ||
$(nix-instantiate '<nixpkgs>' -A emacs)</syntaxhighlight> | $(nix-instantiate '<nixpkgs>' -A emacs)</syntaxhighlight> | ||
For installed packages: | For installed packages: | ||
| Line 144: | Line 144: | ||
|Select major version and stable/unstable | |Select major version and stable/unstable | ||
|Change sources.list and apt-get dist-upgrade. A an extremely infrequent and destructive operation. The nix variants are safe and easy to use. | |Change sources.list and apt-get dist-upgrade. A an extremely infrequent and destructive operation. The nix variants are safe and easy to use. | ||
|<syntaxhighlight lang="console">$ nix-channel --add\ | |<syntaxhighlight lang="console">$ nix-channel --add \ | ||
https://nixos.org | https://channels.nixos.org/nixpkgs-unstable <name></syntaxhighlight> | ||
Add the unstable channel. At that address you will find names for other versions and variants. Name can be any string. | Add the unstable channel. At that address you will find names for other versions and variants. Name can be any string. | ||
<syntaxhighlight lang="console">$ nix-channel --remove <name></syntaxhighlight> | <syntaxhighlight lang="console">$ nix-channel --remove <name></syntaxhighlight> | ||
| Line 167: | Line 167: | ||
$ nix-shell \ | $ nix-shell \ | ||
-p vim \ | -p vim \ | ||
-I nixpkgs= | -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/4bba6650a6a5a2009e25bdeed8c1e871601a9bfb.tar.gz | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| | | | ||
| Line 198: | Line 198: | ||
/nix/store/ji06y4haijly0i0knmr986l2dajffv1p-emacs-24.4/bin/emacs-24.4</syntaxhighlight> | /nix/store/ji06y4haijly0i0knmr986l2dajffv1p-emacs-24.4/bin/emacs-24.4</syntaxhighlight> | ||
then | then | ||
<syntaxhighlight lang="console">$du -a /nix/store/ji06y4haijly0i0knmr986l2dajffv1p-emacs-24.4</syntaxhighlight> | <syntaxhighlight lang="console">$ du -a /nix/store/ji06y4haijly0i0knmr986l2dajffv1p-emacs-24.4</syntaxhighlight> | ||
|<syntaxhighlight lang="console"></syntaxhighlight> | |<syntaxhighlight lang="console"></syntaxhighlight> | ||
|- | |- | ||
|Show package for file | |Show package for file | ||
|<syntaxhighlight lang="console">$ dpkg -S /usr/bin/emacs</syntaxhighlight> | |<syntaxhighlight lang="console">$ dpkg -S /usr/bin/emacs</syntaxhighlight> | ||
|follow the symlink or <syntaxhighlight lang="console">nix-locate /bin/emacs</syntaxhighlight> (requires <syntaxhighlight lang="console">nix-index</syntaxhighlight> package) | |follow the symlink or <syntaxhighlight lang="console">$ nix-locate /bin/emacs</syntaxhighlight> (requires <syntaxhighlight lang="console">$ nix-index</syntaxhighlight> package) | ||
|(same) | |(same) | ||
|- | |- | ||
| Line 220: | Line 220: | ||
| Enable a service | | Enable a service | ||
| <syntaxhighlight lang="console">$ sudo systemctl enable apache</syntaxhighlight> | | <syntaxhighlight lang="console">$ sudo systemctl enable apache</syntaxhighlight> | ||
| In /etc/nixos/configuration.nix, add <syntaxhighlight lang=" | | In /etc/nixos/configuration.nix, add <syntaxhighlight lang="nix">services.tor.enable = true;</syntaxhighlight>, then run <syntaxhighlight lang="console">$ sudo nixos-rebuild switch</syntaxhighlight> | ||
|- | |- | ||
| Disable a service | | Disable a service | ||
| <syntaxhighlight lang="console">$ sudo systemctl disable apache</syntaxhighlight> | | <syntaxhighlight lang="console">$ sudo systemctl disable apache</syntaxhighlight> | ||
| In /etc/nixos/configuration.nix, add <syntaxhighlight lang=" | | In /etc/nixos/configuration.nix, add <syntaxhighlight lang="nix">services.tor.enable = false;</syntaxhighlight>, then run <syntaxhighlight lang="console">$ sudo nixos-rebuild switch</syntaxhighlight> | ||
|- | |- | ||
|Where your log files live | |Where your log files live | ||
| Line 233: | Line 233: | ||
|Adding a user | |Adding a user | ||
|<syntaxhighlight lang="console">$ sudo adduser alice</syntaxhighlight> | |<syntaxhighlight lang="console">$ sudo adduser alice</syntaxhighlight> | ||
|Add <syntaxhighlight lang="nix">users.users.alice = | |Add <syntaxhighlight lang="nix">users.users.alice = { | ||
isNormalUser = true; | |||
home = "/home/alice"; | |||
description = "Alice Foobar"; | |||
extraGroups = [ "wheel" "networkmanager" ]; | |||
openssh.authorizedKeys.keys = | |||
[ "ssh-dss AAAAB3Nza... alice@foobar" ]; | |||
};</syntaxhighlight> to /etc/nixos/configuration.nix and then call <syntaxhighlight lang="console">$ nixos-rebuild switch</syntaxhighlight> | |||
| | | | ||
|- | |- | ||
| Line 247: | Line 247: | ||
|List binaries | |List binaries | ||
|<syntaxhighlight lang="console">$ ls /usr/bin/</syntaxhighlight> | |<syntaxhighlight lang="console">$ ls /usr/bin/</syntaxhighlight> | ||
|<syntaxhighlight lang="console">$ ls /run/current-system/sw/bin &&\ | |<syntaxhighlight lang="console">$ ls /run/current-system/sw/bin && \ | ||
ls /nix/var/nix/profiles/default/bin/</syntaxhighlight> | ls /nix/var/nix/profiles/default/bin/</syntaxhighlight> | ||
|<syntaxhighlight lang="console">$ ls ~/.nix-profile/bin</syntaxhighlight> | |<syntaxhighlight lang="console">$ ls ~/.nix-profile/bin</syntaxhighlight> | ||
|- | |- | ||
| Line 257: | Line 257: | ||
|- | |- | ||
|Get sources for a package | |Get sources for a package | ||
|<syntaxhighlight lang=" | |<syntaxhighlight lang="console">$ sudo apt-get source emacs</syntaxhighlight> | ||
| | | | ||
|In Debian, apt-get source gets both the patched upstream source and the recipe for the package. Those need two steps in Nix. | |In Debian, apt-get source gets both the patched upstream source and the recipe for the package. Those need two steps in Nix. | ||
To find the package's attribute path: <syntaxhighlight lang="console">$ nix-env -qaP emacs</syntaxhighlight> or <syntaxhighlight lang="console">$ nox emacs</syntaxhighlight> | To find the package's attribute path: <syntaxhighlight lang="console">$ nix-env -qaP emacs</syntaxhighlight> or <syntaxhighlight lang="console">$ nox emacs</syntaxhighlight> | ||
To download the source as specified by the package recipe: <syntaxhighlight lang=" | To download the source as specified by the package recipe: <syntaxhighlight lang="console">$ nix-build '<nixpkgs>' -A emacs.src</syntaxhighlight> | ||
The patched source is usually not a derivation itself, but can be produced for most packages with the following command: <syntaxhighlight lang=" | The patched source is usually not a derivation itself, but can be produced for most packages with the following command: <syntaxhighlight lang="console">$ nix-shell '<nixpkgs>' -A emacs \ | ||
--command 'unpackPhase; cd $sourceRoot; patchPhase'</syntaxhighlight> | --command 'unpackPhase; cd $sourceRoot; patchPhase'</syntaxhighlight> | ||
|- | |- | ||
| Line 269: | Line 269: | ||
| | | | ||
| | | | ||
|<syntaxhighlight lang="console">git clone foobar | |<syntaxhighlight lang="console">$ git clone foobar | ||
cat >default.nix <<EOF | $ cat > default.nix <<EOF | ||
with import <nixpkgs> { }; | with import <nixpkgs> { }; | ||
lib.overrideDerivation foobar (oldAttrs : { | lib.overrideDerivation foobar (oldAttrs : { | ||
| Line 276: | Line 276: | ||
}) | }) | ||
EOF | EOF | ||
nix-build</syntaxhighlight> | $ nix-build</syntaxhighlight> | ||
|- | |- | ||
|Install a binary package | |Install a binary package | ||
| | | | ||
| | | | ||
|e.g. via [https://github.com/ | |e.g. via [https://github.com/nix-community/nix-ld#nix-ld nix-ld] | ||
|- | |- | ||
|Install a .deb | |Install a .deb | ||
|<syntaxhighlight lang="console">$ sudo dpkg -i package.deb</syntaxhighlight> | |<syntaxhighlight lang="console">$ sudo dpkg -i package.deb</syntaxhighlight> | ||
| | | | ||
|Install dpkg with Nix, then <syntaxhighlight lang=" | |Install dpkg with Nix, then <syntaxhighlight lang="console">$ dpkg -i package.deb</syntaxhighlight> While this is technically possible it will in all likelihood not work. | ||
|} | |} | ||
</div> | </div> | ||