Nix Installation Guide: Difference between revisions

imported>Colemickens
m modify instruction to work out of box in 18.10
imported>Mic92
nix 2.0 variant is useless unless nix is already installed.
Line 38: Line 38:


If the output of this command is <code>CONFIG_USER_NS=y</code>, then your system supports user namespaces.
If the output of this command is <code>CONFIG_USER_NS=y</code>, then your system supports user namespaces.
=== nix 2.0's native method ===
The following command will create a nix store in <code>~/my-nix</code> and spawn a shell, where <code>~/my-nix</code> be mounted to <code>/nix</code>
<syntaxHighlight lang="console">
$ nix run --store ~/my-nix nixpkgs.nix nixpkgs.bashInteractive
</syntaxHighlight>
You can make all nix commands use the alternate store by specifying it in `~/.config/nix/nix.conf` as <code>store = /home/USERNAME/my-nix</code>.


=== nix-user-chroot ===
=== nix-user-chroot ===


[https://github.com/lethalman/nix-user-chroot nix-user-chroot] was the preferred method before nix 2.0 to use nix on systems without <code>/nix</code>. It also requires user namespaces like the <code>--store</code> parameter in nix 2.0.
[https://github.com/lethalman/nix-user-chroot nix-user-chroot] is the preferred method to install use nix on systems without <code>/nix</code>. It also requires user namespaces to be enabled on the system.  
<code>nix-user-chroot</code> will create an environment in which you can bind mount an directory to <code>/nix</code>.
<code>nix-user-chroot</code> will create an environment in which you can bind mount an directory to <code>/nix</code>.
The mountpoint will be only visible within this environment.
The mountpoint will be only visible within this environment.
Line 101: Line 91:


Note that you can only use Nix and the installed programs within the shell started by PRoot.
Note that you can only use Nix and the installed programs within the shell started by PRoot.
=== nix 2.0's native method ===
If nix is already installed on the system i.e. a self-compiled nix itself can also create
a nix store in an alternative user-writable locations.
The following command will create a nix store in <code>~/my-nix</code> and spawn a shell, where <code>~/my-nix</code> be mounted to <code>/nix</code>.
<syntaxHighlight lang="console">
$ nix run --store ~/my-nix nixpkgs.nix nixpkgs.bashInteractive
</syntaxHighlight>
You can make all nix commands use the alternate store by specifying it in `~/.config/nix/nix.conf` as <code>store = /home/USERNAME/my-nix</code>.