Cheatsheet: Difference between revisions
m Replace backticks with proper formatting |
m propose merge |
||
| (5 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{Merge|Nix (command line utilities)}} | |||
This cheatsheet is a collection of handy snippets for working with a NixOS system. | |||
== Working with the nix store == | == Working with the nix store == | ||
| Line 31: | Line 32: | ||
=== Add files to the store === | === Add files to the store === | ||
{{Warning|Editing the Nix Store manually may cause undefined behaviour to occur in Nix's database. Avoid making manual changes to the store unless you are absolutely sure you know what you're doing.}} | |||
It is sometimes necessary to add files to the store manually. | It is sometimes necessary to add files to the store manually. | ||
This is particularly the case with packages that cannot be downloaded automatically, | This is particularly the case with packages that cannot be downloaded automatically, | ||
| Line 90: | Line 92: | ||
This creates the <code>.drv</code> file that <code>nixos-rebuild build</code> would build. | This creates the <code>.drv</code> file that <code>nixos-rebuild build</code> would build. | ||
=== Explore a NixOS configuration in the REPL === | |||
If you want to see what ''value'' a NixOS option takes without building, as opposed to merely checking that all options work, you can run: | |||
<syntaxhighlight lang="console"> | |||
$ nix repl --file '<nixpkgs/nixos>' | |||
Welcome to Nix 2.18.2. Type :? for help. | |||
Loading installable ''... | |||
Added 6 variables. | |||
nix-repl> config.environment.shells # for example | |||
[ "/run/current-system/sw/bin/zsh" ... ] | |||
# Equivalently, if starting from an existing REPL: | |||
nix-repl> :l <nixpkgs/nixos> | |||
Added 6 variables. | |||
nix-repl> config.environment.shells | |||
</syntaxhighlight> | |||
This can be helpful if your configuration is spread across multiple modules, or if you import modules from external sources, or if NixOS has defaults and you want to know whether a default is being used or extended in your configuration, or a variety of other cases in which you might want the computer to tell you what the end result of all your Nixing is going to be before you switch to it. | |||
You can do this with configuration files other than the one installed in <code>/etc/nixos</code>, too: | |||
<pre> | |||
nix-repl> :a import <nixpkgs/nixos> { configuration = /path/to/config.nix; } | |||
</pre> | |||
=== Manually switching a NixOS system to a certain version of system closure === | === Manually switching a NixOS system to a certain version of system closure === | ||
| Line 220: | Line 248: | ||
=== Cross-compile packages === | === Cross-compile packages === | ||
The following command will cross compile the tinc package for the aarch64 CPU architecture from | The following command will cross compile the <code>tinc</code> package for the aarch64 CPU architecture from the current system architecture (e.g. x86_64 if you are running a x86_64 system). | ||
< | <syntaxhighlight lang="console"> | ||
$ nix-build '<nixpkgs>' - | $ nix-build '<nixpkgs>' -A pkgsCross.aarch64-multiplatform.tinc | ||
</ | </syntaxhighlight> | ||
There are alternative ways to specify and build cross compiled packages, see [[Cross Compiling]]. | |||
=== Customizing Packages === | === Customizing Packages === | ||