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@" ];
70 enable = true; # Fails with and without: https://github.com/tweak/trustix/issue/24
75 pub = "@trustixPubKey@";
78 remotes = [ "grpc+http://alisha/" ];
80 engine = "percentage";
81 percentage.minimum = 66;
84 nix.extraOptions = '''
85 post-build-hook = ${log-local-builds}
91 { config, trustixPubKeyPath, binaryCachePubKeyPath ? "/dev/null", }:
92 writeShellScript "mkConfig" ''
96 s,@trustixPubKey@,$(< ${trustixPubKeyPath}),
97 s,@binaryCachePubKey@,$(< ${binaryCachePubKeyPath}),
98 " ${config} > /etc/nixos/local.nix
99 cat > /etc/nixos/configuration.nix <<EOF
102 ${../lib/nixosTest-rebuild-switch.nix}
111 name = "one-publisher";
113 alisha = { pkgs, ... }: {
115 ../lib/nixosTest-rebuild-switch.nix
117 "${trustixKeyConfig}"
119 system.extraDependencies = [
120 pkgs.hello.inputDerivation
121 pkgs.remarshal # For building trustix-config.toml
124 ../lib/nixosTest-rebuild-switch.nix
126 "${trustixKeyConfig}"
131 virtualisation.diskSize = "1000";
132 virtualisation.memorySize = "1G";
134 clint = { pkgs, ... }: {
136 ../lib/nixosTest-rebuild-switch.nix
138 "${binaryCacheKeyConfig}"
140 system.extraDependencies = [
141 pkgs.hello.inputDerivation
142 pkgs.remarshal # For building trustix-config.toml
145 ../lib/nixosTest-rebuild-switch.nix
147 "${binaryCacheKeyConfig}"
152 virtualisation.diskSize = "1000";
153 virtualisation.memorySize = "1G";
157 from os import getenv
158 from threading import Thread
160 alisha.wait_for_file("/keys/trustix-pub")
161 alisha.copy_from_vm("/keys/trustix-pub")
162 clint.copy_from_host(getenv("out") + "/trustix-pub", "/keys/alisha-signing-pub")
164 clint.wait_for_file("/keys/cache-priv-key.pem")
165 clint_thread = Thread(
166 target=lambda: clint.succeed(
169 config = clientConfig;
170 trustixPubKeyPath = "/keys/alisha-signing-pub";
171 binaryCachePubKeyPath = "/keys/cache-priv-key.pem";
174 "nixos-rebuild switch --show-trace",
182 config = publisherConfig;
183 trustixPubKeyPath = "/keys/trustix-pub";
186 "nixos-rebuild switch --show-trace",
188 alisha.succeed("nix-build '<nixpkgs>' -A hello")
191 clint.succeed("nix-build '<nixpkgs>' -A hello")
192 clint.fail("grep hello /var/log/local-builds")