Nix to Debian phrasebook

From NixOS Wiki
Revision as of 08:59, 15 September 2017 by Makefu (talk | contribs) (add nix-locate)
Jump to: navigation, search
Note: Merge with Cheatsheet
Task Ubuntu NixOS (system-wide and root) NixOS (user) and Nix in general
Install a package sudo apt-get install emacs In /etc/nixos/configuration.nix: systemPackages = with pkgs; [ <other packages...> emacs ]; nix-env -iA nixpkgs.emacs
Uninstall a package sudo apt-get remove emacs remove from /etc/nixos/configuration.nix: sudo nixos-rebuild switch nix-env -e emacs
Uninstall a package removing its configuration apt-get purge emacs All configuration is in configuration.nix
Update the list of packages sudo apt-get update sudo nix-channel --update nix-channel --update
Upgrade packages sudo apt-get upgrade sudo nixos-rebuild switch nix-env -u
Check for broken dependencies sudo apt-get check nix-store --verify --check-contents unneeded!
List package dependencies apt-cache depends emacs nix-store --query --requisites $(readlink -f /run/current-system) && nix-store -q --tree /nix/var/nix/profiles/system nix-store --query --references $(nix-instantiate '<nixpkgs>' -A emacs)
List which packages depend on this one (reverse dependencies) apt-cache rdepends emacs For installed packages (only print reverse dependencies which are already installed): nix-store --query --referrers $(which emacs)
Verify all installed packages debsums sudo nix-store --verify --check-contents nix-store --verify --check-contents
Fix packages with failed checksums Reinstall broken packages sudo nix-store --verify --check-contents --repair nix-store --verify --check-contents --repair
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. Add the unstable channel. At that address you will find names for other versions and variants. Name can be any string. nix-channel --add https://nixos.org/channels/nixpkgs-unstable <name>Remove a channel. nix-channel --remove <name>
Show all installed channel. nix-channel --list
When run by a user channels work locally, when run by root they're used as the system-wide channels.
Private package repository PPA 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.
Configure a package sudo dpkg-reconfigure <package> edit /etc/nixos/configuration.nix edit ~/.nixpkgs/config.nix
Find packages apt-cache search emacs or apt search nix-env -qaP '.*emacs.*' nix-env -qaP '.*emacs.*'
Find a package which provides a file with apt-file installed: apt-file search bin/emacs with nix-index installed: nix-locate bin/emacs nix-locate bin/emacs
Show package description apt-cache show emacs nix-env -qa --description '.*emacs.*' nix-env -qa --description '.*emacs.*'
Show files installed by package dpkg -L emacs du -a $(readlink -f $(which emacs))
Show package for file dpkg -S /usr/bin/emacs follow the symlink follow the symlink
Adding a user sudo adduser alice Add users.extraUsers.alice = { isNormalUser = true; home = "/home/alice"; description = "Alice Foobar"; extraGroups = [ "wheel" "networkmanager" ]; openssh.authorizedKeys.keys = [ "ssh-dss AAAAB3Nza... alice@foobar" ]; }; to /etc/nixos/configuration.nix. Then run nixos-rebuild switch
List binaries ls /usr/bin/ ls /run/current-system/sw/bin && ls /nix/var/nix/profiles/default/bin/ ls ~/.nix-profile/bin
Get the current version number cat /etc/debian_version nixos-version nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion
Get sources for a package apt-get source emacs 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: grep -r emacs $(nix-instantiate --eval --expr '<nixpkgs>')
To download the source as specified by the package recipe: nix-build '<nixpkgs>' -A emacs.src
The patched source is usually not a derivation itself, but can be produced for most packages with the following command: nix-shell '<nixpkgs>' -A emacs --command 'unpackPhase; patchPhase'
Compile & install a package from source git clone foobar && echo "with import <nixpkgs> { }; stdenv.lib.overrideDerivation foobar (oldAttrs: { src = ./foobar })" > default.nix && nix-build
Install a .deb dpkg -i package.deb Install dpkg with Nix, then dpkg -i package.deb