Nix to Debian phrasebook: Difference between revisions

From NixOS Wiki
imported>Makefu
Cookbook -> Nix_to_Debian phrasebook
 
imported>Makefu
add nix-locate
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{note|Merge with [[Cheatsheet]]}}
{|
{|
!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; [ &lt;other packages...&gt; emacs ];</code>
| 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) &amp;&amp; nix-store -q --tree /nix/var/nix/profiles/system</code>
| <code>nix-store --query --requisites $(readlink -f /run/current-system) &amp;&amp; nix-store -q --tree /nix/var/nix/profiles/system</code>
| <code>nix-store --query --references $(nix-instantiate '&lt;nixpkgs&gt;' -A emacs)</code>
| <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 &lt;name&gt;</code>Remove a channel. <code>nix-channel --remove &lt;name&gt;</code><br>Show all installed channel. <code>nix-channel --list</code>
| 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 = &quot;/home/alice&quot;; description = &quot;Alice Foobar&quot;; extraGroups = [ &quot;wheel&quot; &quot;networkmanager&quot; ]; openssh.authorizedKeys.keys = [ &quot;ssh-dss AAAAB3Nza... alice@foobar&quot; ]; };</code> to /etc/nixos/configuration.nix. Then run <code>nixos-rebuild switch</code>
| 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 '&lt;nixpkgs&gt;' -A lib.nixpkgsVersion</code>
| <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 '&lt;nixpkgs&gt;')</code><br>To download the source as specified by the package recipe: <code>nix-build '&lt;nixpkgs&gt;' -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 '&lt;nixpkgs&gt;' -A emacs --command 'unpackPhase; patchPhase'</code><br>Compile &amp; install a package from source <code>git clone foobar &amp;&amp; echo &quot;with import &lt;nixpkgs&gt; { }; stdenv.lib.overrideDerivation foobar (oldAttrs: { src = ./foobar })&quot; &gt; default.nix &amp;&amp; nix-build</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 '<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 &amp; install a package from source <code>git clone foobar &amp;&amp; echo "with import <nixpkgs> { }; stdenv.lib.overrideDerivation foobar (oldAttrs: { src = ./foobar })" > default.nix &amp;&amp; nix-build</code>
|
|



Latest revision as of 08:59, 15 September 2017

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