at 25.11-pre 2.3 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8let 9 inherit (lib) types; 10 cfg = config.services.workout-tracker; 11 stateDir = "workout-tracker"; 12in 13 14{ 15 options = { 16 services.workout-tracker = { 17 enable = lib.mkEnableOption "workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities"; 18 19 package = lib.mkPackageOption pkgs "workout-tracker" { }; 20 21 address = lib.mkOption { 22 type = types.str; 23 default = "127.0.0.1"; 24 description = "Web interface address."; 25 }; 26 27 port = lib.mkOption { 28 type = types.port; 29 default = 8080; 30 description = "Web interface port."; 31 }; 32 33 environmentFile = lib.mkOption { 34 type = types.nullOr types.path; 35 default = null; 36 example = "/run/keys/workout-tracker.env"; 37 description = '' 38 An environment file as defined in {manpage}`systemd.exec(5)`. 39 40 Secrets like `WT_JWT_ENCRYPTION_KEY` may be passed to the service without adding them 41 to the world-readable Nix store. 42 ''; 43 }; 44 45 settings = lib.mkOption { 46 type = types.attrsOf types.str; 47 48 default = { }; 49 description = '' 50 Extra config options. 51 ''; 52 example = { 53 WT_LOGGING = "true"; 54 WT_DEBUG = "false"; 55 WT_DATABASE_DRIVER = "sqlite"; 56 WT_DSN = "./database.db"; 57 }; 58 }; 59 }; 60 }; 61 62 config = lib.mkIf cfg.enable { 63 systemd.services.workout-tracker = { 64 description = "A workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities"; 65 wantedBy = [ "multi-user.target" ]; 66 environment = { 67 WT_BIND = "${cfg.address}:${toString cfg.port}"; 68 WT_DATABASE_DRIVER = "sqlite"; 69 WT_DSN = "./database.db"; 70 } // cfg.settings; 71 serviceConfig = { 72 ExecStart = lib.getExe cfg.package; 73 DynamicUser = true; 74 StateDirectory = stateDir; 75 WorkingDirectory = "%S/${stateDir}"; 76 Restart = "always"; 77 EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile; 78 }; 79 }; 80 }; 81 82 meta.maintainers = with lib.maintainers; [ bhankas ]; 83}