-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloadManifest.nix
More file actions
69 lines (67 loc) · 1.86 KB
/
Copy pathloadManifest.nix
File metadata and controls
69 lines (67 loc) · 1.86 KB
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
{ lib, manifestPath }:
let
inherit (builtins)
attrNames
foldl'
fromJSON
hasAttr
isString
readFile
;
inherit (lib) concatStringsSep hasPrefix throwIf;
parsed = fromJSON (readFile manifestPath);
requiredKeys = [
"tag"
"publishedAt"
"assets"
"logseqRev"
"logseqVersion"
"cliSrcHash"
"cliPnpmDepsHash"
"cliBundlePnpmDepsHash"
"cliCljDepsHash"
"cliVersion"
];
missing = lib.filter (key: !hasAttr key parsed) requiredKeys;
requiredAssetSystems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
missingAssetSystems =
if hasAttr "assets" parsed then
lib.filter (system: !hasAttr system parsed.assets) requiredAssetSystems
else
requiredAssetSystems;
validateHash =
acc: key:
throwIf (
!hasPrefix "sha256-" parsed.${key}
) "Manifest ${key} must begin with sha256- (Nix SRI)." acc;
# Each per-system desktop asset must carry a string url and an SRI sha256.
assetSystems = if hasAttr "assets" parsed then attrNames parsed.assets else [ ];
validateAsset =
acc: system:
let
entry = parsed.assets.${system};
in
throwIf (!(hasAttr "url" entry && isString entry.url))
"Manifest assets.${system}.url must be a string."
(
throwIf (
!(hasAttr "sha256" entry && hasPrefix "sha256-" entry.sha256)
) "Manifest assets.${system}.sha256 must begin with sha256- (Nix SRI)." acc
);
in
throwIf (missing != [ ]) "Manifest missing required keys: ${concatStringsSep ", " missing}" (
throwIf (missingAssetSystems != [ ])
"Manifest missing required desktop asset systems: ${concatStringsSep ", " missingAssetSystems}"
(
foldl' validateAsset (foldl' validateHash parsed [
"cliSrcHash"
"cliPnpmDepsHash"
"cliBundlePnpmDepsHash"
"cliCljDepsHash"
]) assetSystems
)
)