summaryrefslogtreecommitdiffstats
path: root/nixos/tests/canaille.nix
blob: fa0d33b0f2e2d2f1054712fbeb08baa6c78a10d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ pkgs, ... }:
let
  certs = import ./common/acme/server/snakeoil-certs.nix;
  inherit (certs) domain;
in
{
  name = "canaille";
  meta.maintainers = with pkgs.lib.maintainers; [ erictapen ];

  nodes.server =
    { pkgs, lib, ... }:
    {
      services.canaille = {
        enable = true;
        secretKeyFile = pkgs.writeText "canaille-secret-key" ''
          this is not a secret key
        '';
        settings = {
          SERVER_NAME = domain;
        };
      };

      services.nginx.virtualHosts."${domain}" = {
        enableACME = lib.mkForce false;
        sslCertificate = certs."${domain}".cert;
        sslCertificateKey = certs."${domain}".key;
      };

      networking.hosts."::1" = [ "${domain}" ];
      networking.firewall.allowedTCPPorts = [
        80
        443
      ];

      users.users.canaille.shell = pkgs.bashInteractive;

      security.pki.certificateFiles = [ certs.ca.cert ];
    };

  nodes.client =
    { nodes, ... }:
    {
      networking.hosts."${nodes.server.networking.primaryIPAddress}" = [ "${domain}" ];
      security.pki.certificateFiles = [ certs.ca.cert ];
    };

  testScript =
    { ... }:
    ''
      import json

      start_all()
      server.wait_for_unit("canaille.socket")
      server.wait_until_succeeds("curl -f https://${domain}")
      server.succeed("sudo -iu canaille -- canaille create user --user-name admin --password adminpass --emails admin@${domain}")
      json_str = server.succeed("sudo -iu canaille -- canaille get user")
      assert json.loads(json_str)[0]["user_name"] == "admin"
      server.succeed("sudo -iu canaille -- canaille config check")
    '';
}