aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flakes/private/openarc/flake.lock16
-rw-r--r--flakes/private/openarc/flake.nix5
-rw-r--r--flakes/private/opendmarc/flake.lock16
-rw-r--r--flakes/private/opendmarc/flake.nix5
-rw-r--r--flakes/private/peertube/flake.lock32
-rw-r--r--flakes/private/peertube/flake.nix10
-rw-r--r--lib/flake-compat-patched.nix190
-rw-r--r--lib/flake-compat.nix12
8 files changed, 225 insertions, 61 deletions
diff --git a/flakes/private/openarc/flake.lock b/flakes/private/openarc/flake.lock
index 7bafcae..b1ec2b5 100644
--- a/flakes/private/openarc/flake.lock
+++ b/flakes/private/openarc/flake.lock
@@ -70,19 +70,13 @@
70 "openarc": "openarc_2" 70 "openarc": "openarc_2"
71 }, 71 },
72 "locked": { 72 "locked": {
73 "dir": "flakes/openarc", 73 "narHash": "sha256-cTe5ak0julFu18fRiXVWZ469km8dPVTRidjl21W+SWc=",
74 "lastModified": 1611220039, 74 "path": "../../openarc",
75 "narHash": "sha256-R6XrtP+YIa+038LmlEo4B3X3RbMzidk/vo5yKTTKFx4=", 75 "type": "path"
76 "ref": "master",
77 "rev": "ef43c36272ca539cbfe803ded03949451b17b679",
78 "revCount": 803,
79 "type": "git",
80 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
81 }, 76 },
82 "original": { 77 "original": {
83 "dir": "flakes/openarc", 78 "path": "../../openarc",
84 "type": "git", 79 "type": "path"
85 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
86 } 80 }
87 }, 81 },
88 "openarc_2": { 82 "openarc_2": {
diff --git a/flakes/private/openarc/flake.nix b/flakes/private/openarc/flake.nix
index 6a2518b..65a56ca 100644
--- a/flakes/private/openarc/flake.nix
+++ b/flakes/private/openarc/flake.nix
@@ -1,8 +1,7 @@
1{ 1{
2 inputs.openarc = { 2 inputs.openarc = {
3 url = "https://git.immae.eu/perso/Immae/Config/Nix.git"; 3 path = "../../openarc";
4 type = "git"; 4 type = "path";
5 dir = "flakes/openarc";
6 }; 5 };
7 inputs.nixpkgs.url = "github:NixOS/nixpkgs"; 6 inputs.nixpkgs.url = "github:NixOS/nixpkgs";
8 7
diff --git a/flakes/private/opendmarc/flake.lock b/flakes/private/opendmarc/flake.lock
index 2c2a07d..ae07161 100644
--- a/flakes/private/opendmarc/flake.lock
+++ b/flakes/private/opendmarc/flake.lock
@@ -121,19 +121,13 @@
121 "nixpkgs": "nixpkgs_3" 121 "nixpkgs": "nixpkgs_3"
122 }, 122 },
123 "locked": { 123 "locked": {
124 "dir": "flakes/opendmarc", 124 "narHash": "sha256-V6elpT2t2bYOnY6RSwLIu+SU7Zajkk7oonjscoYpWKo=",
125 "lastModified": 1611220039, 125 "path": "../../opendmarc",
126 "narHash": "sha256-R6XrtP+YIa+038LmlEo4B3X3RbMzidk/vo5yKTTKFx4=", 126 "type": "path"
127 "ref": "master",
128 "rev": "ef43c36272ca539cbfe803ded03949451b17b679",
129 "revCount": 803,
130 "type": "git",
131 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
132 }, 127 },
133 "original": { 128 "original": {
134 "dir": "flakes/opendmarc", 129 "path": "../../opendmarc",
135 "type": "git", 130 "type": "path"
136 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
137 } 131 }
138 }, 132 },
139 "root": { 133 "root": {
diff --git a/flakes/private/opendmarc/flake.nix b/flakes/private/opendmarc/flake.nix
index 9aeb3db..384bf98 100644
--- a/flakes/private/opendmarc/flake.nix
+++ b/flakes/private/opendmarc/flake.nix
@@ -1,8 +1,7 @@
1{ 1{
2 inputs.opendmarc = { 2 inputs.opendmarc = {
3 url = "https://git.immae.eu/perso/Immae/Config/Nix.git"; 3 path = "../../opendmarc";
4 type = "git"; 4 type = "path";
5 dir = "flakes/opendmarc";
6 }; 5 };
7 inputs.nixpkgs.url = "github:NixOS/nixpkgs"; 6 inputs.nixpkgs.url = "github:NixOS/nixpkgs";
8 7
diff --git a/flakes/private/peertube/flake.lock b/flakes/private/peertube/flake.lock
index 3085b0a..97c5c63 100644
--- a/flakes/private/peertube/flake.lock
+++ b/flakes/private/peertube/flake.lock
@@ -136,19 +136,13 @@
136 "peertube": "peertube" 136 "peertube": "peertube"
137 }, 137 },
138 "locked": { 138 "locked": {
139 "dir": "flakes/peertube", 139 "narHash": "sha256-YvUqraTpt/I4jw0mSrJgptLymZwlBvhwSK9VLUKD/cc=",
140 "lastModified": 1611273496, 140 "path": "../../peertube",
141 "narHash": "sha256-U+q6Ir9VsL2egLjeXZ6YpRZxwLotKcrp2I0fOX6es+c=", 141 "type": "path"
142 "ref": "master",
143 "rev": "ce95026934c4ea8c647365f68eb195459fcdff08",
144 "revCount": 806,
145 "type": "git",
146 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
147 }, 142 },
148 "original": { 143 "original": {
149 "dir": "flakes/peertube", 144 "path": "../../peertube",
150 "type": "git", 145 "type": "path"
151 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
152 } 146 }
153 }, 147 },
154 "peertube_syden": { 148 "peertube_syden": {
@@ -159,19 +153,13 @@
159 "peertube": "peertube_2" 153 "peertube": "peertube_2"
160 }, 154 },
161 "locked": { 155 "locked": {
162 "dir": "flakes/peertube", 156 "narHash": "sha256-YvUqraTpt/I4jw0mSrJgptLymZwlBvhwSK9VLUKD/cc=",
163 "lastModified": 1611270106, 157 "path": "../../peertube",
164 "narHash": "sha256-VKDczZDM9A2dGoSAEN6rUDxvLKYUuoDMefQc7fabvXo=", 158 "type": "path"
165 "ref": "master",
166 "rev": "1279eb87299a44167c4ed4a10a9088d58654b5d3",
167 "revCount": 805,
168 "type": "git",
169 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
170 }, 159 },
171 "original": { 160 "original": {
172 "dir": "flakes/peertube", 161 "path": "../../peertube",
173 "type": "git", 162 "type": "path"
174 "url": "https://git.immae.eu/perso/Immae/Config/Nix.git"
175 } 163 }
176 }, 164 },
177 "root": { 165 "root": {
diff --git a/flakes/private/peertube/flake.nix b/flakes/private/peertube/flake.nix
index bb399df..e16cbaf 100644
--- a/flakes/private/peertube/flake.nix
+++ b/flakes/private/peertube/flake.nix
@@ -1,14 +1,12 @@
1{ 1{
2 description = "Patched peertube"; 2 description = "Patched peertube";
3 inputs.peertube_origin = { 3 inputs.peertube_origin = {
4 url = "https://git.immae.eu/perso/Immae/Config/Nix.git"; 4 path = "../../peertube";
5 type = "git"; 5 type = "path";
6 dir = "flakes/peertube";
7 }; 6 };
8 inputs.peertube_syden = { 7 inputs.peertube_syden = {
9 url = "https://git.immae.eu/perso/Immae/Config/Nix.git"; 8 path = "../../peertube";
10 type = "git"; 9 type = "path";
11 dir = "flakes/peertube";
12 inputs.peertube = { 10 inputs.peertube = {
13 url = "https://git.immae.eu/github/Chocobozzz/PeerTube.git"; 11 url = "https://git.immae.eu/github/Chocobozzz/PeerTube.git";
14 ref = "gitolite_local/syden"; 12 ref = "gitolite_local/syden";
diff --git a/lib/flake-compat-patched.nix b/lib/flake-compat-patched.nix
new file mode 100644
index 0000000..217a99f
--- /dev/null
+++ b/lib/flake-compat-patched.nix
@@ -0,0 +1,190 @@
1# Compatibility function to allow flakes to be used by
2# non-flake-enabled Nix versions. Given a source tree containing a
3# 'flake.nix' and 'flake.lock' file, it fetches the flake inputs and
4# calls the flake's 'outputs' function. It then returns an attrset
5# containing 'defaultNix' (to be used in 'default.nix'), 'shellNix'
6# (to be used in 'shell.nix').
7
8{ src, system ? builtins.currentSystem or "unknown-system" }:
9
10let
11
12 lockFilePath = src + "/flake.lock";
13
14 lockFile = builtins.fromJSON (builtins.readFile lockFilePath);
15
16 fetchTree =
17 info:
18 if info.type == "github" then
19 { outPath = fetchTarball "https://api.${info.host or "github.com"}/repos/${info.owner}/${info.repo}/tarball/${info.rev}";
20 rev = info.rev;
21 shortRev = builtins.substring 0 7 info.rev;
22 lastModified = info.lastModified;
23 lastModifiedDate = formatSecondsSinceEpoch info.lastModified;
24 narHash = info.narHash;
25 }
26 else if info.type == "git" then
27 { outPath =
28 builtins.fetchGit
29 ({ url = info.url; }
30 // (if info ? rev then { inherit (info) rev; } else {})
31 // (if info ? ref then { inherit (info) ref; } else {})
32 );
33 lastModified = info.lastModified;
34 lastModifiedDate = formatSecondsSinceEpoch info.lastModified;
35 narHash = info.narHash;
36 } // (if info ? rev then {
37 rev = info.rev;
38 shortRev = builtins.substring 0 7 info.rev;
39 } else {
40 })
41 else if info.type == "path" then
42 { outPath = builtins.path { path =
43 if builtins.substring 0 1 info.path == "."
44 then builtins.toString src + "/" + info.path
45 else info.path;
46 };
47 narHash = info.narHash;
48 }
49 else if info.type == "tarball" then
50 { outPath = fetchTarball info.url;
51 narHash = info.narHash;
52 }
53 else if info.type == "gitlab" then
54 { inherit (info) rev narHash lastModified;
55 outPath = fetchTarball "https://${info.host or "gitlab.com"}/api/v4/projects/${info.owner}%2F${info.repo}/repository/archive.tar.gz?sha=${info.rev}";
56 shortRev = builtins.substring 0 7 info.rev;
57 }
58 else
59 # FIXME: add Mercurial, tarball inputs.
60 throw "flake input has unsupported input type '${info.type}'";
61
62 callFlake4 = flakeSrc: locks:
63 let
64 flake = import (flakeSrc + "/flake.nix");
65
66 inputs = builtins.mapAttrs (n: v:
67 if v.flake or true
68 then callFlake4 (fetchTree (v.locked // v.info)) v.inputs
69 else fetchTree (v.locked // v.info)) locks;
70
71 outputs = flakeSrc // (flake.outputs (inputs // {self = outputs;}));
72 in
73 assert flake.edition == 201909;
74 outputs;
75
76 callLocklessFlake = flakeSrc:
77 let
78 flake = import (flakeSrc + "/flake.nix");
79 outputs = flakeSrc // (flake.outputs ({ self = outputs; }));
80 in outputs;
81
82 rootSrc = let
83 # Try to clean the source tree by using fetchGit, if this source
84 # tree is a valid git repository.
85 tryFetchGit = src:
86 if isGit && !isShallow
87 then
88 let res = builtins.fetchGit src;
89 in if res.rev == "0000000000000000000000000000000000000000" then removeAttrs res ["rev" "shortRev"] else res
90 else { outPath = src; };
91 # NB git worktrees have a file for .git, so we don't check the type of .git
92 isGit = builtins.pathExists (src + "/.git");
93 isShallow = builtins.pathExists (src + "/.git/shallow");
94
95 in
96 { lastModified = 0; lastModifiedDate = formatSecondsSinceEpoch 0; }
97 // (if src ? outPath then src else tryFetchGit src);
98
99 # Format number of seconds in the Unix epoch as %Y%m%d%H%M%S.
100 formatSecondsSinceEpoch = t:
101 let
102 rem = x: y: x - x / y * y;
103 days = t / 86400;
104 secondsInDay = rem t 86400;
105 hours = secondsInDay / 3600;
106 minutes = (rem secondsInDay 3600) / 60;
107 seconds = rem t 60;
108
109 # Courtesy of https://stackoverflow.com/a/32158604.
110 z = days + 719468;
111 era = (if z >= 0 then z else z - 146096) / 146097;
112 doe = z - era * 146097;
113 yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
114 y = yoe + era * 400;
115 doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
116 mp = (5 * doy + 2) / 153;
117 d = doy - (153 * mp + 2) / 5 + 1;
118 m = mp + (if mp < 10 then 3 else -9);
119 y' = y + (if m <= 2 then 1 else 0);
120
121 pad = s: if builtins.stringLength s < 2 then "0" + s else s;
122 in "${toString y'}${pad (toString m)}${pad (toString d)}${pad (toString hours)}${pad (toString minutes)}${pad (toString seconds)}";
123
124 allNodes =
125 builtins.mapAttrs
126 (key: node:
127 let
128 sourceInfo =
129 if key == lockFile.root
130 then rootSrc
131 else fetchTree (node.info or {} // removeAttrs node.locked ["dir"]);
132
133 subdir = if key == lockFile.root then "" else node.locked.dir or "";
134
135 flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
136
137 inputs = builtins.mapAttrs
138 (inputName: inputSpec: allNodes.${resolveInput inputSpec})
139 (node.inputs or {});
140
141 # Resolve a input spec into a node name. An input spec is
142 # either a node name, or a 'follows' path from the root
143 # node.
144 resolveInput = inputSpec:
145 if builtins.isList inputSpec
146 then getInputByPath lockFile.root inputSpec
147 else inputSpec;
148
149 # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the
150 # root node, returning the final node.
151 getInputByPath = nodeName: path:
152 if path == []
153 then nodeName
154 else
155 getInputByPath
156 # Since this could be a 'follows' input, call resolveInput.
157 (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path})
158 (builtins.tail path);
159
160 outputs = flake.outputs (inputs // { self = result; });
161
162 result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; };
163 in
164 if node.flake or true then
165 assert builtins.isFunction flake.outputs;
166 result
167 else
168 sourceInfo
169 )
170 lockFile.nodes;
171
172 result =
173 if !(builtins.pathExists lockFilePath)
174 then callLocklessFlake rootSrc
175 else if lockFile.version == 4
176 then callFlake4 rootSrc (lockFile.inputs)
177 else if lockFile.version >= 5 && lockFile.version <= 7
178 then allNodes.${lockFile.root}
179 else throw "lock file '${lockFilePath}' has unsupported version ${toString lockFile.version}";
180
181in
182 rec {
183 defaultNix =
184 result
185 // (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {});
186
187 shellNix =
188 defaultNix
189 // (if result ? devShell.${system} then { default = result.devShell.${system}; } else {});
190 }
diff --git a/lib/flake-compat.nix b/lib/flake-compat.nix
index 1f0d492..d3daa10 100644
--- a/lib/flake-compat.nix
+++ b/lib/flake-compat.nix
@@ -1,6 +1,8 @@
1src: 1src:
2(import ( 2(import ./flake-compat-patched.nix { inherit src; }).defaultNix
3 fetchTarball { 3# Until https://github.com/edolstra/flake-compat/pull/18 is accepted
4 url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; 4# (import (
5 sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; 5# fetchTarball {
6 }) { inherit src; }).defaultNix 6# url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
7# sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
8# }) { inherit src; }).defaultNix