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
158 alisha.wait_for_file("/keys/trustix-pub")
159 alisha.copy_from_vm("/keys/trustix-pub")
160 clint.copy_from_host(getenv("out") + "/trustix-pub", "/keys/alisha-signing-pub")
165 config = publisherConfig;
166 trustixPubKeyPath = "/keys/trustix-pub";
169 "nixos-rebuild switch --show-trace",
171 alisha.succeed("nix-build '<nixpkgs>' -A hello")
173 clint.wait_for_file("/keys/cache-priv-key.pem")
177 config = clientConfig;
178 trustixPubKeyPath = "/keys/alisha-signing-pub";
179 binaryCachePubKeyPath = "/keys/cache-priv-key.pem";
182 "nixos-rebuild switch --show-trace",
184 clint.succeed("nix-build '<nixpkgs>' -A hello")
185 clint.fail("grep hello /var/log/local-builds")