-
Notifications
You must be signed in to change notification settings - Fork 46
/
template.nix
128 lines (123 loc) · 3.08 KB
/
template.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
args_@{
attrName,
# the attr in nixpkgs could be different from what we want to provide
# example: us libvncserver_master nixpkgs libvncserver
nixpkgsAttrName,
prev,
extra,
replace,
replaceInput,
...
}:
let
inherit (prev) lib;
metadata = import ../pkgs/${attrName}/metadata.nix;
ignore = [
"attrName"
"nixpkgsAttrName"
"prev"
"extra"
"replace"
"replaceInput"
];
args = builtins.removeAttrs (args_ // replaceInput) ignore;
nixpkgsAttr = if nixpkgsAttrName != "" then nixpkgsAttrName else attrName;
overridenAttr =
(lib.attrByPath (lib.splitString "." nixpkgsAttr)
(throw "attr ${attrName} does not exist in nixpkgs")
prev
).override
args;
fetchers =
let
fetchSubmodules = metadata.fetchSubmodules or overridenAttr.src.fetchSubmodules or false;
in
{
github = prev.fetchFromGitHub {
inherit (metadata)
owner
repo
rev
sha256
;
inherit fetchSubmodules;
};
gitlab = prev.fetchFromGitLab {
inherit (metadata)
owner
repo
rev
sha256
;
domain = metadata.domain or "gitlab.com";
# uncomment after https://github.com/NixOS/nixpkgs/pull/198489
#inherit fetchSubmodules;
};
gitea = prev.fetchFromGitea {
inherit (metadata)
owner
repo
rev
sha256
domain
;
inherit fetchSubmodules;
};
gitsourcehut = prev.fetchFromSourcehut {
inherit (metadata)
owner
repo
rev
sha256
;
inherit fetchSubmodules;
};
hgsourcehut = prev.fetchFromSourcehut {
inherit (metadata)
owner
repo
rev
sha256
;
vc = "hg";
};
};
src = fetchers.${metadata.type or "github"};
cargoLock = {
lockFile = src + "/Cargo.lock";
allowBuiltinFetchGit = true;
};
replace' = previousAttrs: if builtins.isFunction replace then replace previousAttrs else replace;
in
overridenAttr.overrideAttrs (
previousAttrs:
(
{
pname = attrName;
version = "+${lib.substring 0 7 metadata.rev}";
inherit src;
}
// lib.optionalAttrs (src ? meta.homepage) {
meta = previousAttrs.meta // {
inherit (src.meta) homepage;
};
}
// lib.optionalAttrs (extra ? depsBuildBuild) {
depsBuildBuild = extra.depsBuildBuild ++ previousAttrs.depsBuildBuild;
}
// lib.optionalAttrs (extra ? nativeBuildInputs) {
nativeBuildInputs = extra.nativeBuildInputs ++ previousAttrs.nativeBuildInputs;
}
// lib.optionalAttrs (extra ? mesonFlags) {
mesonFlags = previousAttrs.mesonFlags ++ extra.mesonFlags;
}
// lib.optionalAttrs (extra ? buildInputs) {
buildInputs = extra.buildInputs ++ previousAttrs.buildInputs;
}
// lib.optionalAttrs (previousAttrs ? cargoDeps) {
cargoDeps = prev.rustPlatform.importCargoLock cargoLock;
cargoHash = null;
}
// replace' previousAttrs
)
)