1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#nix #flake
---
Nix flakes are source trees containing a file `flake.nix` at their root. The file `flake.nix` provides a standardized way to provide [[Zettelkast/Index/Nix]] artifacts. It's like a package manager for [[Zettelkast/Index/Nix]]. A flake can be dependent on other Flakes and it's possible to pin dependencies to exact revisions by using a `flake.lock` file.
Nix flake evaluation is hermetic, meaning that it produces the same result wherever it's built.k
The feature can be enabled in `~/.config/nix/nix.conf`:
```
experimental-features = nix-command flakes
```
To initialize in a repo: `nix flake init`.
In flakes dependencies have to be specified explicitly and MUST be locked to specific versions therefore it's no longer allowed to use the nixpkgs found in `NIX_PATH` by referencing it like `<nixpkgs>`.
Output of a Flake is an arbitrary [[Zettelkast/Index/Nix]] value such as a package, [[NixOS]] module or library function.
Commands `nix build` and `nix shell` will build the output `packages.<system>.default` unless we specify another output, for example: `nix shell .#checks.aarch64-linux.build`.
**Inputs**
```
{
inputs = {
# GitHub repository as the data source, specifying the master branch.
# This is the most common input format.
nixpkgs.url = "github:Mic92/nixpkgs/master";
# Git URL, applicable to any Git repository using the https/ssh protocol.
git-example.url = "git+https://git.somehost.tld/user/path?ref=branch";
# Git URL by tag, applicable to any Git repository using the https/ssh protocol.
git-example-tag.url = "git+https://git.somehost.tld/user/path?tag=x.y.x";
# Github URL by pull request.
git-pr.url = "github:NixOS/nixpkgs?ref=pull/349351/head";
# Git URL with submodules, applicable to any Git repository using the https/ssh protocol.
git-example-submodule.url = "git+https://git.somehost.tld/user/path?submodules=1";
# Archive File URL, needed in case your input use LFS.
# Regular git input doesn't support LFS yet.
git-example-lfs.url = "https://codeberg.org/solver-orgz/treedome/archive/master.tar.gz";
# Similar to fetching a Git repository, but using the ssh protocol
# with key authentication. Also uses the shallow=1 parameter
# to avoid copying the .git directory.
ssh-git-example.url = "git+ssh://git@github.com/ryan4yin/nix-secrets.git?shallow=1";
# It's also possible to directly depend on a local Git repository.
git-directory-example.url = "git+file:/path/to/repo?shallow=1";
# Using the `dir` parameter to specify a subdirectory.
nixpkgs.url = "github:foo/bar?dir=shu";
# Local folder (if using an absolute path, the 'path:' prefix can be omitted).
directory-example.url = "path:/path/to/repo";
# If the data source is not a flake, set flake=false.
# `flake=false` is usually used to include additional source code,
# configuration files, etc.
# In Nix code, you can directly reference files within
# it using "${inputs.bar}/xxx/xxx" notation.
# For example, import "${inputs.bar}/xxx/xxx.nix" to import a specific nix file,
# or use "${inputs.bar}/xx/xx" as a path parameter for certain options.
bar = {
url = "github:foo/bar/branch";
flake = false;
};
sops-nix = {
url = "github:Mic92/sops-nix";
# `follows` is the inheritance syntax within inputs.
# Here, it ensures that sops-nix's `inputs.nixpkgs` aligns with
# the current flake's inputs.nixpkgs,
# avoiding inconsistencies in the dependency's nixpkgs version.
inputs.nixpkgs.follows = "nixpkgs";
};
# Lock the flake to a specific commit.
nix-doom-emacs = {
url = "github:vlaci/nix-doom-emacs?rev=238b18d7b2c8239f676358634bfb32693d3706f3";
flake = false;
};
};
outputs = { self, ... }@inputs: { ... };
}
```
---
[Flakes Wiki](https://nixos.wiki/wiki/Flakes)
|