zaphyra's git: nixfiles

zaphyra's nixfiles

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 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
{
  npins,
  config,
  lib,
  pkgs,
  ...
}:

{

  options.zpha.websites."things.zaphyra.eu".enable = lib.mkEnableOption "";

  imports =
    (lib.mkIf config.zpha.websites."things.zaphyra.eu".enable [
      "${npins.things}/nixosModule.nix"
    ]).content;

  config = lib.mkIf config.zpha.websites."things.zaphyra.eu".enable {
    dns.zones."zaphyra.eu".subdomains."things".CNAME = [
      "${config.networking.fqdn}."
    ];

    users = {
      users.things.uid = 512;
      groups.things.gid = 512;
    };

    sops.secrets = {
      "restic/things/repositoryPassword" = { };
      "restic/things/sshPrivateKey" = { };
    };

    common = {
      configure.persist.system.dirs = [
        {
          directory = config.services.things.storagePath;
          mode = "0700";
          user = "things";
          group = "things";
        }
      ];

      services.resticBackup.things = {
        inherit (config.services.things) user;
        enable = true;
        targets = [
          "restic-target.fc9f.de"
          "isodon.fc9f.de"
        ];
        sshKeyFile = config.sops.secrets."restic/things/sshPrivateKey".path;
        passwordFile = config.sops.secrets."restic/things/repositoryPassword".path;
        paths = [ config.services.things.storagePath ];
      };
    };

    services = {
      things = {
        enable = true;
        package = pkgs.zpha.things;
        storagePath = "/var/lib/things";
        nginx.enable = true;
        nginx.domain = "things.zaphyra.eu";
      };

      nginx.virtualHosts."things.zaphyra.eu" = {
        useACMEHost = "${config.networking.fqdn}";
        forceSSL = true;
        kTLS = true;
      };
    };
  };

}