Skip to content

Commit 50f5420

Browse files
committed
refactor json docs
1 parent 2c954c9 commit 50f5420

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

dev/docs.nix

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88
docs =
99
pkgs.runCommand "docs"
1010
{
11+
passthru.json =
12+
pkgs.runCommand "docs-json"
13+
{
14+
buildInputs = [ pkgs.jq ];
15+
hosts = pkgs.writeText "hosts.json" (
16+
builtins.toJSON (
17+
pkgs.lib.mapAttrs (_: x: {
18+
experimental-features = x.config.nix.settings.experimental-features or [ ];
19+
extra-platforms = x.config.nix.settings.extra-platforms or [ ];
20+
system-features = x.config.nix.settings.system-features or [ ];
21+
inherit (x.pkgs.stdenv.hostPlatform) system;
22+
inherit (x.config.nix.settings) sandbox;
23+
}) (self.darwinConfigurations // self.nixosConfigurations)
24+
)
25+
);
26+
}
27+
''
28+
mkdir -p $out
29+
for host in $(jq -r 'keys[]' $hosts); do
30+
jq --arg host "$host" \
31+
'.[$host] | walk(if type == "array" then sort else . end)' \
32+
--sort-keys < $hosts > $out/$host.json
33+
done
34+
'';
1135
buildInputs = [
1236
pkgs.python3.pkgs.mkdocs-material
1337
pkgs.python3.pkgs.mkdocs-redirects
@@ -22,33 +46,9 @@
2246
}
2347
''
2448
cp --no-preserve=mode -r $files/* .
25-
cp --no-preserve=mode ${config.packages.docs-json}/*.json docs
49+
cp --no-preserve=mode ${config.packages.docs.json}/*.json docs
2650
mkdocs build --strict --site-dir $out
2751
'';
28-
docs-json =
29-
pkgs.runCommand "docs-json"
30-
{
31-
buildInputs = [ pkgs.jq ];
32-
hosts = pkgs.writeText "hosts.json" (
33-
builtins.toJSON (
34-
pkgs.lib.mapAttrs (_: x: {
35-
experimental-features = x.config.nix.settings.experimental-features or [ ];
36-
extra-platforms = x.config.nix.settings.extra-platforms or [ ];
37-
system-features = x.config.nix.settings.system-features or [ ];
38-
inherit (x.pkgs.stdenv.hostPlatform) system;
39-
inherit (x.config.nix.settings) sandbox;
40-
}) (self.darwinConfigurations // self.nixosConfigurations)
41-
)
42-
);
43-
}
44-
''
45-
mkdir -p $out
46-
for host in $(jq -r 'keys[]' $hosts); do
47-
jq --arg host "$host" \
48-
'.[$host] | walk(if type == "array" then sort else . end)' \
49-
--sort-keys < $hosts > $out/$host.json
50-
done
51-
'';
5252
};
5353
};
5454
}

0 commit comments

Comments
 (0)