1{ lib, pkgs, ... }:
2
3let
4 accessKey = "BKIKJAA5BMMU2RHO6IBB";
5 secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
6
7 minioCredentialsFile = pkgs.writeText "minio-credentials-full" ''
8 MINIO_ROOT_USER=${accessKey}
9 MINIO_ROOT_PASSWORD=${secretKey}
10 '';
11 environmentFile = pkgs.runCommand "atticd-env" { } ''
12 echo ATTIC_SERVER_TOKEN_RS256_SECRET_BASE64="$(${lib.getExe pkgs.openssl} genrsa -traditional 4096 | ${pkgs.coreutils}/bin/base64 -w0)" > $out
13 '';
14in
15
16{
17 name = "atticd";
18
19 nodes = {
20 local = {
21 services.atticd = {
22 enable = true;
23
24 inherit environmentFile;
25 };
26
27 environment.systemPackages = [
28 pkgs.attic-client
29 ];
30 };
31
32 s3 = {
33 services.atticd = {
34 enable = true;
35 settings = {
36 storage = {
37 type = "s3";
38 bucket = "attic";
39 region = "us-east-1";
40 endpoint = "http://127.0.0.1:9000";
41
42 credentials = {
43 access_key_id = accessKey;
44 secret_access_key = secretKey;
45 };
46 };
47 };
48
49 inherit environmentFile;
50 };
51
52 services.minio = {
53 enable = true;
54 rootCredentialsFile = minioCredentialsFile;
55 };
56
57 environment.systemPackages = [
58 pkgs.attic-client
59 pkgs.minio-client
60 ];
61 };
62 };
63
64 testScript = # python
65 ''
66 start_all()
67
68 with subtest("local storage push"):
69 local.wait_for_unit("atticd.service")
70 token = local.succeed("atticd-atticadm make-token --sub stop --validity 1y --create-cache '*' --pull '*' --push '*' --delete '*' --configure-cache '*' --configure-cache-retention '*'").strip()
71
72 local.succeed(f"attic login local http://localhost:8080 {token}")
73 local.succeed("attic cache create test-cache")
74 local.succeed("attic push test-cache ${environmentFile}")
75
76 with subtest("s3 storage push"):
77 s3.wait_for_unit("atticd.service")
78 s3.wait_for_unit("minio.service")
79 s3.wait_for_open_port(9000)
80 s3.succeed(
81 "mc alias set minio "
82 + "http://localhost:9000 "
83 + "${accessKey} ${secretKey} --api s3v4",
84 "mc mb minio/attic",
85 )
86 token = s3.succeed("atticd-atticadm make-token --sub stop --validity 1y --create-cache '*' --pull '*' --push '*' --delete '*' --configure-cache '*' --configure-cache-retention '*'").strip()
87
88 s3.succeed(f"attic login s3 http://localhost:8080 {token}")
89 s3.succeed("attic cache create test-cache")
90 s3.succeed("attic push test-cache ${environmentFile}")
91 '';
92}