diff options
author | Payas Relekar <payas@relekar.org> | 2024-03-16 14:26:22 +0530 |
---|---|---|
committer | Payas Relekar <payas@relekar.org> | 2024-03-28 20:08:28 +0530 |
commit | 466b994af99a23ce1140eedb610199606708d7b0 (patch) | |
tree | 5ab30d4df52de75605b3f3470a91738d19078187 /nixos/modules/services/misc | |
parent | 050f4664b55e1a7f1d405d611cd12677b03b14d0 (diff) |
nixos/workout-tracker: init
Diffstat (limited to 'nixos/modules/services/misc')
-rw-r--r-- | nixos/modules/services/misc/workout-tracker.nix | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/nixos/modules/services/misc/workout-tracker.nix b/nixos/modules/services/misc/workout-tracker.nix new file mode 100644 index 0000000000000..13555504be302 --- /dev/null +++ b/nixos/modules/services/misc/workout-tracker.nix @@ -0,0 +1,83 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) types; + cfg = config.services.workout-tracker; + stateDir = "workout-tracker"; +in + +{ + options = { + services.workout-tracker = { + enable = lib.mkEnableOption "workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities"; + + package = lib.mkPackageOption pkgs "workout-tracker" { }; + + address = lib.mkOption { + type = types.str; + default = "127.0.0.1"; + description = "Web interface address."; + }; + + port = lib.mkOption { + type = types.port; + default = 8080; + description = "Web interface port."; + }; + + environmentFile = lib.mkOption { + type = types.nullOr types.path; + default = null; + example = "/run/keys/workout-tracker.env"; + description = '' + An environment file as defined in {manpage}`systemd.exec(5)`. + + Secrets like `WT_JWT_ENCRYPTION_KEY` may be passed to the service without adding them + to the world-readable Nix store. + ''; + }; + + settings = lib.mkOption { + type = types.attrsOf types.str; + + default = { }; + description = '' + Extra config options. + ''; + example = { + WT_LOGGING = "true"; + WT_DEBUG = "false"; + WT_DATABASE_DRIVER = "sqlite"; + WT_DSN = "./database.db"; + }; + }; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.workout-tracker = { + description = "A workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities"; + wantedBy = [ "multi-user.target" ]; + environment = { + WT_BIND = "${cfg.address}:${toString cfg.port}"; + WT_DATABASE_DRIVER = "sqlite"; + WT_DSN = "./database.db"; + } // cfg.settings; + serviceConfig = { + ExecStart = lib.getExe cfg.package; + DynamicUser = true; + StateDirectory = stateDir; + WorkingDirectory = "%S/${stateDir}"; + Restart = "always"; + EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile; + }; + }; + }; + + meta.maintainers = with lib.maintainers; [ bhankas ]; +} |