FAQ: Difference between revisions
Reduce header level to make font size more readable on mobile |
Marked this version for translation |
||
| (9 intermediate revisions by 5 users not shown) | |||
| Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
{{cleanup}} | |||
<translate> | <translate> | ||
<!--T:1--> | <!--T:1--> | ||
| Line 22: | Line 23: | ||
<!--T:28--> | <!--T:28--> | ||
We tried to address these issues multiple times over multiple years across multiple channels (email, matrix). We never got a direct answer. The last point of contact was made through zimbatm representing the NixOS | We tried to address these issues multiple times over multiple years across multiple channels (email, matrix). We never got a direct answer. The last point of contact was made through zimbatm representing the [[NixOS Foundation]], asking the maintainer about possible cooperation on a new wiki. The answer was no. With the old wiki deteriorating and the maintainer unresponsive, forking the content into a new wiki remained the only way forward. | ||
<!--T:29--> | <!--T:29--> | ||
| Line 35: | Line 36: | ||
=== How to keep build-time dependencies around / be able to rebuild while being offline? === <!--T:3--> | === How to keep build-time dependencies around / be able to rebuild while being offline? === <!--T:3--> | ||
</translate> | |||
<syntaxhighlight lang="nix"># /etc/nixos/configuration.nix | <syntaxhighlight lang="nix"># /etc/nixos/configuration.nix | ||
{ config, pkgs, lib, ... }: | { config, pkgs, lib, ... }: | ||
| Line 47: | Line 48: | ||
}; | }; | ||
}</syntaxhighlight> | }</syntaxhighlight> | ||
<translate> | |||
<!--T:31--> | |||
Check 'man configuration.nix' for these options. Rebuild for these options to take effect: | Check 'man configuration.nix' for these options. Rebuild for these options to take effect: | ||
</translate> | |||
<syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight> | |||
<translate> | |||
<!--T:32--> | <!--T:32--> | ||
List all store paths that form the system closure and realise them: | List all store paths that form the system closure and realise them: | ||
</translate> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
nix-store -qR $(nix-instantiate '<nixpkgs/nixos>' -A system) | xargs nix-store -r | nix-store -qR $(nix-instantiate '<nixpkgs/nixos>' -A system) | xargs nix-store -r | ||
warning: you did not specify `--add-root'; the result might be removed by the garbage collector | warning: you did not specify `--add-root'; the result might be removed by the garbage collector | ||
<build output and list of successfully realised paths> | <build output and list of successfully realised paths> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:34--> | |||
Repeat for your user and further profiles: | Repeat for your user and further profiles: | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-store -qR ~/.nix-profile | xargs nix-store -r</syntaxhighlight> | |||
<translate> | |||
<!--T:35--> | <!--T:35--> | ||
The warning can be ignored for profiles that are listed/linked in ''/nix/var/nix/profiles/'' or one of its subdirectories. | The warning can be ignored for profiles that are listed/linked in ''/nix/var/nix/profiles/'' or one of its subdirectories. | ||
| Line 85: | Line 97: | ||
<!--T:40--> | <!--T:40--> | ||
This is what might happen if you don't garbage collect frequently, or if you are testing compilation variants: | This is what might happen if you don't garbage collect frequently, or if you are testing compilation variants: | ||
</translate> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
q0yi2nr8i60gm2zap46ryysydd2nhzhp-automake-1.11.1/ | q0yi2nr8i60gm2zap46ryysydd2nhzhp-automake-1.11.1/ | ||
| Line 99: | Line 111: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== I've updated my channel and something is broken, how can I rollback to an earlier channel? === <!--T:5--> | === I've updated my channel and something is broken, how can I rollback to an earlier channel? === <!--T:5--> | ||
<!--T:42--> | <!--T:42--> | ||
View the available generations of your channel: | View the available generations of your channel: | ||
</translate> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
nix-env --list-generations -p /nix/var/nix/profiles/per-user/root/channels | nix-env --list-generations -p /nix/var/nix/profiles/per-user/root/channels | ||
| Line 111: | Line 124: | ||
20 2014-08-12 19:09:20 (current) | 20 2014-08-12 19:09:20 (current) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:43--> | |||
To rollback to the previous generation: | To rollback to the previous generation: | ||
</translate> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
nix-env --rollback -p /nix/var/nix/profiles/per-user/root/channels | nix-env --rollback -p /nix/var/nix/profiles/per-user/root/channels | ||
switching from generation 20 to 19 | switching from generation 20 to 19 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:44--> | |||
To switch to a particular generation: | To switch to a particular generation: | ||
</translate> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
nix-env --switch-generation 18 -p /nix/var/nix/profiles/per-user/root/channels | nix-env --switch-generation 18 -p /nix/var/nix/profiles/per-user/root/channels | ||
| Line 126: | Line 145: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== I'm working on a new package, how can I build it without adding it to nixpkgs? === <!--T:6--> | === I'm working on a new package, how can I build it without adding it to nixpkgs? === <!--T:6--> | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; callPackage ./mypackage.nix { }'</syntaxhighlight> | |||
<translate> | |||
<!--T:46--> | <!--T:46--> | ||
You can replace callPackage with callPackage_i686 to build the 32-bit version of your package on a 64-bit system if you want to test that. | You can replace callPackage with callPackage_i686 to build the 32-bit version of your package on a 64-bit system if you want to test that. | ||
| Line 136: | Line 159: | ||
<!--T:47--> | <!--T:47--> | ||
To build a package with -Og and -g, and without stripping debug symbols use: | To build a package with -Og and -g, and without stripping debug symbols use: | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; enableDebugging fooPackage'</syntaxhighlight> | <syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; enableDebugging fooPackage'</syntaxhighlight> | ||
<translate> | |||
<!--T:49--> | <!--T:49--> | ||
See also [[Debug Symbols]] | See also [[Debug Symbols]] | ||
| Line 147: | Line 171: | ||
<!--T:50--> | <!--T:50--> | ||
As root you can run nix-build with the --check flag: | As root you can run nix-build with the --check flag: | ||
</translate> | |||
<syntaxhighlight lang="bash">sudo nix-build --check -A ncdu</syntaxhighlight> | <syntaxhighlight lang="bash">sudo nix-build --check -A ncdu</syntaxhighlight> | ||
=== How can I manage software with nix-env like with configuration.nix? === | |||
<translate> | |||
=== How can I manage software with nix-env like with configuration.nix? === <!--T:51--> | |||
<!--T:52--> | <!--T:52--> | ||
There are many ways, one is the following: | There are many ways, one is the following: | ||
</translate> | |||
<ol style="list-style-type: decimal;"> | <ol style="list-style-type: decimal;"> | ||
<li><p>Create a meta package called ''userPackages'' your ''~/.config/nixpkgs/config.nix'' file with the packages you would like to have in your environment:</p> | <li><p><translate><!--T:53--> Create a meta package called ''userPackages'' your ''~/.config/nixpkgs/config.nix'' file with the packages you would like to have in your environment:</translate></p> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
with (import <nixpkgs> {}); | with (import <nixpkgs> {}); | ||
| Line 172: | Line 198: | ||
} | } | ||
</syntaxhighlight></li> | </syntaxhighlight></li> | ||
<li><p>Install all specified packages using this command:</p> | <li><p><translate><!--T:137--> Install all specified packages using this command:</translate></p> | ||
<syntaxhighlight lang="bash">nix-env -iA userPackages -f '<nixpkgs>'</syntaxhighlight></li></ol> | <syntaxhighlight lang="bash">nix-env -iA userPackages -f '<nixpkgs>'</syntaxhighlight></li></ol> | ||
<translate> | |||
<!--T:54--> | <!--T:54--> | ||
Now you can add and remove packages from the paths list and rerun nix-env to update your user local packages. | Now you can add and remove packages from the paths list and rerun nix-env to update your user local packages. | ||
| Line 181: | Line 208: | ||
Another way is using [[Home Manager]]. | Another way is using [[Home Manager]]. | ||
=== I've downloaded a binary, but I can't run it, what can I do? === <!--T:9--> | |||
=== I've downloaded a binary, but I can't run it, what can I do? === | |||
<!--T:138--> | |||
Binaries normally do not work out of the box when you download them because they normally just assume that libraries can be found in hardcoded paths such as <code>/lib</code>. However this assumption is incorrect on NixOS systems due to the inner workings of <code>nix</code> - there is no default path, everything gets set to the corresponding version on compile time. | Binaries normally do not work out of the box when you download them because they normally just assume that libraries can be found in hardcoded paths such as <code>/lib</code>. However this assumption is incorrect on NixOS systems due to the inner workings of <code>nix</code> - there is no default path, everything gets set to the corresponding version on compile time. | ||
| Line 193: | Line 221: | ||
<!--T:58--> | <!--T:58--> | ||
You can use [https://github.com/Mic92/nix-ld nix-ld] to run compiled binaries. For example, if your binary needs zlib and openssl: | You can use [https://github.com/Mic92/nix-ld nix-ld] to run compiled binaries. For example, if your binary needs zlib and openssl: | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
programs.nix-ld = { | programs.nix-ld = { | ||
| Line 201: | Line 229: | ||
};</syntaxhighlight> | };</syntaxhighlight> | ||
<translate> | |||
<!--T:60--> | <!--T:60--> | ||
Log out and back in to apply the environment variables it sets, and you can then directly run the binary. | Log out and back in to apply the environment variables it sets, and you can then directly run the binary. | ||
| Line 206: | Line 235: | ||
<!--T:61--> | <!--T:61--> | ||
If you don't want to configure the list of libraries manually, a quick and dirty way to run nearly any precompiled binary is the following: | If you don't want to configure the list of libraries manually, a quick and dirty way to run nearly any precompiled binary is the following: | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
programs.nix-ld = { | programs.nix-ld = { | ||
| Line 214: | Line 243: | ||
};</syntaxhighlight> | };</syntaxhighlight> | ||
<translate> | |||
<!--T:63--> | <!--T:63--> | ||
This uses the libraries that are used by [[Steam]] to simulate a traditional Linux FHS environment to run games in. It's a [https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/ | This uses the libraries that are used by [[Steam]] to simulate a traditional Linux FHS environment to run games in. It's a [https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/st/steam/package.nix big list] that usually contains all the libraries your binary needs to run. | ||
<!--T:64--> | <!--T:64--> | ||
Another possibility is to use [https://nixos.org/patchelf.html patchelf] to set the library path and dynamic linker appropriately, since compiled binaries have hard-coded interpreter and require certain dynamic libraries. | Another possibility is to use [https://nixos.org/patchelf.html patchelf] to set the library path and dynamic linker appropriately, since compiled binaries have hard-coded interpreter and require certain dynamic libraries. | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# mybinaryprogram.nix | # mybinaryprogram.nix | ||
| Line 241: | Line 271: | ||
''; | ''; | ||
}</syntaxhighlight> | }</syntaxhighlight> | ||
<translate> | |||
<!--T:65--> | |||
This can be built with: | This can be built with: | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-build mybinaryprogram.nix</syntaxhighlight> | |||
<translate> | |||
<!--T:66--> | <!--T:66--> | ||
And run with: | And run with: | ||
</translate> | |||
<syntaxhighlight lang="bash">./result/bin/mybinaryprogram</syntaxhighlight> | |||
<translate> | |||
<!--T:67--> | <!--T:67--> | ||
Another possibility is using a FHS-compatible Sandbox with [https://nixos.org/nixpkgs/manual/#sec-fhs-environments buildFHSUserEnv] | Another possibility is using a FHS-compatible Sandbox with [https://nixos.org/nixpkgs/manual/#sec-fhs-environments buildFHSUserEnv] | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# fhsUser.nix | # fhsUser.nix | ||
| Line 273: | Line 312: | ||
runScript = "bash"; | runScript = "bash"; | ||
}).env</syntaxhighlight> | }).env</syntaxhighlight> | ||
<translate> | |||
<!--T:68--> | |||
the sandbox can be entered with | the sandbox can be entered with | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-shell fhsUser.nix</syntaxhighlight> | |||
<translate> | |||
<!--T:10--> | <!--T:10--> | ||
If your target application can't find shared libraries inside buildFHSUserEnv, you may run [https://github.com/lexleogryfon/de-generate nix-de-generate] for target application inside FHS, which will generate newenv.nix file, an nix-expression of buildFHSUserEnv with resolved dependencies for shared libraries. | If your target application can't find shared libraries inside buildFHSUserEnv, you may run [https://github.com/lexleogryfon/de-generate nix-de-generate] for target application inside FHS, which will generate newenv.nix file, an nix-expression of buildFHSUserEnv with resolved dependencies for shared libraries. | ||
=== What are channels and how do they get updated? === | === What are channels and how do they get updated? === <!--T:136--> | ||
</translate> | |||
{{main|Channel branches}} | {{main|Channel branches}} | ||
<translate> | |||
<!--T:69--> | <!--T:69--> | ||
[https://github.com/NixOS/nixpkgs Nixpkgs] is the git repository containing all packages and NixOS modules/expressions. Installing packages directly from Nixpkgs master branch is possible but a bit risky as git commits are merged into master before being heavily tested. That's where channels are useful. | [https://github.com/NixOS/nixpkgs Nixpkgs] is the git repository containing all packages and NixOS modules/expressions. Installing packages directly from Nixpkgs master branch is possible but a bit risky as git commits are merged into master before being heavily tested. That's where channels are useful. | ||
| Line 315: | Line 362: | ||
* For nixos-small: the unstable-small [http://hydra.nixos.org/job/nixos/unstable-small/tested tested] job. | * For nixos-small: the unstable-small [http://hydra.nixos.org/job/nixos/unstable-small/tested tested] job. | ||
* For nixpkgs: the trunk [http://hydra.nixos.org/job/nixpkgs/trunk/unstable unstable] job, which contains some critical release packages. | * For nixpkgs: the trunk [http://hydra.nixos.org/job/nixpkgs/trunk/unstable unstable] job, which contains some critical release packages. | ||
</translate> | |||
<ol start="2" style="list-style-type: decimal;"> | <ol start="2" style="list-style-type: decimal;"> | ||
<li>Once the job succeeds at a particular nixpkgs commit, '''cache.nixos.org''' will download binaries from '''hydra.nixos.org'''.</li> | <li><translate><!--T:76--> Once the job succeeds at a particular nixpkgs commit, '''cache.nixos.org''' will download binaries from '''hydra.nixos.org'''.</translate></li> | ||
<li>Once the above download completes, the channel updates.</li></ol> | <li><translate><!--T:139--> Once the above download completes, the channel updates.</translate></li> | ||
</ol> | |||
<translate> | |||
<!--T:77--> | <!--T:77--> | ||
You can checkout the nixpkgs git and reset it to a particular commit of a channel. This will not affect your access to the binary cache. | You can checkout the nixpkgs git and reset it to a particular commit of a channel. This will not affect your access to the binary cache. | ||
| Line 331: | Line 381: | ||
<!--T:79--> | <!--T:79--> | ||
If you want to know where <nixpkgs> is located: | If you want to know where <nixpkgs> is located: | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-instantiate --find-file nixpkgs</syntaxhighlight> | |||
<translate> | |||
<!--T:80--> | <!--T:80--> | ||
To know the commit, open the .version-suffix file in the nixpkgs location. The hash after the dot is the git commit. | To know the commit, open the .version-suffix file in the nixpkgs location. The hash after the dot is the git commit. | ||
<!--T:12--> | === Nixpkgs branches === <!--T:12--> | ||
<!--T:140--> | |||
Branches on the nixpkgs repo have a relationship with channels, but that relationship is not 1:1. | Branches on the nixpkgs repo have a relationship with channels, but that relationship is not 1:1. | ||
| Line 354: | Line 408: | ||
<!--T:84--> | <!--T:84--> | ||
You can jump the queue and use <code>nix-shell</code> with a <code>NIX_PATH</code> pointing to a tarball of the channel to get a shell for that software. Some building may occur. This will not work for system services. | You can jump the queue and use <code>nix-shell</code> with a <code>NIX_PATH</code> pointing to a tarball of the channel to get a shell for that software. Some building may occur. This will not work for system services. | ||
</translate> | |||
<syntaxhighlight lang="command"> | <syntaxhighlight lang="command"> | ||
NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/release-17.09.tar.gz nix-shell -p $software | NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/release-17.09.tar.gz nix-shell -p $software | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== There's an updated version for $software on the unstable branch, but I use stable, how can I use it? === <!--T:143--> | |||
<!--T:144--> | |||
Before going ahead with this, note that firstly, this likely means that the package you intend to update has had a major version change. If you have used it previously, there is a chance that your existing data either will not work with the new version or will need to be migrated; If in doubt, consult the upstream documentation of the package. | |||
<!--T:145--> | |||
Secondly, while you're less likely to run into issues on NixOS than on, for example, Debian when installing packages from different releases, it's not impossible. | |||
<!--T:146--> | |||
Nix ensures that libraries and (usually) runtime dependencies of packages are kept separate, so that you can trivially have many versions of those dependencies installed, without affecting the versions of said dependencies used by important system components. This ensures that you cannot accidentally break your package manager by, say, updating Python, as is quite common on other distros. | |||
<!--T:147--> | |||
Nix cannot however ensure that there will be no incompatibilities with services of which there can inherently be only one running instance. As an example, if you try to use a package from unstable on a stable system that requires a feature in systemd that is not yet present in the systemd version on stable, this package will not work; it's simply not possible to run two different versions of systemd simultaneously. | |||
<!--T:148--> | |||
Nonetheless, it's quite uncommon that end-user facing applications rely on such singleton services, or at the very least they will typically have internal backwards compatibility. As such, mixing channels is usually unproblematic in practice, and even if not, NixOS' rollback features make it trivial to recover from problems should they occur. | |||
==== Using channels ==== <!--T:149--> | |||
<!--T:150--> | |||
First we need to add the unstable channel to our system channels: | |||
<!--T:151--> | |||
{{Warning|`nixos-rebuild --upgrade` will by default only update the channel named `nixos`, which this new channel is not. Use `nixos-rebuild --upgrade-all` instead.}} | |||
</translate> | |||
<syntaxhighlight lang="console"> | |||
$ sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable | |||
$ sudo nix-channel --update | |||
</syntaxhighlight> | |||
<translate> | |||
<!--T:152--> | |||
Then we can import this channel using the angle-bracket notation to refer to it: | |||
</translate> | |||
<syntaxhighlight lang="nixos"># configuration.nix | |||
{ | |||
config, | |||
pkgsUnstable, | |||
... | |||
}: { | |||
# We add a new `pkgsUnstable` to the module arguments; this allows | |||
# us to easily use `pkgsUnstable` in other modules as well, without | |||
# having to evaluate it again. | |||
_module.args.pkgsUnstable = import <nixos-unstable> { inherit (config.nixpkgs) config; }; | |||
environment.systemPackages = [ | |||
# Once we have created our `pkgsUnstable`, we can easily use | |||
# packages from it wherever NixOS modules expect derivations | |||
pkgsUnstable.hello | |||
]; | |||
}</syntaxhighlight> | |||
<translate> | |||
==== Using flakes ==== <!--T:153--> | |||
<!--T:154--> | |||
We simply add the unstable branch to our flake inputs, and pass them into the NixOS module system using <code>specialArgs</code>: | |||
</translate> | |||
<syntaxhighlight lang="nix"> | |||
# flake.nix | |||
{ | |||
inputs = { | |||
nixpkgs.url = "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz"; | |||
nixpkgs-unstable.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; | |||
}; | |||
outputs = { nixpkgs, ... } @ inputs: { | |||
# Note that the hostname "nixos" and the system tuple used here are | |||
# examples. | |||
nixosConfigurations."nixos" = nixpkgs.lib.nixosSystem { | |||
system = "x86_64-linux"; | |||
modules = [ | |||
./configuration.nix | |||
]; | |||
# Any attributes of `specialArgs` will be added to our NixOS module | |||
# arguments. | |||
# | |||
# We've bound `nixpkgs-unstable` to the `inputs` variable using the `@` | |||
# syntax; if we add any other flake inputs in the future those will also | |||
# be added to our module arguments. | |||
specialArgs.flake-inputs = inputs; | |||
}; | |||
}; | |||
} | |||
</syntaxhighlight> | |||
<translate> | |||
<!--T:155--> | |||
Using this in <code>configuration.nix</code> then looks as follows: | |||
</translate> | |||
<syntaxhighlight lang="nixos"> | |||
# configuration.nix | |||
{ | |||
pkgs, | |||
flake-inputs, | |||
... | |||
}: { | |||
environment.systemPackages = [ | |||
flake-inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.hello | |||
]; | |||
} | |||
</syntaxhighlight> | |||
<translate> | |||
=== How do I install a specific version of a package for build reproducibility etc.? === <!--T:14--> | === How do I install a specific version of a package for build reproducibility etc.? === <!--T:14--> | ||
| Line 381: | Line 546: | ||
<!--T:91--> | <!--T:91--> | ||
start a new shell with a private mount namespace (Linux-only) | start a new shell with a private mount namespace (Linux-only) | ||
</translate> | |||
<syntaxhighlight lang="bash">sudo unshare -m bash</syntaxhighlight> | |||
<translate> | |||
<!--T:92--> | <!--T:92--> | ||
remount the filesystem with write privileges (as root) | remount the filesystem with write privileges (as root) | ||
</translate> | |||
<syntaxhighlight lang="bash">mount -o remount,rw /nix/store</syntaxhighlight> | |||
<translate> | |||
<!--T:93--> | <!--T:93--> | ||
update the file | update the file | ||
</translate> | |||
<syntaxhighlight lang="bash">nano <PATH_TO_PACKAGE>/default.nix</syntaxhighlight> | |||
<translate> | |||
<!--T:94--> | <!--T:94--> | ||
exit to shell where /nix/store is still mounted read-only | exit to shell where /nix/store is still mounted read-only | ||
</translate> | |||
<syntaxhighlight lang="bash">exit</syntaxhighlight> | |||
<translate> | |||
<!--T:95--> | <!--T:95--> | ||
Be sure to [https://github.com/NixOS/nixpkgs/issues report the incorrect url] or [https://github.com/NixOS/nixpkgs/pulls fix it yourself]. | Be sure to [https://github.com/NixOS/nixpkgs/issues report the incorrect url] or [https://github.com/NixOS/nixpkgs/pulls fix it yourself]. | ||
| Line 405: | Line 582: | ||
<!--T:97--> | <!--T:97--> | ||
For instance to get the checksum of a git repository use: | For instance to get the checksum of a git repository use: | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-prefetch-git https://git.zx2c4.com/password-store</syntaxhighlight> | <syntaxhighlight lang="bash">nix-prefetch-git https://git.zx2c4.com/password-store</syntaxhighlight> | ||
<translate> | |||
<!--T:99--> | <!--T:99--> | ||
Or, use <code>lib.fakeHash</code> as the fetcher's hash argument, and attempt to build; Nix will tell you the actual and expected hash's mismatch, and you may copy the actual hash. | Or, use <code>lib.fakeHash</code> as the fetcher's hash argument, and attempt to build; Nix will tell you the actual and expected hash's mismatch, and you may copy the actual hash. | ||
| Line 435: | Line 613: | ||
<!--T:105--> | <!--T:105--> | ||
This is also useful to make simple configuration changes in NixOS (ex.: network related), when no network connectivity is available: | This is also useful to make simple configuration changes in NixOS (ex.: network related), when no network connectivity is available: | ||
</translate> | |||
<syntaxhighlight lang="bash">nixos-rebuild switch --option binary-caches ''</syntaxhighlight> | <syntaxhighlight lang="bash">nixos-rebuild switch --option binary-caches ''</syntaxhighlight> | ||
<translate> | |||
=== How do I enable sandboxed builds on non-NixOS? === <!--T:20--> | === How do I enable sandboxed builds on non-NixOS? === <!--T:20--> | ||
<!--T:107--> | <!--T:107--> | ||
Two options have to be added to make sandboxed builds work on Nix, ''build-use-sandbox'' and ''build-sandbox-paths'': | Two options have to be added to make sandboxed builds work on Nix, ''build-use-sandbox'' and ''build-sandbox-paths'': | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# /etc/nix/nix.conf | # /etc/nix/nix.conf | ||
| Line 450: | Line 629: | ||
build-sandbox-paths = $(nix-store -qR $(nix-build '<nixpkgs>' -A bash) | xargs echo /bin/sh=$(nix-build '<nixpkgs>' -A bash)/bin/bash) | build-sandbox-paths = $(nix-store -qR $(nix-build '<nixpkgs>' -A bash) | xargs echo /bin/sh=$(nix-build '<nixpkgs>' -A bash)/bin/bash) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:108--> | |||
On NixOS set the following in ''configuration.nix'': | On NixOS set the following in ''configuration.nix'': | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
nix.settings.sandbox = true; | nix.settings.sandbox = true; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:110--> | <!--T:110--> | ||
See [[Nix package manager#Sandbox_builds]] for more details. | See [[Nix package manager#Sandbox_builds]] for more details. | ||
| Line 464: | Line 647: | ||
<!--T:111--> | <!--T:111--> | ||
If you simply want to run a ''nix-shell'' with a package from unstable, you can run a command like the following: | If you simply want to run a ''nix-shell'' with a package from unstable, you can run a command like the following: | ||
</translate> | |||
<syntaxhighlight lang="bash">nix-shell -I nixpkgs=channel:nixpkgs-unstable -p somepackage</syntaxhighlight> | <syntaxhighlight lang="bash">nix-shell -I nixpkgs=channel:nixpkgs-unstable -p somepackage</syntaxhighlight> | ||
<translate> | |||
<!--T:113--> | <!--T:113--> | ||
It is possible to have multiple nix-channels simultaneously. To add the unstable channel with the specifier ''unstable'', | It is possible to have multiple nix-channels simultaneously. To add the unstable channel with the specifier ''unstable'', | ||
</translate> | |||
<syntaxhighlight lang="bash">sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable</syntaxhighlight> | |||
<translate> | |||
<!--T:114--> | <!--T:114--> | ||
After updating the channel | After updating the channel | ||
</translate> | |||
<syntaxhighlight lang="bash">sudo nix-channel --update nixos-unstable</syntaxhighlight> | |||
<translate> | |||
<!--T:115--> | <!--T:115--> | ||
queries via <code>nix-env</code> will show packages from both ''stable'' and ''unstable''. Use this to install unstable packages into your user environment. The following snippet shows how this can be done in ''configuration.nix''. | queries via <code>nix-env</code> will show packages from both ''stable'' and ''unstable''. Use this to install unstable packages into your user environment. The following snippet shows how this can be done in ''configuration.nix''. | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
| Line 489: | Line 679: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:117--> | <!--T:117--> | ||
This only changes what version of <code>PACKAGE_NAME</code> is available on <code>$PATH</code>. If the package you want to take from unstable is installed through a NixOS module, you must use [[overlays]]: | This only changes what version of <code>PACKAGE_NAME</code> is available on <code>$PATH</code>. If the package you want to take from unstable is installed through a NixOS module, you must use [[overlays]]: | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
| Line 503: | Line 696: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:141--> | |||
Note that this will rebuild all packages depending on the overlaid package, which may be a lot. Some modules offer a <code>services.foo.package</code> to change the actual derivation used by the module without and overlay, and without recompiling dependencies ([https://nixos.org/manual/nixos/stable/options.html#opt-services.gvfs.package example]). | Note that this will rebuild all packages depending on the overlaid package, which may be a lot. Some modules offer a <code>services.foo.package</code> to change the actual derivation used by the module without and overlay, and without recompiling dependencies ([https://nixos.org/manual/nixos/stable/options.html#opt-services.gvfs.package example]). | ||
<!--T:118--> | <!--T:118--> | ||
If you want to install unfree packages from unstable you need to also set allowUnfree by replacing the import statment above with: | If you want to install unfree packages from unstable you need to also set allowUnfree by replacing the import statment above with: | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
import <nixos-unstable> { config = { allowUnfree = true; }; } | import <nixos-unstable> { config = { allowUnfree = true; }; } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== I'm unable to connect my USB HDD | External HDD is failing to mount automatically === <!--T:22--> | === I'm unable to connect my USB HDD | External HDD is failing to mount automatically === <!--T:22--> | ||
| Line 518: | Line 717: | ||
<!--T:120--> | <!--T:120--> | ||
exfat is not supported in NixOS by default - since there are legality issues still with exFAT filesystem. | exfat is not supported in NixOS by default - since there are legality issues still with exFAT filesystem. | ||
</translate> | |||
<syntaxhighlight lang="bash">su nano /etc/nixos/configuration.nix</syntaxhighlight> | <syntaxhighlight lang="bash">su nano /etc/nixos/configuration.nix</syntaxhighlight> | ||
<translate> | |||
<!--T:122--> | <!--T:122--> | ||
Add this line to your configuration file. | Add this line to your configuration file. | ||
</translate> | |||
<syntaxhighlight lang="bash">boot.extraModulePackages = [ config.boot.kernelPackages.exfat-nofuse ];</syntaxhighlight> | <syntaxhighlight lang="bash">boot.extraModulePackages = [ config.boot.kernelPackages.exfat-nofuse ];</syntaxhighlight> | ||
<translate> | |||
<!--T:123--> | <!--T:123--> | ||
After saving the file rebuild NixOS: | After saving the file rebuild NixOS: | ||
</translate> | |||
<syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight> | <syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight> | ||
<translate> | |||
<!--T:125--> | <!--T:125--> | ||
Restart NixOS. | Restart NixOS. | ||
| Line 540: | Line 744: | ||
The name <code>Nix</code> comes from the Dutch word [https://en.wiktionary.org/wiki/nix niks] which means ''nothing''. It reflects the fact that Nix derivations do not have access to anything that has not been explicitly declared as an input.<ref>Eelco Dolstra et al. “Nix: A Safe and Policy-Free System for Software Deployment.” LiSA (2004), https://pdfs.semanticscholar.org/5fd8/8f89bd8738816e62808a1b7fb12d3ab14a2f.pdf</ref> | The name <code>Nix</code> comes from the Dutch word [https://en.wiktionary.org/wiki/nix niks] which means ''nothing''. It reflects the fact that Nix derivations do not have access to anything that has not been explicitly declared as an input.<ref>Eelco Dolstra et al. “Nix: A Safe and Policy-Free System for Software Deployment.” LiSA (2004), https://pdfs.semanticscholar.org/5fd8/8f89bd8738816e62808a1b7fb12d3ab14a2f.pdf</ref> | ||
=== What does it mean to say that NixOS is "immutable" === <!--T:127--> | |||
=== What does it mean to say that NixOS is "immutable" === | |||
<!--T:142--> | |||
Immutability is a property of data, in general, which means that the data cannot be modified after it is created. In the context of an operating system, it really means that certain parts of the system have this property. In the case of Nix and NixOS, that includes the Nix store, where files can be created but not modified after the time they are created. It does not apply to every part of the operating system, in that users can still modify their own files in their home directory, for example. | Immutability is a property of data, in general, which means that the data cannot be modified after it is created. In the context of an operating system, it really means that certain parts of the system have this property. In the case of Nix and NixOS, that includes the Nix store, where files can be created but not modified after the time they are created. It does not apply to every part of the operating system, in that users can still modify their own files in their home directory, for example. | ||
| Line 557: | Line 762: | ||
<!--T:132--> | <!--T:132--> | ||
(Note that none of this applies to the [https://nix.dev/manual/nix/stable/language/builtins#builtins-import <code>import</code> built-in Nix language function], which is its own thing.) | (Note that none of this applies to the [https://nix.dev/manual/nix/stable/language/builtins#builtins-import <code>import</code> built-in Nix language function], which is its own thing.) | ||
</translate> | |||
{{:FAQ/Libraries}} | {{:FAQ/Libraries}} | ||
{{:FAQ/nix-env -iA}} | {{:FAQ/nix-env -iA}} | ||
{{:FAQ/stateVersion}} | {{:FAQ/stateVersion}} | ||
{{:FAQ/notfound}} | {{:FAQ/notfound}} | ||
<!-- Transclude subpages --> | <!-- Transclude subpages --> | ||
<translate> | |||
== References == <!--T:134--> | == References == <!--T:134--> | ||