| 1 | { pkgs, ... }: |
| 2 | { |
| 3 | fileSystems."/srv/tiny" = { |
| 4 | device = "/dev/disk/by-uuid/98f49cba-bd8c-432d-a91a-41db66920e90" ; |
| 5 | fsType = "ext4" ; |
| 6 | options = [ "noatime" "nofail" "x-systemd.device-timeout=15s" ]; |
| 7 | }; |
| 8 | |
| 9 | services.fstrim.enable = true; |
| 10 | |
| 11 | systemd.services.tiny-certificates = { |
| 12 | description = "Renew tiny HTTPS certificates" ; |
| 13 | after = [ "tiny.service" ]; |
| 14 | requires = [ "tiny.service" ]; |
| 15 | unitConfig.RequiresMountsFor = "/srv/tiny" ; |
| 16 | path = [ pkgs.bash pkgs.coreutils pkgs.docker pkgs.openssl pkgs.util-linux ]; |
| 17 | serviceConfig = { |
| 18 | Type = "oneshot" ; |
| 19 | ExecStart = "${pkgs.bash}/bin/bash /srv/tiny/deploy/renew-certificates.sh" ; |
| 20 | }; |
| 21 | }; |
| 22 | |
| 23 | systemd.timers.tiny-certificates = { |
| 24 | wantedBy = [ "timers.target" ]; |
| 25 | timerConfig = { |
| 26 | OnCalendar = "daily" ; |
| 27 | Persistent = true; |
| 28 | RandomizedDelaySec = "1h" ; |
| 29 | }; |
| 30 | }; |
| 31 | |
| 32 | systemd.services.tiny = { |
| 33 | description = "Personal tiny relay" ; |
| 34 | wantedBy = [ "multi-user.target" ]; |
| 35 | after = [ "docker.service" "network-online.target" "srv-tiny.mount" ]; |
| 36 | requires = [ "docker.service" ]; |
| 37 | bindsTo = [ "srv-tiny.mount" ]; |
| 38 | wants = [ "network-online.target" ]; |
| 39 | unitConfig.RequiresMountsFor = "/srv/tiny" ; |
| 40 | path = [ pkgs.docker pkgs.docker-compose pkgs.util-linux ]; |
| 41 | preStart = '' |
| 42 | test "$(findmnt -n -o UUID --target /srv/tiny)" = 98f49cba-bd8c-432d-a91a-41db66920e90 |
| 43 | '' ; |
| 44 | serviceConfig = { |
| 45 | Type = "oneshot" ; |
| 46 | RemainAfterExit = true; |
| 47 | WorkingDirectory = "/srv/tiny/deploy" ; |
| 48 | ExecStart = "${pkgs.docker-compose}/bin/docker-compose -f compose.yaml up -d --no-build" ; |
| 49 | ExecStop = "${pkgs.docker-compose}/bin/docker-compose -f compose.yaml down --timeout 30" ; |
| 50 | TimeoutStartSec = 180; |
| 51 | TimeoutStopSec = 90; |
| 52 | }; |
| 53 | }; |
| 54 | } |