FAQ/zh: Difference between revisions

Weijia (talk | contribs)
Created page with "旧的 wiki(nixos.wiki)存在以下几个问题:"
Ardenet (talk | contribs)
No edit summary
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{cleanup}}
为了避免重复回答那些经常被问到的问题以及处理新手常遇到的麻烦,这些问题被收录在这里。
为了避免重复回答那些经常被问到的问题以及处理新手常遇到的麻烦,这些问题被收录在这里。


<div lang="en" dir="ltr" class="mw-content-ltr">
http://unix.stackexchange.com/questions/tagged/nixos 也可用于提问。
http://unix.stackexchange.com/questions/tagged/nixos can also be used for questions.
</div>


<span id="Why_is_there_a_new_wiki?_What_is_with_nixos.wiki?"></span>
<span id="Why_is_there_a_new_wiki?_What_is_with_nixos.wiki?"></span>
== 为什么创建了一个新的 wiki?nixos.wiki 怎么了? ==
=== 为什么创建了一个新的维基?nixos.wiki 怎么了? ===


旧的 wiki(nixos.wiki)存在以下几个问题:
旧的 wiki(nixos.wiki)存在以下几个问题:


<div lang="en" dir="ltr" class="mw-content-ltr">
* 许多组件(MediaWiki、PHP、ICU)严重过时。
* Many components (mediawiki, php, icu) are severely outdated.
** MediaWiki 1.29(生命周期结束于 2018 年),当前版本为 1.35(生命周期结束于 2023 12 月)
** MediaWiki 1.29 (EOL 2018), now 1.35 (EOL 2023-12)
** PHP 7.3.33(生命周期结束于 2021 12 月)
** PHP 7.3.33 (EOL 2021-12)
** ICU 64.2
** ICU 64.2
* Cloudflare DDOS protection makes wiki edits fail sometimes.
* Cloudflare 的 DDoS 防御有时会导致维基编辑失败。
* There is no WYSIWYG editor.
* 没有所见即所得(WYSIWYG)的编辑器。
* The wiki infrastructure, which was supposed to be made public after launch, never ended-up being made public.
* 维基的基础设施本应在上线后公开,但最终未能公开。
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
我们曾通过多种渠道(电子邮件、Matrix)多次尝试解决这些问题,历时多年,但始终未能得到直接答复。最后一次联系是由 zimbatm 代表 [[NixOS Foundation|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.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
另请参阅:
Also see:
* https://wiki.nixos.org/wiki/User:Winny/WikiRisks
* https://wiki.nixos.org/wiki/User:Winny/WikiRisks
* 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(用于将 nixos.wiki 链接重定向到此处的简单用户脚本)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Why_is_Nix_written_in_C++_rather_than_a_functional_language_like_Haskell?"></span>
== Why is Nix written in C++ rather than a functional language like Haskell? ==
=== 为什么 Nix 是用 C++ 编写的,而不是使用像 Haskell 这样的函数式语言? ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
主要是因为 Nix 旨在轻量级、易于学习且具有良好的可移植性(零依赖)。
Mainly because Nix is intended to be lightweight, easy to learn, and portable (zero dependencies).
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_to_keep_build-time_dependencies_around_/_be_able_to_rebuild_while_being_offline?"></span>
== How to keep build-time dependencies around / be able to rebuild while being offline? ==
=== 如何保留构建时依赖/在离线状态下重新构建? ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix"># /etc/nixos/configuration.nix
<syntaxhighlight lang="nix"># /etc/nixos/configuration.nix
{ config, pkgs, lib, ... }:
{ config, pkgs, lib, ... }:
Line 54: Line 42:
   };
   };
}</syntaxhighlight>
}</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
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:
</div>
</div>
<syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight>
List all store paths that form the system closure and realise them:
List all store paths that form the system closure and realise them:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<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
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<build output and list of successfully realised paths>
<build output and list of successfully realised paths>
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
Repeat for your user and further profiles:
Repeat for your user and further profiles:
</div>
</div>
<syntaxhighlight lang="bash">nix-store -qR ~/.nix-profile | xargs nix-store -r</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nix-store -qR ~/.nix-profile | xargs nix-store -r</syntaxhighlight>
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.
</div>
</div>
Line 83: Line 74:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Why_-_instead_of_-?"></span>
== Why <hash>-<name> instead of <name>-<hash>? ==
=== 为什么使用 <hash>-<name> 而不是 <name>-<hash>? ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
在少数需要深入查看 /nix/store 的情况下,将哈希值的前几位放在开头更方便记忆和使用。
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.
也就是说,几乎可以仅通过哈希的前 4-5 个字符唯一地识别一个存储路径。
Ie, you can uniquely identify almost any storepath with just the first 4-5 characters of the hash.
(这比先输入完整的包名再加上哈希的前几位要更高效。)
(Rather than having to type out the full package name, then 4-5 characters of the hash.)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
此外,由于开头部分长度一致,查看一系列软件包列表时在视觉上也更容易解析。
Also, since the initial part is all of the same length, visually parsing a list of packages is easier.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 105: Line 91:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
q0yi2nr8i60gm2zap46ryysydd2nhzhp-automake-1.11.1/
q0yi2nr8i60gm2zap46ryysydd2nhzhp-automake-1.11.1/
Line 117: Line 102:
xvs7y09jf7j48p6l0p87iypgpq470jqw-nixos-build-vms/
xvs7y09jf7j48p6l0p87iypgpq470jqw-nixos-build-vms/
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="I&#039;ve_updated_my_channel_and_something_is_broken,_how_can_I_rollback_to_an_earlier_channel?"></span>
== I've updated my channel and something is broken, how can I rollback to an earlier channel? ==
=== 我更新了我的 channel后出现问题,如何回滚到之前的 channel? ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
查看可用的各代 channel
View the available generations of your channel:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<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 134: Line 114:
20  2014-08-12 19:09:20  (current)
20  2014-08-12 19:09:20  (current)
</syntaxhighlight>
</syntaxhighlight>
To rollback to the previous generation:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
回滚到上一代的方法:
 
<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>
To switch to a particular generation:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
切换到指定世代:
 
<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
switching from generation 20 to 18
switching from generation 20 to 18
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
== 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? ===
</div>
</div>
<syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; callPackage ./mypackage.nix { }'</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<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.
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_can_I_compile_a_package_with_debugging_symbols_included?"></span>
== How can I compile a package with debugging symbols included? ==
=== 我如何编译包含调试符号的包?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 169: Line 146:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; enableDebugging fooPackage'</syntaxhighlight>
<syntaxhighlight lang="bash">nix-build -E 'with import <nixpkgs> { }; enableDebugging fooPackage'</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 177: Line 152:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_can_I_force_a_rebuild_from_source_even_without_modifying_the_nix_expression?"></span>
== How can I force a rebuild from source even without modifying the nix expression? ==
=== 即使不修改 nix 表达式,我如何强制从源代码重建?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 185: Line 159:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<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? ==
 
</div>
<span id="How_can_I_manage_software_with_nix-env_like_with_configuration.nix?"></span>
=== 我如何使用 nix-env 管理软件,就像使用 configuration.nix 一样?===


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 194: Line 168:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<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><span lang="en" dir="ltr" class="mw-content-ltr">Create a meta package called ''userPackages'' your ''~/.config/nixpkgs/config.nix'' file with the packages you would like to have in your environment:</span></p>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
with (import <nixpkgs> {});
with (import <nixpkgs> {});
Line 211: Line 184:
}
}
</syntaxhighlight></li>
</syntaxhighlight></li>
<li><p>Install all specified packages using this command:</p>
<li><p><span lang="en" dir="ltr" class="mw-content-ltr">Install all specified packages using this command:</span></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>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 222: Line 194:
Another way is using [[Home Manager]].
Another way is using [[Home Manager]].
</div>
</div>
<span id="I&#039;ve_downloaded_a_binary,_but_I_can&#039;t_run_it,_what_can_I_do?"></span>
=== 我下载了一个二进制文件,但是无法运行它,我该怎么办?===


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
== 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.
</div>
</div>
Line 240: Line 214:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.nix-ld = {
programs.nix-ld = {
Line 246: Line 219:
   libraries = [ pkgs.zlib pkgs.openssl ];
   libraries = [ pkgs.zlib pkgs.openssl ];
};</syntaxhighlight>
};</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 256: Line 228:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.nix-ld = {
programs.nix-ld = {
   enable = true;
   enable = true;
   libraries = pkgs.steam-run.fhsenv.args.multiPkgs pkgs;
   libraries = pkgs.steam-run.args.multiPkgs pkgs;
};</syntaxhighlight>
};</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
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/games/steam/fhsenv.nix big list] that usually contains all the libraries your binary needs to run.
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.
</div>
</div>


Line 272: Line 242:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# mybinaryprogram.nix
# mybinaryprogram.nix
Line 293: Line 262:
   '';
   '';
}</syntaxhighlight>
}</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
This can be built with:
This can be built with:
</div>
</div>
<syntaxhighlight lang="bash">nix-build mybinaryprogram.nix</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nix-build mybinaryprogram.nix</syntaxhighlight>
And run with:
And run with:
</div>
</div>
<syntaxhighlight lang="bash">./result/bin/mybinaryprogram</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">./result/bin/mybinaryprogram</syntaxhighlight>
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]
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# fhsUser.nix
# fhsUser.nix
Line 328: Line 300:
   runScript = "bash";
   runScript = "bash";
}).env</syntaxhighlight>
}).env</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
the sandbox can be entered with
the sandbox can be entered with
</div>
</div>
<syntaxhighlight lang="bash">nix-shell fhsUser.nix</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nix-shell fhsUser.nix</syntaxhighlight>
<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? ==
</div>
 
<span id="What_are_channels_and_how_do_they_get_updated?"></span>
=== 什么是频道以及如何更新?===
 
{{main|Channel branches}}
{{main|Channel branches}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 379: Line 356:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
 
<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><span lang="en" dir="ltr" class="mw-content-ltr">Once the job succeeds at a particular nixpkgs commit, '''cache.nixos.org''' will download binaries from '''hydra.nixos.org'''.</span></li>
<li>Once the above download completes, the channel updates.</li></ol>
<li><span lang="en" dir="ltr" class="mw-content-ltr">Once the above download completes, the channel updates.</span></li>
</div>
</ol>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 389: Line 366:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_do_I_know_where&#039;s_nixpkgs_channel_located_and_at_which_commit?"></span>
== How do I know where's nixpkgs channel located and at which commit? ==
=== 我如何知道 nixpkgs 频道位于哪里以及在哪个提交?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 400: Line 376:
If you want to know where <nixpkgs> is located:
If you want to know where <nixpkgs> is located:
</div>
</div>
<syntaxhighlight lang="bash">nix-instantiate --find-file nixpkgs</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nix-instantiate --find-file nixpkgs</syntaxhighlight>
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.
</div>
</div>
<span id="Nixpkgs_branches"></span>
=== Nixpkgs 分支 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
== 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.
</div>
</div>
Line 424: Line 403:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="There&#039;s_an_updated_version_for_$software_on_nixpkgs_but_not_in_channels,_how_can_I_use_it?"></span>
== There's an updated version for $software on nixpkgs but not in channels, how can I use it? ==
=== nixpkgs 上有 $software 的更新版本,但在频道中没有,我该如何使用它?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 432: Line 410:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<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>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_do_I_install_a_specific_version_of_a_package_for_build_reproducibility_etc.?"></span>
== How do I install a specific version of a package for build reproducibility etc.? ==
=== 如何安装特定版本的软件包以实现构建可重复性等?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 450: Line 425:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="An_error_occurs_while_fetching_sources_from_an_url,_how_do_I_fix_it?"></span>
== An error occurs while fetching sources from an url, how do I fix it? ==
=== 从 URL 获取源时发生错误,我该如何修复?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 459: Line 433:


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
If that fails you can update the url in the nix expression yourself. [https://nixos.org/wiki/FAQ#How_do_I_know_where.27s_nixpkgs_channel_located_and_at_which_commit.3F 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 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.
</div>
</div>


Line 469: Line 443:
start a new shell with a private mount namespace (Linux-only)
start a new shell with a private mount namespace (Linux-only)
</div>
</div>
<syntaxhighlight lang="bash">sudo unshare -m bash</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">sudo unshare -m bash</syntaxhighlight>
remount the filesystem with write privileges (as root)
remount the filesystem with write privileges (as root)
</div>
</div>
<syntaxhighlight lang="bash">mount -o remount,rw /nix/store</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">mount -o remount,rw /nix/store</syntaxhighlight>
update the file
update the file
</div>
</div>
<syntaxhighlight lang="bash">nano <PATH_TO_PACKAGE>/default.nix</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nano <PATH_TO_PACKAGE>/default.nix</syntaxhighlight>
exit to shell where /nix/store is still mounted read-only
exit to shell where /nix/store is still mounted read-only
</div>
</div>
<syntaxhighlight lang="bash">exit</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">exit</syntaxhighlight>
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].
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_do_I_know_the_sha256_to_use_with_fetchgit,_fetchsvn,_fetchbzr_or_fetchcvs?"></span>
== How do I know the sha256 to use with fetchgit, fetchsvn, fetchbzr or fetchcvs? ==
=== 我如何知道要与 fetchgit、fetchsvn、fetchbzr 或 fetchcvs 一起使用的 sha256?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 502: Line 479:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<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>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 510: Line 485:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Should_I_use_http://hydra.nixos.org/_as_a_binary_cache?"></span>
== Should I use http://hydra.nixos.org/ as a binary cache? ==
=== 我应该使用 http://hydra.nixos.org/ 作为二进制缓存吗?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
不可以。截至 2017 年,所有构建工件都直接推送到 http://cache.nixos.org/ 并在那里可用,因此将 http://hydra.nixos.org/ 设置为二进制缓存不再具有任何功能。
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.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="I&#039;m_trying_to_install_NixOS_but_my_WiFi_isn&#039;t_working_and_I_don&#039;t_have_an_ethernet_port"></span>
== I'm trying to install NixOS but my WiFi isn't working and I don't have an ethernet port ==
=== 我正在尝试安装 NixOS,但我的 WiFi 无法使用,而且我没有以太网端口 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 534: Line 505:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_can_I_disable_the_binary_cache_and_build_everything_locally?"></span>
== How can I disable the binary cache and build everything locally? ==
=== 我如何禁用二进制缓存并在本地构建所有内容?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 546: Line 516:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nixos-rebuild switch --option binary-caches ''</syntaxhighlight>
<syntaxhighlight lang="bash">nixos-rebuild switch --option binary-caches ''</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_do_I_enable_sandboxed_builds_on_non-NixOS?"></span>
== How do I enable sandboxed builds on non-NixOS? ==
=== 如何在非 NixOS 上启用沙盒构建?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 558: Line 525:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# /etc/nix/nix.conf
# /etc/nix/nix.conf
Line 564: Line 530:
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>
<div lang="en" dir="ltr" class="mw-content-ltr">
On NixOS set the following in ''configuration.nix'':
On NixOS set the following in ''configuration.nix'':
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
nix.settings.sandbox = true;
nix.settings.sandbox = true;
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 577: Line 543:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="How_can_I_install_a_package_from_unstable_while_remaining_on_the_stable_channel?"></span>
== How can I install a package from unstable while remaining on the stable channel? ==
=== 我如何在稳定频道上安装来自不稳定频道的软件包?===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 585: Line 550:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<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>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
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'',
</div>
</div>
<syntaxhighlight lang="bash">sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable</syntaxhighlight>
After updating the channel
After updating the channel
</div>
</div>
<syntaxhighlight lang="bash">sudo nix-channel --update nixos-unstable</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">sudo nix-channel --update nixos-unstable</syntaxhighlight>
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''.
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ config, pkgs, ... }:
{ config, pkgs, ... }:
Line 612: Line 576:
}
}
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
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]]:
</div>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ config, pkgs, ... }:
{ config, pkgs, ... }:
Line 628: Line 593:
}
}
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
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]).
</div>
</div>
Line 633: Line 600:
<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
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:
</div>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
import <nixos-unstable> { config = { allowUnfree = true; }; }
import <nixos-unstable> { config = { allowUnfree = true; }; }
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="I&#039;m_unable_to_connect_my_USB_HDD_|_External_HDD_is_failing_to_mount_automatically"></span>
== I'm unable to connect my USB HDD | External HDD is failing to mount automatically ==
=== 我无法连接我的 USB HDD | 外部 HDD 无法自动安装 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 650: Line 617:
</div>  
</div>  


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">su nano /etc/nixos/configuration.nix</syntaxhighlight>
<syntaxhighlight lang="bash">su nano /etc/nixos/configuration.nix</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Add this line to your configuration file.
Add this line to your configuration file.
</div>
<syntaxhighlight lang="bash">boot.extraModulePackages = [ config.boot.kernelPackages.exfat-nofuse ];</syntaxhighlight>
<syntaxhighlight lang="bash">boot.extraModulePackages = [ config.boot.kernelPackages.exfat-nofuse ];</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 663: Line 629:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight>
<syntaxhighlight lang="bash">nixos-rebuild switch</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 671: Line 635:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="What_is_the_origin_of_the_name_&quot;Nix&quot;"></span>
== What is the origin of the name "Nix" ==
=== “Nix” 这个名字的由来 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
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>
</div>
</div>
<span id="What_does_it_mean_to_say_that_NixOS_is_&quot;immutable&quot;"></span>
=== NixOS 中的“不可变”是什么意思 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
== 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.
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="I&#039;m_getting_‘infinite_recursion’_errors_when_trying_to_do_something_clever_with_imports"></span>
== I'm getting ‘infinite recursion’ errors when trying to do something clever with <code>imports</code> ==
=== 当我尝试使用 <code>imports</code> 做一些巧妙的事情时,我得到了“无限递归”(infinite recursion)错误 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 704: Line 668:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{:FAQ/Libraries}}
{{:FAQ/Libraries}}
{{:FAQ/nix-env -iA}}
{{:FAQ/nix-env -iA}}
{{:FAQ/stateVersion}}
{{:FAQ/stateVersion}}
{{:FAQ/notfound}}
{{:FAQ/notfound}}
{{:FAQ/unfree}}
<!-- Transclude subpages -->
<!-- Transclude subpages -->
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="References"></span>
== References ==
== 参考 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[[Category:Cookbook]]
[[Category:Cookbook]]
</div>