mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2024-12-01 12:34:11 +01:00
fix: broken links
This commit is contained in:
parent
ecfc6f5143
commit
fb2fe1224a
@ -157,5 +157,5 @@ TODO
|
|||||||
|
|
||||||
- [How to make nix build display all commands executed by make?](https://www.reddit.com/r/NixOS/comments/14stdgy/how_to_make_nix_build_display_all_commands/)
|
- [How to make nix build display all commands executed by make?](https://www.reddit.com/r/NixOS/comments/14stdgy/how_to_make_nix_build_display_all_commands/)
|
||||||
- use `NIX_DEBUG=7` in derivation
|
- use `NIX_DEBUG=7` in derivation
|
||||||
- [Collection of functions useful for debugging broken nix expressions.](https://github.com/NixOS/nixpkgs/blob/f3d9f46/lib/debug.nix)
|
- [Collection of functions useful for debugging broken nix expressions.](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/lib/debug.nix)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ In the following sections, we'll introduce how the development environment works
|
|||||||
|
|
||||||
We can create a development environment using `pkgs.mkShell { ... }` and open an interactive Bash shell of this development environment using `nix develop`.
|
We can create a development environment using `pkgs.mkShell { ... }` and open an interactive Bash shell of this development environment using `nix develop`.
|
||||||
|
|
||||||
To see how `pkgs.mkShell` works, let's take a look at [its source code](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/build-support/mkshell/default.nix).
|
To see how `pkgs.mkShell` works, let's take a look at [its source code](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/build-support/mkshell/default.nix).
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ lib, stdenv, buildEnv }:
|
{ lib, stdenv, buildEnv }:
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
We know that many programs have a large number of build parameters that need to be configured, and different users may want to use different build parameters. This is where `Overriding` and `Overlays` come in handy. Let me give you a few examples I have encountered:
|
We know that many programs have a large number of build parameters that need to be configured, and different users may want to use different build parameters. This is where `Overriding` and `Overlays` come in handy. Let me give you a few examples I have encountered:
|
||||||
|
|
||||||
1. [`fcitx5-rime.nix`](https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix): By default, `fcitx5-rime` use `rime-data` as the value of `rimeDataPkgs`, but this parameter can be customized by `override`.
|
1. [`fcitx5-rime.nix`](https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix): By default, `fcitx5-rime` use `rime-data` as the value of `rimeDataPkgs`, but this parameter can be customized by `override`.
|
||||||
2. [`vscode/with-extensions.nix`](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/applications/editors/vscode/with-extensions.nix): This package for VS Code can also be customized by overriding the value of `vscodeExtensions`, thus we can install some custom plugins into VS Code.
|
2. [`vscode/with-extensions.nix`](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/editors/vscode/with-extensions.nix): This package for VS Code can also be customized by overriding the value of `vscodeExtensions`, thus we can install some custom plugins into VS Code.
|
||||||
- [`nix-vscode-extensions`](https://github.com/nix-community/nix-vscode-extensions): This is a vscode plugin manager implemented by overriding `vscodeExtensions`.
|
- [`nix-vscode-extensions`](https://github.com/nix-community/nix-vscode-extensions): This is a vscode plugin manager implemented by overriding `vscodeExtensions`.
|
||||||
3. [`firefox/common.nix`](https://github.com/NixOS/nixpkgs/blob/416ffcd08f1f16211130cd9571f74322e98ecef6/pkgs/applications/networking/browsers/firefox/common.nix): Firefox has many customizable parameters too.
|
3. [`firefox/common.nix`](https://github.com/NixOS/nixpkgs/blob/416ffcd08f1f16211130cd9571f74322e98ecef6/pkgs/applications/networking/browsers/firefox/common.nix): Firefox has many customizable parameters too.
|
||||||
4. ...
|
4. ...
|
||||||
|
@ -54,8 +54,8 @@ We have learned in our study of Nix syntax:
|
|||||||
> The `import` expression takes a path to another Nix file as an argument and returns the execution result of that Nix file.
|
> The `import` expression takes a path to another Nix file as an argument and returns the execution result of that Nix file.
|
||||||
> If the argument to `import` is a folder path, it returns the execution result of the `default.nix` file within that folder.
|
> If the argument to `import` is a folder path, it returns the execution result of the `default.nix` file within that folder.
|
||||||
|
|
||||||
`nixpkgs` is a flake with a `default.nix` file in its root directory. So, `import nixpkgs` essentially returns the execution result of [nixpkgs/default.nix](https://github.com/NixOS/nixpkgs/blob/f3d9f46/default.nix).
|
`nixpkgs` is a flake with a `default.nix` file in its root directory. So, `import nixpkgs` essentially returns the execution result of [nixpkgs/default.nix](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/default.nix).
|
||||||
Starting from this file, you can find that the implementation of `import nixpkgs` is in [pkgs/top-level/impure.nix](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/top-level/impure.nix), as excerpted below:
|
Starting from this file, you can find that the implementation of `import nixpkgs` is in [pkgs/top-level/impure.nix](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/top-level/impure.nix), as excerpted below:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
# ... skipping some lines
|
# ... skipping some lines
|
||||||
|
@ -15,7 +15,7 @@ To find out which parameters of a specific package can be overridden, there are
|
|||||||
|
|
||||||
By using these methods, you can discover the input parameters of a package and determine which ones can be modified using `override`.
|
By using these methods, you can discover the input parameters of a package and determine which ones can be modified using `override`.
|
||||||
|
|
||||||
For example, let's take a look at the source code of [pkgs.hello](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/applications/misc/hello/default.nix):
|
For example, let's take a look at the source code of [pkgs.hello](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/misc/hello/default.nix):
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ callPackage
|
{ callPackage
|
||||||
|
@ -153,6 +153,6 @@ TODO
|
|||||||
|
|
||||||
- [How to make nix build display all commands executed by make?](https://www.reddit.com/r/NixOS/comments/14stdgy/how_to_make_nix_build_display_all_commands/)
|
- [How to make nix build display all commands executed by make?](https://www.reddit.com/r/NixOS/comments/14stdgy/how_to_make_nix_build_display_all_commands/)
|
||||||
- use `NIX_DEBUG=7` in derivation
|
- use `NIX_DEBUG=7` in derivation
|
||||||
- [Collection of functions useful for debugging broken nix expressions.](https://github.com/NixOS/nixpkgs/blob/f3d9f46/lib/debug.nix)
|
- [Collection of functions useful for debugging broken nix expressions.](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/lib/debug.nix)
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
为了更好的使用上述两个功能,我们先来看看它们的原理。
|
为了更好的使用上述两个功能,我们先来看看它们的原理。
|
||||||
|
|
||||||
[`pkgs.mkShell` 的源码](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/build-support/mkshell/default.nix)如下:
|
[`pkgs.mkShell` 的源码](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/build-support/mkshell/default.nix)如下:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ lib, stdenv, buildEnv }:
|
{ lib, stdenv, buildEnv }:
|
||||||
|
@ -5,7 +5,7 @@ callPackage、Overriding 与 Overlays 是在使用 Nix 时偶尔会用到的技
|
|||||||
我们知道许多程序都有大量构建参数需要配置,不同的用户会希望使用不同的构建参数,这时候就需要 Overriding 与 Overlays 来实现。我举几个我遇到过的例子:
|
我们知道许多程序都有大量构建参数需要配置,不同的用户会希望使用不同的构建参数,这时候就需要 Overriding 与 Overlays 来实现。我举几个我遇到过的例子:
|
||||||
|
|
||||||
1. [fcitx5-rime.nix](https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix): fcitx5-rime 的 `rimeDataPkgs` 默认使用 `rime-data` 包,但是也可以通过 override 来自定义该参数的值,以加载自定义的 rime 配置(比如加载小鹤音形输入法配置)。
|
1. [fcitx5-rime.nix](https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix): fcitx5-rime 的 `rimeDataPkgs` 默认使用 `rime-data` 包,但是也可以通过 override 来自定义该参数的值,以加载自定义的 rime 配置(比如加载小鹤音形输入法配置)。
|
||||||
2. [vscode/with-extensions.nix](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/applications/editors/vscode/with-extensions.nix): vscode 的这个包也可以通过 override 来自定义 `vscodeExtensions` 参数的值来安装自定义插件。
|
2. [vscode/with-extensions.nix](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/editors/vscode/with-extensions.nix): vscode 的这个包也可以通过 override 来自定义 `vscodeExtensions` 参数的值来安装自定义插件。
|
||||||
1. [nix-vscode-extensions](https://github.com/nix-community/nix-vscode-extensions): 就是利用该参数实现的 vscode 插件管理
|
1. [nix-vscode-extensions](https://github.com/nix-community/nix-vscode-extensions): 就是利用该参数实现的 vscode 插件管理
|
||||||
3. [firefox/common.nix](https://github.com/NixOS/nixpkgs/blob/416ffcd08f1f16211130cd9571f74322e98ecef6/pkgs/applications/networking/browsers/firefox/common.nix): firefox 同样有许多可自定义的参数
|
3. [firefox/common.nix](https://github.com/NixOS/nixpkgs/blob/416ffcd08f1f16211130cd9571f74322e98ecef6/pkgs/applications/networking/browsers/firefox/common.nix): firefox 同样有许多可自定义的参数
|
||||||
4. 等等
|
4. 等等
|
||||||
|
@ -54,8 +54,8 @@
|
|||||||
> `import` 表达式以其他 Nix 文件的路径作为参数,返回该 Nix 文件的执行结果。
|
> `import` 表达式以其他 Nix 文件的路径作为参数,返回该 Nix 文件的执行结果。
|
||||||
> `import` 的参数如果为文件夹路径,那么会返回该文件夹下的 `default.nix` 文件的执行结果。
|
> `import` 的参数如果为文件夹路径,那么会返回该文件夹下的 `default.nix` 文件的执行结果。
|
||||||
|
|
||||||
`nixpkgs` 是一个 Git 仓库,它的根目录下刚好有一个 `default.nix` 文件,那么答案就呼之欲出了:`import nixpkgs` 就是返回 [nixpkgs/default.nix](https://github.com/NixOS/nixpkgs/blob/f3d9f46/default.nix) 文件的执行结果。
|
`nixpkgs` 是一个 Git 仓库,它的根目录下刚好有一个 `default.nix` 文件,那么答案就呼之欲出了:`import nixpkgs` 就是返回 [nixpkgs/default.nix](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/default.nix) 文件的执行结果。
|
||||||
从这个文件开始探索,就能找到 `import nixpkgs` 的实现代码是 [pkgs/top-level/impure.nix](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/top-level/impure.nix),这里截取部分内容:
|
从这个文件开始探索,就能找到 `import nixpkgs` 的实现代码是 [pkgs/top-level/impure.nix](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/top-level/impure.nix),这里截取部分内容:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
# ... skip some lines
|
# ... skip some lines
|
||||||
|
@ -38,7 +38,7 @@ stdenv.mkDerivation rec {
|
|||||||
```
|
```
|
||||||
|
|
||||||
除了覆写参数,还可以通过 `overrideAttrs` 来覆写使用 `stdenv.mkDerivation` 构建的 Derivation 的属性。
|
除了覆写参数,还可以通过 `overrideAttrs` 来覆写使用 `stdenv.mkDerivation` 构建的 Derivation 的属性。
|
||||||
以 [pkgs.hello](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/applications/misc/hello/default.nix) 为例,首先通过前述方法查看这个包的源码:
|
以 [pkgs.hello](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/misc/hello/default.nix) 为例,首先通过前述方法查看这个包的源码:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ callPackage
|
{ callPackage
|
||||||
|
@ -393,7 +393,7 @@ Store Object 的存放路径格式为 `/nix/store/<hash>-<name>`,其中 `<hash
|
|||||||
Derivation 实质上只是一个 attribute set,Nix 底层会使用内置函数 `builtins.derivation` 将这个 attribute set 构建为一个 Store Object。
|
Derivation 实质上只是一个 attribute set,Nix 底层会使用内置函数 `builtins.derivation` 将这个 attribute set 构建为一个 Store Object。
|
||||||
我们实际编写 Derivation 时,通常使用的是 `stdenv.mkDerivation`,它是前述内置函数 `builtins.derivation` 的 Nix 语言 wrapper,屏蔽了底层的细节,简化了用法。
|
我们实际编写 Derivation 时,通常使用的是 `stdenv.mkDerivation`,它是前述内置函数 `builtins.derivation` 的 Nix 语言 wrapper,屏蔽了底层的细节,简化了用法。
|
||||||
|
|
||||||
一个简单的 Derivation 如下,它声明了一个名为 hello 的应用程序(摘抄自 [nixpkgs/pkgs/hello](https://github.com/NixOS/nixpkgs/blob/f3d9f46/pkgs/applications/misc/hello/default.nix)):
|
一个简单的 Derivation 如下,它声明了一个名为 hello 的应用程序(摘抄自 [nixpkgs/pkgs/hello](https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/misc/hello/default.nix)):
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ callPackage
|
{ callPackage
|
||||||
|
Loading…
Reference in New Issue
Block a user