fix: code block's style

This commit is contained in:
Ryan Yin 2023-10-09 23:21:03 +08:00
parent 57a3289fb8
commit 06281dfb7e
4 changed files with 35 additions and 20 deletions

View File

@ -16,7 +16,8 @@ Let's take a look at an example module that loads overlays. This module can be u
{ {
nixpkgs.overlays = [ nixpkgs.overlays = [
# Overlay 1: Use `self` and `super` to express the inheritance relationship # Overlay 1: Use `self` and `super` to express
# the inheritance relationship
(self: super: { (self: super: {
google-chrome = super.google-chrome.override { google-chrome = super.google-chrome.override {
commandLineArgs = commandLineArgs =
@ -24,7 +25,8 @@ Let's take a look at an example module that loads overlays. This module can be u
}; };
}) })
# Overlay 2: Use `final` and `prev` to express the relationship between the new and the old # Overlay 2: Use `final` and `prev` to express
# the relationship between the new and the old
(final: prev: { (final: prev: {
steam = prev.steam.override { steam = prev.steam.override {
extraPkgs = pkgs: with pkgs; [ extraPkgs = pkgs: with pkgs; [
@ -62,14 +64,19 @@ In the previous example, all overlays were written in a single Nix file, which c
Start by creating an `overlays` folder in your Git repository to store all overlay configurations. Inside this folder, create a `default.nix` file with the following content: Start by creating an `overlays` folder in your Git repository to store all overlay configurations. Inside this folder, create a `default.nix` file with the following content:
```nix ```nix
# import all nix files in the current folder, and execute them with args as parameters # import all nix files in the current folder,
# The return value is a list of all execution results, which is the list of overlays # and execute them with args as parameters
# The return value is a list of all execution results,
# which is the list of overlays
args: args:
# execute and import all overlay files in the current directory with the given args # execute and import all overlay files in the current
# directory with the given args
builtins.map builtins.map
(f: (import (./. + "/${f}") args)) # execute and import the overlay file # execute and import the overlay file
(builtins.filter # find all overlay files in the current directory (f: (import (./. + "/${f}") args))
# find all overlay files in the current directory
(builtins.filter
(f: f != "default.nix") (f: f != "default.nix")
(builtins.attrNames (builtins.readDir ./.))) (builtins.attrNames (builtins.readDir ./.)))
``` ```
@ -82,8 +89,11 @@ Next, write your overlay configurations in the `overlays` folder. For example, y
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
(self: super: { (self: super: {
rime-data = ./rime-data-flypy; # Customized rime-data package # Customized rime-data package
fcitx5-rime = super.fcitx5-rime.override { rimeDataPkgs = [ ./rime-data-flypy ]; }; rime-data = ./rime-data-flypy;
fcitx5-rime = super.fcitx5-rime.override {
rimeDataPkgs = [ ./rime-data-flypy ];
};
}) })
``` ```

View File

@ -15,10 +15,9 @@ 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`: For example, let's take a look at the source code of [pkgs.hello](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/hello/default.nix):
```nix ```nix
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/hello/default.nix
{ callPackage { callPackage
, lib , lib
, stdenv , stdenv
@ -65,4 +64,4 @@ In this case, we override the `separateDebugInfo` attribute, which is defined in
To see all the attributes defined in `stdenv.mkDerivation`, you can check its source code by using `nix repl '<nixpkgs>'` and entering `:e stdenv.mkDerivation`. To see all the attributes defined in `stdenv.mkDerivation`, you can check its source code by using `nix repl '<nixpkgs>'` and entering `:e stdenv.mkDerivation`.
This will open the source code in your default editor. If you're new to using `nix repl`, you can type `:?` to see the help information. This will open the source code in your default editor. If you're new to using `nix repl`, you can type `:?` to see the help information.

View File

@ -53,7 +53,8 @@
}) })
# overlay3 - 也可以将 overlay 定义在其他文件中 # overlay3 - 也可以将 overlay 定义在其他文件中
# 这里 overlay3.nix 中的内容格式与上面的一致,都是 `final: prev: { xxx = prev.xxx.override { ... }; }` # 这里 overlay3.nix 中的内容格式与上面的一致
# 都是 `final: prev: { xxx = prev.xxx.override { ... }; }`
(import ./overlays/overlay3.nix) (import ./overlays/overlay3.nix)
]; ];
} }
@ -74,23 +75,29 @@ args:
# import 当前文件夹下所有的 nix 文件,并以 args 为参数执行它们 # import 当前文件夹下所有的 nix 文件,并以 args 为参数执行它们
# 返回值是一个所有执行结果的列表,也就是 overlays 的列表 # 返回值是一个所有执行结果的列表,也就是 overlays 的列表
builtins.map builtins.map
(f: (import (./. + "/${f}") args)) # map 的第一个参数,是一个 import 并执行 nix 文件的函数 # map 的第一个参数,是一个 import 并执行 nix 文件的函数
(builtins.filter # map 的第二个参数,它返回一个当前文件夹下除 default.nix 外所有 nix 文件的列表 (f: (import (./. + "/${f}") args))
# map 的第二个参数,它返回一个当前文件夹下除 default.nix 外所有 nix 文件的列表
(builtins.filter
(f: f != "default.nix") (f: f != "default.nix")
(builtins.attrNames (builtins.readDir ./.))) (builtins.attrNames (builtins.readDir ./.)))
``` ```
后续所有 overlays 配置都添加到 `overlays` 文件夹中,一个示例配置 `overlays/fcitx5/default.nix` 内容如下: 后续所有 overlays 配置都添加到 `overlays` 文件夹中,一个示例配置 `overlays/fcitx5/default.nix` 内容如下:
> 这里参考了 https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix
```nix ```nix
# 为了不使用默认的 rime-data改用我自定义的小鹤音形数据这里需要 override # 为了不使用默认的 rime-data改用我自定义的小鹤音形数据这里需要 override
## 参考 https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix
{pkgs, config, lib, ...}: {pkgs, config, lib, ...}:
(self: super: { (self: super: {
# 小鹤音形配置,配置来自 flypy.com 官方网盘的鼠须管配置压缩包「小鹤音形“鼠须管”for macOS.zip」 # 小鹤音形配置,配置来自 flypy.com 官方网盘的
# 鼠须管配置压缩包「小鹤音形“鼠须管”for macOS.zip」
rime-data = ./rime-data-flypy; rime-data = ./rime-data-flypy;
fcitx5-rime = super.fcitx5-rime.override { rimeDataPkgs = [ ./rime-data-flypy ]; }; fcitx5-rime = super.fcitx5-rime.override {
rimeDataPkgs = [ ./rime-data-flypy ];
};
}) })
``` ```

View File

@ -38,10 +38,9 @@ stdenv.mkDerivation rec {
``` ```
除了覆写参数,还可以通过 `overrideAttrs` 来覆写使用 `stdenv.mkDerivation` 构建的 Derivation 的属性。 除了覆写参数,还可以通过 `overrideAttrs` 来覆写使用 `stdenv.mkDerivation` 构建的 Derivation 的属性。
`pkgs.hello` 为例,首先通过前述方法查看这个包的源码: [pkgs.hello](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/hello/default.nix) 为例,首先通过前述方法查看这个包的源码:
```nix ```nix
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/hello/default.nix
{ callPackage { callPackage
, lib , lib
, stdenv , stdenv