FAQ/en: Difference between revisions
Phanirithvij (talk | contribs) m fix nixos channels url |
Updating to match new version of source page Tags: Mobile edit Mobile web edit |
||
| Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
{{cleanup}} | |||
Frequently asked questions and common newcomer trouble should be put here so that we can point to this page instead of answering the same question over and over again. | Frequently asked questions and common newcomer trouble should be put here so that we can point to this page instead of answering the same question over and over again. | ||
http://unix.stackexchange.com/questions/tagged/nixos can also be used for questions. | http://unix.stackexchange.com/questions/tagged/nixos can also be used for questions. | ||
== Why is there a new wiki? What is with nixos.wiki? == | === Why is there a new wiki? What is with nixos.wiki? === | ||
The old wiki at nixos.wiki has several problems: | The old wiki at nixos.wiki has several problems: | ||
| Line 16: | Line 17: | ||
* The wiki infrastructure, which was supposed to be made public after launch, never ended-up being made public. | * The wiki infrastructure, which was supposed to be made public after launch, never ended-up being made public. | ||
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. | ||
Also see: | Also see: | ||
| Line 22: | Line 23: | ||
* https://greasyfork.org/en/scripts/495011-redirect-to-wiki-nixos-org (trivial userscript to redirect nixos.wiki links here) | * https://greasyfork.org/en/scripts/495011-redirect-to-wiki-nixos-org (trivial userscript to redirect nixos.wiki links here) | ||
== Why is Nix written in C++ rather than a functional language like Haskell? == | === Why is Nix written in C++ rather than a functional language like Haskell? === | ||
Mainly because Nix is intended to be lightweight, easy to learn, and portable (zero dependencies). | Mainly because Nix is intended to be lightweight, easy to learn, and portable (zero dependencies). | ||
== How to keep build-time dependencies around / be able to rebuild while being offline? == | === How to keep build-time dependencies around / be able to rebuild while being offline? === | ||
<syntaxhighlight lang="nix"># /etc/nixos/configuration.nix | <syntaxhighlight lang="nix"># /etc/nixos/configuration.nix | ||
| Line 56: | Line 57: | ||
Consult man pages of nix-store and nix-instantiate for further information. | Consult man pages of nix-store and nix-instantiate for further information. | ||
== Why <hash>-<name> instead of <name>-<hash>? == | === Why <hash>-<name> instead of <name>-<hash>? === | ||
For the rare cases where we have to dig into the /nix/store it is more practical to keep in mind the first few letters at the beginning than finding a package by name. | For the rare cases where we have to dig into the /nix/store it is more practical to keep in mind the first few letters at the beginning than finding a package by name. | ||
| Line 80: | Line 81: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== I've updated my channel and something is broken, how can I rollback to an earlier channel? == | === I've updated my channel and something is broken, how can I rollback to an earlier channel? === | ||
View the available generations of your channel: | View the available generations of your channel: | ||
| Line 103: | Line 104: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== I'm working on a new package, how can I build it without adding it to nixpkgs? == | === I'm working on a new package, how can I build it without adding it to nixpkgs? === | ||
<syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; callPackage ./mypackage.nix { }'</syntaxhighlight> | <syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; callPackage ./mypackage.nix { }'</syntaxhighlight> | ||
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. | ||
== How can I compile a package with debugging symbols included? == | === How can I compile a package with debugging symbols included? === | ||
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: | ||
| Line 116: | Line 117: | ||
See also [[Debug Symbols]] | See also [[Debug Symbols]] | ||
== How can I force a rebuild from source even without modifying the nix expression? == | === How can I force a rebuild from source even without modifying the nix expression? === | ||
As root you can run nix-build with the --check flag: | As root you can run nix-build with the --check flag: | ||
<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? == | === How can I manage software with nix-env like with configuration.nix? === | ||
There are many ways, one is the following: | There are many ways, one is the following: | ||
| Line 148: | Line 149: | ||
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? == | === I've downloaded a binary, but I can't run it, what can I do? === | ||
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 170: | Line 171: | ||
programs.nix-ld = { | programs.nix-ld = { | ||
enable = true; | enable = true; | ||
libraries = pkgs.steam-run | libraries = pkgs.steam-run.args.multiPkgs pkgs; | ||
};</syntaxhighlight> | };</syntaxhighlight> | ||
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. | ||
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. | ||
| Line 231: | Line 232: | ||
<br> | <br> | ||
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? === | |||
{{main|Channel branches}} | {{main|Channel branches}} | ||
| Line 246: | Line 248: | ||
** '''description''' This channel is identical to <code>nixos-unstable</code> described above, except that this channel contains fewer binary packages. This means the channel gets updated faster than <code>nixos-unstable</code> (for instance, when a critical security patch is committed to NixOS’s source tree). However, the binary cache may contain less binary packages and thus using this channel may require building more packages from source than <code>nixos-unstable</code>. This channel is mostly intended for server environments and as such contains few GUI applications. | ** '''description''' This channel is identical to <code>nixos-unstable</code> described above, except that this channel contains fewer binary packages. This means the channel gets updated faster than <code>nixos-unstable</code> (for instance, when a critical security patch is committed to NixOS’s source tree). However, the binary cache may contain less binary packages and thus using this channel may require building more packages from source than <code>nixos-unstable</code>. This channel is mostly intended for server environments and as such contains few GUI applications. | ||
** '''definition''' this channel is updated depending on [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release-small.nix release-small.nix] and [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release-lib.nix release-lib.nix] | ** '''definition''' this channel is updated depending on [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release-small.nix release-small.nix] and [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release-lib.nix release-lib.nix] | ||
* '''nixos-YY.MM''' (where '''YY''' is a 2-digit year and '''MM''' is a 2-digit month, such as [https:// | * '''nixos-YY.MM''' (where '''YY''' is a 2-digit year and '''MM''' is a 2-digit month, such as [https://nixos.org/channels/nixos-15.09/ ''nixos-17.03'']) | ||
** '''description''' These channels are called '''stable''' and only get conservative bug fixes and package upgrades. For instance, a channel update may cause the Linux kernel on your system to be upgraded from 3.4.66 to 3.4.67 (a minor bug fix), but not from 3.4.x to 3.11.x (a major change that has the potential to break things). Stable channels are generally maintained until the next stable branch is created. | ** '''description''' These channels are called '''stable''' and only get conservative bug fixes and package upgrades. For instance, a channel update may cause the Linux kernel on your system to be upgraded from 3.4.66 to 3.4.67 (a minor bug fix), but not from 3.4.x to 3.11.x (a major change that has the potential to break things). Stable channels are generally maintained until the next stable branch is created. | ||
** '''definition''' this channel is updated depending on [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release.nix release.nix] and [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release-lib.nix release-lib.nix] | ** '''definition''' this channel is updated depending on [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release.nix release.nix] and [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release-lib.nix release-lib.nix] | ||
* '''nixos-YY.MM-small''' (where '''YY''' is a 2-digit year and '''MM''' is a 2-digit month, such as [https:// | * '''nixos-YY.MM-small''' (where '''YY''' is a 2-digit year and '''MM''' is a 2-digit month, such as [https://nixos.org/channels/nixos-15.09-small/ nixos-15.09-small]) | ||
** '''description''' The difference between <code>nixos-YY.MM-small</code> and <code>nixos-YY.MM</code> is the same as the one between <code>nixos-unstable-small</code> and <code>nixos-unstable</code> (see above) | ** '''description''' The difference between <code>nixos-YY.MM-small</code> and <code>nixos-YY.MM</code> is the same as the one between <code>nixos-unstable-small</code> and <code>nixos-unstable</code> (see above) | ||
| Line 266: | Line 268: | ||
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. | ||
== How do I know where's nixpkgs channel located and at which commit? == | === How do I know where's nixpkgs channel located and at which commit? === | ||
First <code>echo $NIX_PATH</code> to see where nix looks for the expressions. Note that nix-env uses ''~/.nix-defexpr'' regardless of ''$NIX_PATH''. | First <code>echo $NIX_PATH</code> to see where nix looks for the expressions. Note that nix-env uses ''~/.nix-defexpr'' regardless of ''$NIX_PATH''. | ||
| Line 275: | Line 277: | ||
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. | ||
== Nixpkgs branches == | === Nixpkgs branches === | ||
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 285: | Line 287: | ||
So in short, the <code>relase-XX.YY</code> branches have not been run through Hydra yet, whereas the <code>nixos-XX.YY</code> ones have. | So in short, the <code>relase-XX.YY</code> branches have not been run through Hydra yet, whereas the <code>nixos-XX.YY</code> ones have. | ||
== There's an updated version for $software on nixpkgs but not in channels, how can I use it? == | === There's an updated version for $software on nixpkgs but not in channels, how can I use it? === | ||
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. | ||
| Line 293: | Line 295: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== How do I install a specific version of a package for build reproducibility etc.? == | === How do I install a specific version of a package for build reproducibility etc.? === | ||
See [[FAQ/Pinning Nixpkgs]] and [[How to fetch Nixpkgs with an empty NIX PATH]]. Find the version of nixpkgs with the package version you want and pin nixpkgs to that. However, be aware that the pinning of a package of another nixpkgs version results in a much larger package size as not only the package itself but all dependencies (down to libc) have older versions. | See [[FAQ/Pinning Nixpkgs]] and [[How to fetch Nixpkgs with an empty NIX PATH]]. Find the version of nixpkgs with the package version you want and pin nixpkgs to that. However, be aware that the pinning of a package of another nixpkgs version results in a much larger package size as not only the package itself but all dependencies (down to libc) have older versions. | ||
| Line 299: | Line 301: | ||
if you just want the old version of the single package but with new dependencies it is often easier to copy the package description into your scope and add it to your <code>configuration.nix</code> via: <code> mypackage-old = pkgs.callPackage ./mypackage-old.nix {};</code>.You can try to build the package as described in [[FAQ#I.27m_working_on_a_new_package.2C_how_can_I_build_it_without_adding_it_to_nixpkgs.3F|the FAQ: building a single derivation]]. | if you just want the old version of the single package but with new dependencies it is often easier to copy the package description into your scope and add it to your <code>configuration.nix</code> via: <code> mypackage-old = pkgs.callPackage ./mypackage-old.nix {};</code>.You can try to build the package as described in [[FAQ#I.27m_working_on_a_new_package.2C_how_can_I_build_it_without_adding_it_to_nixpkgs.3F|the FAQ: building a single derivation]]. | ||
== An error occurs while fetching sources from an url, how do I fix it? == | === An error occurs while fetching sources from an url, how do I fix it? === | ||
First try to update the local nixpkgs expressions with <code>nix-channel --update</code> (these describe where to download sources from and how to build them). Try your build again and the url might have already been correctly updated for the package in question. You can also subscribe the unstable channel (which includes the most up-to-date expressions) with <code>nix-channel --add http://nixos.org/channels/nixpkgs-unstable</code>, update and try the build again. | First try to update the local nixpkgs expressions with <code>nix-channel --update</code> (these describe where to download sources from and how to build them). Try your build again and the url might have already been correctly updated for the package in question. You can also subscribe the unstable channel (which includes the most up-to-date expressions) with <code>nix-channel --add http://nixos.org/channels/nixpkgs-unstable</code>, update and try the build again. | ||
If that fails you can update the url in the nix expression yourself. [ | If that fails you can update the url in the nix expression yourself. [[#How_do_I_know_where's_nixpkgs_channel_located_and_at_which_commit?|Navigate to your channel's expressions]] and find the package in one of the subdirectories. Edit the respective ''default.nix'' file by altering the ''url'' and ''sha256''. You can use <code>nix-prefetch-url url</code> to get the SHA-256 hash of source distributions. | ||
If the shell complains that you do not have write privileges for the file system, you will have to enable them. | If the shell complains that you do not have write privileges for the file system, you will have to enable them. | ||
| Line 321: | Line 323: | ||
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]. | ||
== How do I know the sha256 to use with fetchgit, fetchsvn, fetchbzr or fetchcvs? == | === How do I know the sha256 to use with fetchgit, fetchsvn, fetchbzr or fetchcvs? === | ||
Install <code>nix-prefetch-scripts</code> and use the corresponding nix prefetch helper. | Install <code>nix-prefetch-scripts</code> and use the corresponding nix prefetch helper. | ||
| Line 331: | Line 333: | ||
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. | ||
== Should I use http://hydra.nixos.org/ as a binary cache? == | === Should I use http://hydra.nixos.org/ as a binary cache? === | ||
No. As of 2017, all build artifacts are directly pushed to http://cache.nixos.org/ and are available there, therefore setting http://hydra.nixos.org/ as a binary cache no longer serves any function. | No. As of 2017, all build artifacts are directly pushed to http://cache.nixos.org/ and are available there, therefore setting http://hydra.nixos.org/ as a binary cache no longer serves any function. | ||
== I'm trying to install NixOS but my WiFi isn't working and I don't have an ethernet port == | === I'm trying to install NixOS but my WiFi isn't working and I don't have an ethernet port === | ||
Most phones will allow you to share your WiFi connection over USB. On Android you can enable this setting via ''Settings'' > ''Wireless & Networks'' / More ... > ''Tethering & portable hotspot'' > ''USB tethering''. This should be enough to allow you to install NixOS, and then fix your WiFi. iPhones only let you tether using your data connection rather than WiFi. | Most phones will allow you to share your WiFi connection over USB. On Android you can enable this setting via ''Settings'' > ''Wireless & Networks'' / More ... > ''Tethering & portable hotspot'' > ''USB tethering''. This should be enough to allow you to install NixOS, and then fix your WiFi. iPhones only let you tether using your data connection rather than WiFi. | ||
| Line 343: | Line 345: | ||
For connecting to your WiFi, see [[NixOS_Installation_Guide#Wireless]] | For connecting to your WiFi, see [[NixOS_Installation_Guide#Wireless]] | ||
== How can I disable the binary cache and build everything locally? == | === How can I disable the binary cache and build everything locally? === | ||
Set the binary caches to an empty list: <code>nix.binaryCaches = [];</code> in <code>configuration.nix</code> or pass ad-hoc <code>--option binary-caches <nowiki>''</nowiki></code> as parameter to nix-build or its wrappers. | Set the binary caches to an empty list: <code>nix.binaryCaches = [];</code> in <code>configuration.nix</code> or pass ad-hoc <code>--option binary-caches <nowiki>''</nowiki></code> as parameter to nix-build or its wrappers. | ||
| Line 351: | Line 353: | ||
<syntaxhighlight lang="bash">nixos-rebuild switch --option binary-caches ''</syntaxhighlight> | <syntaxhighlight lang="bash">nixos-rebuild switch --option binary-caches ''</syntaxhighlight> | ||
== How do I enable sandboxed builds on non-NixOS? == | === How do I enable sandboxed builds on non-NixOS? === | ||
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'': | ||
| Line 368: | Line 370: | ||
See [[Nix package manager#Sandbox_builds]] for more details. | See [[Nix package manager#Sandbox_builds]] for more details. | ||
== How can I install a package from unstable while remaining on the stable channel? == | === How can I install a package from unstable while remaining on the stable channel? === | ||
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: | ||
| Line 411: | Line 413: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== I'm unable to connect my USB HDD | External HDD is failing to mount automatically == | === I'm unable to connect my USB HDD | External HDD is failing to mount automatically === | ||
'''Note:''' If you're using a kernel with at least version 5.6, you don't need to explicitly add this. | '''Note:''' If you're using a kernel with at least version 5.6, you don't need to explicitly add this. | ||
| Line 428: | Line 430: | ||
Restart NixOS. | Restart NixOS. | ||
== What is the origin of the name "Nix" == | === What is the origin of the name "Nix" === | ||
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" == | === What does it mean to say that NixOS is "immutable" === | ||
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. | ||
== I'm getting ‘infinite recursion’ errors when trying to do something clever with <code>imports</code> == | === I'm getting ‘infinite recursion’ errors when trying to do something clever with <code>imports</code> === | ||
Evaluating the <code>imports</code> attribute of a NixOS module (such as configuration.nix) is a prerequisite for evaluating just about everything else, so trying anything clever with <code>imports</code> is a common source of infinite recursion (because the evaluator can't determine the values of packages and options without knowing what is imported, and can't determine what is imported without knowing the values of packages or options). | Evaluating the <code>imports</code> attribute of a NixOS module (such as configuration.nix) is a prerequisite for evaluating just about everything else, so trying anything clever with <code>imports</code> is a common source of infinite recursion (because the evaluator can't determine the values of packages and options without knowing what is imported, and can't determine what is imported without knowing the values of packages or options). | ||
| Line 449: | Line 451: | ||
{{:FAQ/stateVersion}} | {{:FAQ/stateVersion}} | ||
{{:FAQ/notfound}} | {{:FAQ/notfound}} | ||
<!-- Transclude subpages --> | <!-- Transclude subpages --> | ||