Nix Installation Guide: Difference between revisions

imported>DavHau
No edit summary
imported>Doronbehar
Remove now uneeded NFS patch with sqlite-wal
Line 3: Line 3:
== Single-user install ==
== Single-user install ==


To install Nix from any Linux distribution, use the following two commands. (Note: This assumes you have the permission to use <code>sudo</code>, and you are logged in as the user you want to install Nix for.)
=== Stable Nix ===
 
To install stable Nix from any Linux distribution, use the following two commands. (Note: This assumes you have the permission to use <code>sudo</code>, and you are logged in as the user you want to install Nix for.)


<syntaxHighlight lang="console">
<syntaxHighlight lang="console">
Line 19: Line 21:
After that being done, you can use all Nix commands as a normal user without any special permissions (for example by using <code>sudo</code>).
After that being done, you can use all Nix commands as a normal user without any special permissions (for example by using <code>sudo</code>).


==== User namespaces ====
==== Troubleshooting ====
 
===== User namespaces =====
If the installation fails with the following error:
If the installation fails with the following error:
<pre>
<pre>
Line 29: Line 33:
enabled by default on Linux which requires user namespaces.
enabled by default on Linux which requires user namespaces.
If possible enable them; the procedure depends on the distribution. In last resort, you can disable the sandbox: create the file <code>~/.config/nix/nix.conf</code> and include the line <code>sandbox = false</code>.
If possible enable them; the procedure depends on the distribution. In last resort, you can disable the sandbox: create the file <code>~/.config/nix/nix.conf</code> and include the line <code>sandbox = false</code>.
=== Unstable Nix ===
To install unstable Nix with flakes support, you can use the [https://github.com/numtide/nix-unstable-installer unofficial installer by @numtide]. Instructions are available in the README of the repository.


== Nix store on an unusual filesystem ==
== Nix store on an unusual filesystem ==
=== Case insensitive filesystem on Linux ===
=== Case insensitive filesystem on Linux ===
Most Linux filesystems are case sensitive. If your nix store is on a case insensitive filesystem like CIFS on Linux, derivation outputs cannot contain two files differing only in case in the same directory. Nix can work around this by adding <code>use-case-hack = true</code> to your nix configuration (<code>/etc/nix/nix.conf</code> for a multi-user-install or <code>~/.config/nix/nix.conf</code> otherwise). Unfortunately, this will change the hash of some derivations and thus make the binary cache useless.
Most Linux filesystems are case sensitive. If your nix store is on a case insensitive filesystem like CIFS on Linux, derivation outputs cannot contain two files differing only in case in the same directory. Nix can work around this by adding <code>use-case-hack = true</code> to your nix configuration (<code>/etc/nix/nix.conf</code> for a multi-user-install or <code>~/.config/nix/nix.conf</code> otherwise). Unfortunately, this will change the hash of some derivations and thus make the binary cache useless.
=== WSL ===
The same caveats as NFS below apply.


=== NFS ===
=== NFS ===
Without special care, concurrent use of Nix if the nix store is on a NFS filesystem may corrupt Nix's sqlite database.
To prevent this, add <code>use-sqlite-wal = false</code> to your nix configuration and recompile nix with this patch:


<syntaxHighlight lang="diff">
With a Nix store residing on an NFS filesystem, concurrent use of Nix may corrupt Nix's sqlite database. To prevent this, set <code>use-sqlite-wal = false</code>. Since [https://github.com/NixOS/nix/pull/5475 nix/pull/5475 nix/pull/5475] and it's backports to the stable branches, a patch that was previously described in this wiki is no longer needed for using Nix on WSL (Windows' Subsystem for Linux) and NFS filesystems.
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -28,7 +28,7 @@ namespace nix {
SQLite::SQLite(const Path & path)
{
    if (sqlite3_open_v2(path.c_str(), &db,
-           SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0) != SQLITE_OK)
+            SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, "unix-dotfile") != SQLITE_OK)
        throw Error(format("cannot open SQLite database '%s'") % path);
}</syntaxHighlight>
 
(source: [https://github.com/NixOS/nix/issues/2357 this issue])
 
Nix is hard to build by hand, but you can still use vanilla nix without concurrent use, so you can install nix with a NFS store as follows:
* Install nix with the vanilla binary installer
* Create a file <code>~/.config/nixpkgs/config.nix</code> as follows, and place the patch above alongside it.
<syntaxHighlight lang="nix">
{
        packageOverrides = pkgs: {
                nix = pkgs.nix.overrideAttrs (old: {
                                patches = (old.patches or []) ++ [ ./nfs.patch ];
                      });
        };
}
</syntaxHighlight>
* Run <code>nix-env -iA nixpkgs.nix</code> to compile and install the new, patched nix.
* From then on, you can use nix concurrently without risk of corrupting the sqlite database.


== Installing without root permissions ==
== Installing without root permissions ==