at 21.11-pre 1.7 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 cfg = config.services.trac; 5 6 inherit (lib) mkEnableOption mkIf mkOption types; 7 8in { 9 10 options = { 11 12 services.trac = { 13 enable = mkEnableOption "Trac service"; 14 15 listen = { 16 ip = mkOption { 17 type = types.str; 18 default = "0.0.0.0"; 19 description = '' 20 IP address that Trac should listen on. 21 ''; 22 }; 23 24 port = mkOption { 25 type = types.port; 26 default = 8000; 27 description = '' 28 Listen port for Trac. 29 ''; 30 }; 31 }; 32 33 dataDir = mkOption { 34 default = "/var/lib/trac"; 35 type = types.path; 36 description = '' 37 The directory for storing the Trac data. 38 ''; 39 }; 40 41 openFirewall = mkOption { 42 type = types.bool; 43 default = false; 44 description = '' 45 Open ports in the firewall for Trac. 46 ''; 47 }; 48 }; 49 50 }; 51 52 config = mkIf cfg.enable { 53 54 systemd.services.trac = { 55 description = "Trac server"; 56 wantedBy = [ "multi-user.target" ]; 57 serviceConfig = { 58 DynamicUser = true; 59 StateDirectory = baseNameOf cfg.dataDir; 60 ExecStart = '' 61 ${pkgs.trac}/bin/tracd -s \ 62 -b ${toString cfg.listen.ip} \ 63 -p ${toString cfg.listen.port} \ 64 ${cfg.dataDir} 65 ''; 66 }; 67 preStart = '' 68 if [ ! -e ${cfg.dataDir}/VERSION ]; then 69 ${pkgs.trac}/bin/trac-admin ${cfg.dataDir} initenv Trac "sqlite:db/trac.db" 70 fi 71 ''; 72 }; 73 74 networking.firewall = mkIf cfg.openFirewall { 75 allowedTCPPorts = [ cfg.listen.port ]; 76 }; 77 78 }; 79}