1 { lib, gnused, nixos, nixosTest, trustix, trustixSrc, writeShellScript
4 inherit (lib) filterAttrs hasPrefix mapAttrsToList optional;
6 trustixModule = trustixSrc + "/nixos";
8 trustixKeyConfig = writeText "trustixKeyConfig" ''
11 system.activationScripts.trustix-create-key = '''
12 if [[ ! -e /keys/trustix-priv ]];then
14 ''${pkgs.trustix}/bin/trustix generate-key --privkey /keys/trustix-priv --pubkey /keys/trustix-pub
21 binaryCacheKeyConfig = writeText "binaryCacheKeyConfig" ''
24 system.activationScripts.trustix-create-key = '''
25 if [[ ! -e /keys/cache-priv-key.pem ]];then
27 ''${pkgs.nix}/bin/nix-store --generate-binary-cache-key clint /keys/cache-priv-key.pem /keys/cache-pub-key.pem
34 publisherConfig = writeText "publisherConfig" ''
38 signers.aisha-snakeoil = {
40 ed25519 = { private-key-path = "/keys/trustix-priv"; };
43 signer = "aisha-snakeoil";
47 pub = "@trustixPubKey@";
54 log-local-builds = writeShellScript "log-local-builds" ''
55 echo "$OUT_PATHS" >> /var/log/local-builds
58 clientConfig = writeText "clientConfig" ''
60 services.trustix-nix-cache = {
62 private-key = "/keys/cache-priv-key.pem";
66 binaryCaches = lib.mkForce [ "http//localhost:9001" ];
67 binaryCachePublicKeys = lib.mkForce [ "clint://@binaryCachePubKey@" ];
74 pub = "@trustixPubKey@";
77 remotes = [ "grpc+http://alisha/" ];
79 engine = "percentage";
80 percentage.minimum = 66;
83 nix.extraOptions = '''
84 post-build-hook = ${log-local-builds}
90 { config, trustixPubKeyPath, binaryCachePubKeyPath ? "/dev/null", }:
91 writeShellScript "mkConfig" ''
95 s,@trustixPubKey@,$(< ${trustixPubKeyPath}),
96 s,@binaryCachePubKey@,$(< ${binaryCachePubKeyPath}),
97 " ${config} > /etc/nixos/local.nix
98 cat > /etc/nixos/configuration.nix <<EOF
101 ${../lib/nixosTest-rebuild-switch.nix}
110 name = "one-publisher";
112 alisha = { pkgs, ... }: {
114 ../lib/nixosTest-rebuild-switch.nix
116 "${trustixKeyConfig}"
118 system.extraDependencies = [
119 pkgs.hello.inputDerivation
120 pkgs.remarshal # For building trustix-config.toml
123 ../lib/nixosTest-rebuild-switch.nix
125 "${trustixKeyConfig}"
130 virtualisation.diskSize = "1000";
131 virtualisation.memorySize = "1G";
133 clint = { pkgs, ... }: {
135 ../lib/nixosTest-rebuild-switch.nix
137 "${binaryCacheKeyConfig}"
139 system.extraDependencies = [
140 pkgs.hello.inputDerivation
141 pkgs.remarshal # For building trustix-config.toml
144 ../lib/nixosTest-rebuild-switch.nix
146 "${binaryCacheKeyConfig}"
151 virtualisation.diskSize = "1000";
152 virtualisation.memorySize = "1G";
156 from os import getenv
157 from threading import Thread
159 alisha.wait_for_file("/keys/trustix-pub")
160 alisha.copy_from_vm("/keys/trustix-pub")
161 clint.copy_from_host(getenv("out") + "/trustix-pub", "/keys/alisha-signing-pub")
163 clint.wait_for_file("/keys/cache-priv-key.pem")
164 clint_thread = Thread(
165 target=lambda: clint.succeed(
168 config = clientConfig;
169 trustixPubKeyPath = "/keys/alisha-signing-pub";
170 binaryCachePubKeyPath = "/keys/cache-priv-key.pem";
173 "nixos-rebuild switch --show-trace",
181 config = publisherConfig;
182 trustixPubKeyPath = "/keys/trustix-pub";
185 "nixos-rebuild switch --show-trace",
187 alisha.succeed("nix-build '<nixpkgs>' -A hello")
190 clint.succeed("nix-build '<nixpkgs>' -A hello")
191 clint.fail("grep hello /var/log/local-builds")