|
3 | 3 | `flake.nix` 中的 `inputs` 是一个 attribute set,用来指定当前 Flake 的依赖,inputs 有很多种 |
4 | 4 | 类型,举例如下: |
5 | 5 |
|
| 6 | +> 详细的例子参见官方文档 [Flakes Inputs - Nix Manual] |
| 7 | +
|
6 | 8 | ```nix |
7 | 9 | { |
8 | 10 | inputs = { |
9 | 11 | # 以 GitHub 仓库为数据源,指定使用 master 分支,这是最常见的 input 格式 |
10 | 12 | nixpkgs.url = "github:Mic92/nixpkgs/master"; |
11 | 13 | # Git URL,可用于任何基于 https/ssh 协议的 Git 仓库 |
12 | 14 | git-example.url = "git+https://git.somehost.tld/user/path?ref=branch"; |
13 | | - # 同样是拉取 Git 仓库,但使用 ssh 协议 + 密钥认证,同时使用了 shallow=1 参数避免复制 .git |
14 | | - ssh-git-example.url = "git+ssh://[email protected]/ryan4yin/nix-secrets.git?shallow=1"; |
| 15 | + # Git URL by tag, applicable to any Git repository using the https/ssh protocol. |
| 16 | + git-example-tag.url = "git+https://git.somehost.tld/user/path?tag=x.y.x"; |
| 17 | + # Github URL by pull request. |
| 18 | + git-pr.url = "github:NixOS/nixpkgs?ref=pull/349351/head"; |
| 19 | + # Git URL with submodules, applicable to any Git repository using the https/ssh protocol. |
| 20 | + git-example-submodule.url = "git+https://git.somehost.tld/user/path?submodules=1"; |
15 | 21 | # Archive File URL, needed in case your input use LFS. |
16 | | - # Regular git input doesn't support LFS yet. |
| 22 | + # Regular git input doesn't support LFS before nix 2.27 |
17 | 23 | git-example-lfs.url = "https://codeberg.org/solver-orgz/treedome/archive/master.tar.gz"; |
| 24 | + # Starting from nix 2.27, you can use the url like below to enable git lfs on flake input |
| 25 | + treedome.url = "git+https://codeberg.org/solver-orgz/treedome?ref=master&lfs=1"; |
| 26 | + # 同样是拉取 Git 仓库,但使用 ssh 协议 + 密钥认证,同时使用了 shallow=1 参数避免复制 .git |
| 27 | + ssh-git-example.url = "git+ssh://[email protected]/ryan4yin/nix-secrets.git?shallow=1"; |
18 | 28 | # 当然也可以直接依赖本地的 git 仓库 |
19 | 29 | git-directory-example.url = "git+file:/path/to/repo?shallow=1"; |
20 | 30 | # 使用 `dir` 参数指定某个子目录 |
|
50 | 60 | outputs = { self, ... }@inputs: { ... }; |
51 | 61 | } |
52 | 62 | ``` |
| 63 | + |
| 64 | + |
| 65 | +## 参考 |
| 66 | + |
| 67 | +- [Flakes Inputs - Nix Manual] |
| 68 | + |
| 69 | +[Flakes Inputs - Nix Manual]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references |
0 commit comments