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 clientConfig = writeText "clientConfig" ''
56 services.trustix-nix-cache = {
58 private-key = "/keys/cache-priv-key.pem";
62 binaryCaches = lib.mkForce [ "http//localhost:9001" ];
63 binaryCachePublicKeys = lib.mkForce [ "clint://@binaryCachePubKey@" ];
70 pub = "@trustixPubKey@";
73 remotes = [ "grpc+http://alisha/" ];
75 engine = "percentage";
76 percentage.minimum = 66;
84 { config, trustixPubKeyPath, binaryCachePubKeyPath ? "/dev/null", }:
85 writeShellScript "mkConfig" ''
89 s,@trustixPubKey@,$(< ${trustixPubKeyPath}),
90 s,@binaryCachePubKey@,$(< ${binaryCachePubKeyPath}),
91 " ${config} > /etc/nixos/local.nix
92 cat > /etc/nixos/configuration.nix <<EOF
95 ${../lib/nixosTest-rebuild-switch.nix}
104 name = "one-publisher";
106 alisha = { pkgs, ... }: {
108 ../lib/nixosTest-rebuild-switch.nix
110 "${trustixKeyConfig}"
112 system.extraDependencies = [
113 pkgs.hello.inputDerivation
114 pkgs.remarshal # For building trustix-config.toml
117 ../lib/nixosTest-rebuild-switch.nix
119 "${trustixKeyConfig}"
124 virtualisation.diskSize = "1000";
125 virtualisation.memorySize = "1G";
127 clint = { pkgs, ... }: {
129 ../lib/nixosTest-rebuild-switch.nix
131 "${binaryCacheKeyConfig}"
133 system.extraDependencies = [
134 pkgs.hello.inputDerivation
135 pkgs.remarshal # For building trustix-config.toml
138 ../lib/nixosTest-rebuild-switch.nix
140 "${binaryCacheKeyConfig}"
145 virtualisation.diskSize = "1000";
146 virtualisation.memorySize = "1G";
150 from os import getenv
152 alisha.wait_for_file("/keys/trustix-pub")
153 alisha.copy_from_vm("/keys/trustix-pub")
154 clint.copy_from_host(getenv("out") + "/trustix-pub", "/keys/alisha-signing-pub")
159 config = publisherConfig;
160 trustixPubKeyPath = "/keys/trustix-pub";
163 "nixos-rebuild switch --show-trace",
165 alisha.succeed("nix-build '<nixpkgs>' -A hello")
167 clint.wait_for_file("/keys/cache-priv-key.pem")
171 config = clientConfig;
172 trustixPubKeyPath = "/keys/alisha-signing-pub";
173 binaryCachePubKeyPath = "/keys/cache-priv-key.pem";
176 "nixos-rebuild switch --show-trace",
178 clint.succeed("nix-build '<nixpkgs>' -A hello")