Nix to Debian phrasebook: Difference between revisions
imported>Makefu Cookbook -> Nix_to_Debian phrasebook |
m Fix merge request |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{merge|Cheatsheet|Duplicated content}} | |||
{| | {| | ||
!width="18%"| Task | !width="18%"| Task | ||
| Line 7: | Line 9: | ||
| Install a package | | Install a package | ||
| <code>sudo apt-get install emacs</code> | | <code>sudo apt-get install emacs</code> | ||
| In /etc/nixos/configuration.nix: <code>systemPackages = with pkgs; [ | | In /etc/nixos/configuration.nix: <code>systemPackages = with pkgs; [ <other packages...> emacs ];</code> | ||
| <code>nix-env -iA nixpkgs.emacs</code> | | <code>nix-env -iA nixpkgs.emacs</code> | ||
|- | |- | ||
| Line 39: | Line 41: | ||
| <code>apt-cache depends emacs</code> | | <code>apt-cache depends emacs</code> | ||
| <code>nix-store --query --requisites $(readlink -f /run/current-system) && nix-store -q --tree /nix/var/nix/profiles/system</code> | | <code>nix-store --query --requisites $(readlink -f /run/current-system) && nix-store -q --tree /nix/var/nix/profiles/system</code> | ||
| <code>nix-store --query --references $(nix-instantiate ' | | <code>nix-store --query --references $(nix-instantiate '<nixpkgs>' -A emacs)</code> | ||
|- | |- | ||
| List which packages depend on this one (reverse dependencies) | | List which packages depend on this one (reverse dependencies) | ||
| Line 59: | Line 61: | ||
| 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. | ||
| Add the unstable channel. At that address you will find names for other versions and variants. Name can be any string. <code>nix-channel --add https://nixos.org/channels/nixpkgs-unstable | | Add the unstable channel. At that address you will find names for other versions and variants. Name can be any string. <code>nix-channel --add https://nixos.org/channels/nixpkgs-unstable <name></code>Remove a channel. <code>nix-channel --remove <name></code><br>Show all installed channel. <code>nix-channel --list</code> | ||
| 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. | ||
|- | |- | ||
| Line 74: | Line 76: | ||
|- | |- | ||
| Find packages | | Find packages | ||
| <code>apt-cache search emacs</code> | | <code>apt-cache search emacs</code> or <code>apt search</code> | ||
| <code>nix-env -qaP '.*emacs.*'</code> | | <code>nix-env -qaP '.*emacs.*'</code> | ||
| <code>nix-env -qaP '.*emacs.*'</code> | | <code>nix-env -qaP '.*emacs.*'</code> | ||
|- | |||
| Find a package which provides a file | |||
| with <code>apt-file</code> installed: <code>apt-file search bin/emacs</code> | |||
| with <code>nix-index</code> installed: <code>nix-locate bin/emacs</code> | |||
| <code>nix-locate bin/emacs</code> | |||
|- | |- | ||
| Show package description | | Show package description | ||
| Line 96: | Line 103: | ||
| Adding a user | | Adding a user | ||
| sudo adduser alice | | sudo adduser alice | ||
| Add <code>users.extraUsers.alice = { isNormalUser = true; home = | | Add <code>users.extraUsers.alice = { isNormalUser = true; home = "/home/alice"; description = "Alice Foobar"; extraGroups = [ "wheel" "networkmanager" ]; openssh.authorizedKeys.keys = [ "ssh-dss AAAAB3Nza... alice@foobar" ]; };</code> to /etc/nixos/configuration.nix. Then run <code>nixos-rebuild switch</code> | ||
| | | | ||
| Line 108: | Line 115: | ||
| <code>cat /etc/debian_version</code> | | <code>cat /etc/debian_version</code> | ||
| <code>nixos-version</code> | | <code>nixos-version</code> | ||
| <code>nix-instantiate --eval ' | | <code>nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion</code> | ||
|- | |- | ||
| Get sources for a package | | Get sources for a package | ||
| <code>apt-get source emacs</code> | | <code>apt-get source emacs</code> | ||
| 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 recipe: <code>grep -r emacs $(nix-instantiate --eval --expr ' | | 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 recipe: <code>grep -r emacs $(nix-instantiate --eval --expr '<nixpkgs>')</code><br>To download the source as specified by the package recipe: <code>nix-build '<nixpkgs>' -A emacs.src</code><br>The patched source is usually not a derivation itself, but can be produced for most packages with the following command: <code>nix-shell '<nixpkgs>' -A emacs --command 'unpackPhase; patchPhase'</code><br>Compile & install a package from source <code>git clone foobar && echo "with import <nixpkgs> { }; stdenv.lib.overrideDerivation foobar (oldAttrs: { src = ./foobar })" > default.nix && nix-build</code> | ||
| | | | ||