mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2025-06-22 13:01:25 +02:00
fix: code block's style
This commit is contained in:
parent
57a3289fb8
commit
06281dfb7e
@ -16,7 +16,8 @@ Let's take a look at an example module that loads overlays. This module can be u
|
||||
|
||||
{
|
||||
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: {
|
||||
google-chrome = super.google-chrome.override {
|
||||
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: {
|
||||
steam = prev.steam.override {
|
||||
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:
|
||||
|
||||
```nix
|
||||
# import all nix files in the current folder, and execute them with args as parameters
|
||||
# The return value is a list of all execution results, which is the list of overlays
|
||||
# import all nix files in the current folder,
|
||||
# and execute them with args as parameters
|
||||
# The return value is a list of all execution results,
|
||||
# which is the list of overlays
|
||||
|
||||
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
|
||||
(f: (import (./. + "/${f}") args)) # execute and import the overlay file
|
||||
(builtins.filter # find all overlay files in the current directory
|
||||
# execute and import the overlay file
|
||||
(f: (import (./. + "/${f}") args))
|
||||
# find all overlay files in the current directory
|
||||
(builtins.filter
|
||||
(f: f != "default.nix")
|
||||
(builtins.attrNames (builtins.readDir ./.)))
|
||||
```
|
||||
@ -82,8 +89,11 @@ Next, write your overlay configurations in the `overlays` folder. For example, y
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
(self: super: {
|
||||
rime-data = ./rime-data-flypy; # Customized rime-data package
|
||||
fcitx5-rime = super.fcitx5-rime.override { rimeDataPkgs = [ ./rime-data-flypy ]; };
|
||||
# Customized rime-data package
|
||||
rime-data = ./rime-data-flypy;
|
||||
fcitx5-rime = super.fcitx5-rime.override {
|
||||
rimeDataPkgs = [ ./rime-data-flypy ];
|
||||
};
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -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`.
|
||||
|
||||
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
|
||||
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/hello/default.nix
|
||||
{ callPackage
|
||||
, lib
|
||||
, stdenv
|
||||
|
@ -53,7 +53,8 @@
|
||||
})
|
||||
|
||||
# overlay3 - 也可以将 overlay 定义在其他文件中
|
||||
# 这里 overlay3.nix 中的内容格式与上面的一致,都是 `final: prev: { xxx = prev.xxx.override { ... }; }`
|
||||
# 这里 overlay3.nix 中的内容格式与上面的一致
|
||||
# 都是 `final: prev: { xxx = prev.xxx.override { ... }; }`
|
||||
(import ./overlays/overlay3.nix)
|
||||
];
|
||||
}
|
||||
@ -74,23 +75,29 @@ args:
|
||||
# import 当前文件夹下所有的 nix 文件,并以 args 为参数执行它们
|
||||
# 返回值是一个所有执行结果的列表,也就是 overlays 的列表
|
||||
builtins.map
|
||||
(f: (import (./. + "/${f}") args)) # map 的第一个参数,是一个 import 并执行 nix 文件的函数
|
||||
(builtins.filter # map 的第二个参数,它返回一个当前文件夹下除 default.nix 外所有 nix 文件的列表
|
||||
# map 的第一个参数,是一个 import 并执行 nix 文件的函数
|
||||
(f: (import (./. + "/${f}") args))
|
||||
# map 的第二个参数,它返回一个当前文件夹下除 default.nix 外所有 nix 文件的列表
|
||||
(builtins.filter
|
||||
(f: f != "default.nix")
|
||||
(builtins.attrNames (builtins.readDir ./.)))
|
||||
```
|
||||
|
||||
后续所有 overlays 配置都添加到 `overlays` 文件夹中,一个示例配置 `overlays/fcitx5/default.nix` 内容如下:
|
||||
|
||||
> 这里参考了 https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix
|
||||
|
||||
```nix
|
||||
# 为了不使用默认的 rime-data,改用我自定义的小鹤音形数据,这里需要 override
|
||||
## 参考 https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix
|
||||
{pkgs, config, lib, ...}:
|
||||
|
||||
(self: super: {
|
||||
# 小鹤音形配置,配置来自 flypy.com 官方网盘的鼠须管配置压缩包「小鹤音形“鼠须管”for macOS.zip」
|
||||
# 小鹤音形配置,配置来自 flypy.com 官方网盘的
|
||||
# 鼠须管配置压缩包「小鹤音形“鼠须管”for macOS.zip」
|
||||
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 ];
|
||||
};
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -38,10 +38,9 @@ stdenv.mkDerivation rec {
|
||||
```
|
||||
|
||||
除了覆写参数,还可以通过 `overrideAttrs` 来覆写使用 `stdenv.mkDerivation` 构建的 Derivation 的属性。
|
||||
以 `pkgs.hello` 为例,首先通过前述方法查看这个包的源码:
|
||||
以 [pkgs.hello](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/hello/default.nix) 为例,首先通过前述方法查看这个包的源码:
|
||||
|
||||
```nix
|
||||
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/hello/default.nix
|
||||
{ callPackage
|
||||
, lib
|
||||
, stdenv
|
||||
|
Loading…
x
Reference in New Issue
Block a user