vuko | bd124bd | 2021-12-28 15:05:59 +0100 | [diff] [blame] | 1 | { pkgs, workspace, ... }: |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 2 | |
| 3 | let |
vuko | bd124bd | 2021-12-28 15:05:59 +0100 | [diff] [blame] | 4 | hscloud = workspace; |
| 5 | checkinator = hscloud.hswaw.checkinator; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 6 | |
| 7 | name = "checkinator-tracker"; |
| 8 | user = name; |
| 9 | group = name; |
| 10 | socket_dir = "/run/${name}/"; |
| 11 | |
| 12 | prepare = pkgs.writeShellScriptBin "${name}-prepare" '' |
| 13 | rm -rf /mnt/secrets/${name} |
| 14 | ${pkgs.coreutils}/bin/install --owner=${user} --mode=500 --directory /mnt/secrets/${name} |
| 15 | ${pkgs.coreutils}/bin/install --owner=${user} --mode=400 -t /mnt/secrets/${name} \ |
| 16 | /etc/nixos/secrets/${name}/ca.pem \ |
| 17 | /etc/nixos/secrets/${name}/cert.pem \ |
| 18 | /etc/nixos/secrets/${name}/key.pem |
| 19 | |
| 20 | rm -rf ${socket_dir} |
| 21 | mkdir --mode=700 ${socket_dir} |
| 22 | ${pkgs.acl}/bin/setfacl -m "u:${user}:rwx" ${socket_dir} |
| 23 | ${pkgs.acl}/bin/setfacl -m "u:checkinator-web:rx" ${socket_dir} |
| 24 | ''; |
| 25 | config = builtins.toFile "${name}-config.yaml" (pkgs.lib.generators.toYAML {} { |
vuko | bd124bd | 2021-12-28 15:05:59 +0100 | [diff] [blame] | 26 | # path to dhcpd lease file |
vuko | ee8f1d5 | 2022-12-31 01:04:42 +0100 | [diff] [blame] | 27 | LEASE_FILE = "/var/lib/dhcpd4/dhcpd.leases"; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 28 | |
| 29 | # timeout for old leases |
| 30 | TIMEOUT = 1500; |
| 31 | |
| 32 | # optional - local trusted socket |
| 33 | GRPC_UNIX_SOCKET = "${socket_dir}/checkinator.sock"; |
| 34 | |
vuko | bd124bd | 2021-12-28 15:05:59 +0100 | [diff] [blame] | 35 | # optional - remote authenticated (TLS cert) socket |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 36 | GRPC_TLS_CERT_DIR = "/mnt/secrets/checkinator-tracker"; |
| 37 | GRPC_TLS_CA_CERT = "/mnt/secrets/checkinator-tracker/ca.pem"; |
| 38 | GRPC_TLS_ADDRESS = "[::]:2847"; |
| 39 | }); |
| 40 | in { |
| 41 | users.users."${user}" = { |
| 42 | group = "${group}"; |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 43 | isSystemUser = true; |
| 44 | uid = 1001; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 45 | }; |
| 46 | users.groups."${group}" = {}; |
| 47 | |
| 48 | systemd.services."${name}" = { |
| 49 | description = "Hackerspace Checkinator"; |
| 50 | wantedBy = [ "multi-user.target" ]; |
| 51 | |
| 52 | serviceConfig.User = "${user}"; |
| 53 | serviceConfig.Type = "simple"; |
vuko | ee8f1d5 | 2022-12-31 01:04:42 +0100 | [diff] [blame] | 54 | |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 55 | serviceConfig.ExecStartPre = [ |
| 56 | ''!${prepare}/bin/${name}-prepare'' |
| 57 | ]; |
| 58 | serviceConfig.ExecStart = "${checkinator}/bin/checkinator-tracker ${config}"; |
| 59 | serviceConfig.ExecStopPost = [ |
| 60 | ''!${pkgs.coreutils}/bin/rm -rf /mnt/secrets/${name}'' |
| 61 | ''!${pkgs.coreutils}/bin/rm -rf ${socket_dir}'' |
| 62 | ]; |
| 63 | |
vuko | ee8f1d5 | 2022-12-31 01:04:42 +0100 | [diff] [blame] | 64 | serviceConfig.DynamicUser = false; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 65 | }; |
| 66 | environment.systemPackages = [ checkinator ]; |
| 67 | } |