Nix (command): Difference between revisions

DoggoBit (talk | contribs)
m DoggoBit moved page Nix command to Nix (command): Use disambiguation-style naming
Malix (talk | contribs)
No edit summary
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Navbox Nix}}
{{Disambiguation|message=This article is about the new nix command. Not to be confused with the [[Nix ecosystem]], the [[Nix (language)|Nix language]] or the [[Nix (package manager)|Nix package manager]].}}
This article is about the new <code>nix</code> command and all of its subcommands. The new <code>nix</code> command is intended to unify many different Nix package manager utilities that exist currently as many separate commands, eg. <code>nix-build</code>, <code>nix-shell</code>, etc.  
This article is about the new <code>nix</code> command and all of its subcommands. The new <code>nix</code> command is intended to unify many different Nix package manager utilities that exist currently as many separate commands, eg. <code>nix-build</code>, <code>nix-shell</code>, etc.  


Line 5: Line 8:
== Enabling the nix command ==
== Enabling the nix command ==


In nix 2.4 the nix command must be enabled explicitly set. You can do this in a few different ways.
In nix 2.4, the nix command must be explicitly enabled. You can do this in a few different ways.


For an individual invocation, eg.
=== As an individual invocation ===
<syntaxHighlight lang=text>
<syntaxhighlight lang="console">
nix --experimental-features nix-command build ...
nix --experimental-features nix-command build ...
</syntaxHighlight>
</syntaxhighlight>


Or by setting a user-specific configuration,
=== By setting it in the nix configuration ===
<syntaxHighlight lang=toml>
{{File|3=experimental-features = nix-command|name=~/.config/nix/nix.conf|lang=toml}}
# ~/.config/nix/nix.conf
experimental-features = nix-command
</syntaxHighlight>
in <code>~/.config/nix/nix.conf</code>.


On NixOS you can't edit <code>/etc/nix/nix.conf</code> directly, but you can enable this feature by editing <code>/etc/nixos/configuration.nix</code>:
=== On NixOS, by setting it in the NixOS configuration ===
<syntaxHighlight lang=nix>
''On NixOS you can't edit <code>/etc/nix/nix.conf</code> directly, so you have to set it through the NixOS configuration instead''
#
{{File|3={ pkgs, ... }: {
{ pkgs, ... }: {
  …
   nix.settings.experimental-features = [ "nix-command" ];
   nix.settings.experimental-features = [ "nix-command" ];
  …
}|name=/etc/nixos/configuration.nix|lang=nix}}{{Evaluate}}
}
</syntaxHighlight>
and then run <code>sudo nixos-rebuild switch</code> as always.
 
== Switching between <code>nix-env</code> and <code>nix profile</code> ==
 
{{warning|Be careful when testing.
Once you have used <code>nix profile</code> you can no longer use <code>nix-env</code> without first deleting <code>/nix/var/nix/profiles/per-user/$USER/profile</code>}}


Once you installed a package with <code>nix profile</code>, you
== Switching from <code>nix profile</code> to <code>nix-env</code> ==
get the following error message when using <code>nix-env</code>:
{{Warning|Using <code>nix-env</code> is not recommended.}}
Once you installed a package with <code>nix profile</code>, you get the following error message when using <code>nix-env</code>:


<syntaxHighlight lang=console>
<syntaxHighlight lang=console>
Line 44: Line 34:
</syntaxHighlight>
</syntaxHighlight>


To migrate back to <code>nix-env</code> you can delete your current profile:
To migrate from <code>nix profile</code> to <code>nix-env</code>, you need to delete your current profile:


{{warning|This will delete packages that have been installed before, so you may want to back this information before running the command.}}
{{warning|This will delete packages that have been installed before, so you may want to back this information before running the command.}}
Line 53: Line 43:


== New equivalents to old commands ==
== New equivalents to old commands ==
<syntaxHighlight lang=console>
<syntaxhighlight lang="shell">
# create a store derivation for a package defined in the current directory's default.nix
# create a store derivation for a package defined in the current directory's default.nix
old$ nix-instantiate -A somepackage
old$ nix-instantiate -A somepackage
Line 60: Line 50:
# alternative option
# alternative option
new$ nix derivation show .#somepackage | jq '.[keys[0]]' | nix derivation add
new$ nix derivation show .#somepackage | jq '.[keys[0]]' | nix derivation add
</syntaxHighlight>
</syntaxhighlight>


[[Category:Nix]]
[[Category:Nix]]