-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
/
Copy pathnix-flakes.nix
110 lines (106 loc) · 2.92 KB
/
nix-flakes.nix
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Manages the flake registry.
See also
- ./nix.nix
- ./nix-channel.nix
*/
{ config, lib, ... }:
let
inherit (lib)
filterAttrs
literalExpression
mapAttrsToList
mkDefault
mkIf
mkOption
types
;
cfg = config.nix;
in
{
options = {
nix = {
registry = mkOption {
type = types.attrsOf (
types.submodule (
let
referenceAttrs =
with types;
attrsOf (oneOf [
str
int
bool
path
package
]);
in
{ config, name, ... }:
{
options = {
from = mkOption {
type = referenceAttrs;
example = {
type = "indirect";
id = "nixpkgs";
};
description = "The flake reference to be rewritten.";
};
to = mkOption {
type = referenceAttrs;
example = {
type = "github";
owner = "my-org";
repo = "my-nixpkgs";
};
description = "The flake reference {option}`from` is rewritten to.";
};
flake = mkOption {
type = types.nullOr types.attrs;
default = null;
example = literalExpression "nixpkgs";
description = ''
The flake input {option}`from` is rewritten to.
'';
};
exact = mkOption {
type = types.bool;
default = true;
description = ''
Whether the {option}`from` reference needs to match exactly. If set,
a {option}`from` reference like `nixpkgs` does not
match with a reference like `nixpkgs/nixos-20.03`.
'';
};
};
config = {
from = mkDefault {
type = "indirect";
id = name;
};
to = mkIf (config.flake != null) (
mkDefault (
{
type = "path";
path = config.flake.outPath;
}
// filterAttrs (n: _: n == "lastModified" || n == "rev" || n == "narHash") config.flake
)
);
};
}
)
);
default = { };
description = ''
A system-wide flake registry.
'';
};
};
};
config = mkIf cfg.enable {
environment.etc."nix/registry.json".text = builtins.toJSON {
version = 2;
flakes = mapAttrsToList (n: v: { inherit (v) from to exact; }) cfg.registry;
};
};
}