···11+{ pkgs, ... }:
22+# Private CA of the build farm plus the client cert lass uses towards it.
33+# Shared, so every machine importing this sees the same CA. Clan requires a
44+# shared generator to be defined identically on all machines, so nothing is
55+# deployed from here: per-machine generators (nix-farm-server in builder.nix,
66+# nix-farm-client in client.nix) depend on it and copy out the files they
77+# need with their own owner/mode. The certs are not secret, but as secret
88+# files their paths are known before `clan vars generate` ran, so the configs
99+# still evaluate until then.
1010+{
1111+ clan.core.vars.generators.nix-farm-ca = {
1212+ share = true;
1313+ files."ca.key".deploy = false;
1414+ files."ca.crt".deploy = false;
1515+ files."client.key".deploy = false;
1616+ files."client.crt".deploy = false;
1717+ runtimeInputs = [ pkgs.openssl ];
1818+ script = ''
1919+ openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
2020+ -keyout "$out/ca.key" -out "$out/ca.crt" -days 3650 \
2121+ -subj "/CN=nix-farm-ca" \
2222+ -addext "basicConstraints=critical,CA:TRUE" \
2323+ -addext "keyUsage=critical,keyCertSign,cRLSign"
2424+2525+ openssl req -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
2626+ -keyout "$out/client.key" -out client.csr -subj "/CN=lass"
2727+ printf '%s\n' \
2828+ "basicConstraints=critical,CA:FALSE" \
2929+ "keyUsage=critical,digitalSignature" \
3030+ "extendedKeyUsage=clientAuth" > client.ext
3131+ openssl x509 -req -in client.csr -CA "$out/ca.crt" -CAkey "$out/ca.key" \
3232+ -CAcreateserial -days 3650 -extfile client.ext -out "$out/client.crt"
3333+ '';
3434+ };
3535+}