1 { lib, pkgs, config, ... }:
4 cfg = config.services.hledger-web;
6 options.services.hledger-web = {
8 enable = mkEnableOption "hledger-web service";
10 serveApi = mkEnableOption "serving only the JSON web API, without the web UI";
14 default = "127.0.0.1";
30 type = types.enum [ "view" "add" "edit" "sandstorm" ];
33 User's access level for changing data.
35 * view: view only permission.
36 * add: view and add permissions.
37 * edit: view, add, and edit permissions.
38 * sandstorm: permissions from the `X-Sandstorm-Permissions` request header.
44 default = "/var/lib/hledger-web";
46 Path the service has access to. If left as the default value this
47 directory will automatically be created before the hledger-web server
48 starts, otherwise the sysadmin is responsible for ensuring the
49 directory exists with appropriate ownership and permissions.
53 journalFiles = mkOption {
54 type = types.listOf types.str;
55 default = [ ".hledger.journal" ];
57 Paths to journal files relative to {option}`services.hledger-web.stateDir`.
62 type = with types; nullOr str;
64 example = "https://example.org";
66 Base URL, when sharing over a network.
70 extraOptions = mkOption {
71 type = types.listOf types.str;
73 example = [ "--forecast" ];
75 Extra command line arguments to pass to hledger-web.
82 (mkRemovedOptionModule [ "services" "hledger-web" "capabilities" ]
83 "This option has been replaced by new option `services.hledger-web.allow`.")
86 config = mkIf cfg.enable {
88 users.users.hledger = {
93 useDefaultShell = true;
96 users.groups.hledger = {};
98 systemd.services.hledger-web = let
99 serverArgs = with cfg; escapeShellArgs ([
102 "--port=${toString port}"
104 (optionalString (cfg.baseUrl != null) "--base-url=${cfg.baseUrl}")
105 (optionalString (cfg.serveApi) "--serve-api")
106 ] ++ (map (f: "--file=${stateDir}/${f}") cfg.journalFiles)
109 description = "hledger-web - web-app for the hledger accounting tool.";
110 documentation = [ "https://hledger.org/hledger-web.html" ];
111 wantedBy = [ "multi-user.target" ];
112 after = [ "networking.target" ];
113 serviceConfig = mkMerge [
115 ExecStart = "${pkgs.hledger-web}/bin/hledger-web ${serverArgs}";
117 WorkingDirectory = cfg.stateDir;
122 (mkIf (cfg.stateDir == "/var/lib/hledger-web") {
123 StateDirectory = "hledger-web";
130 meta.maintainers = with lib.maintainers; [ marijanp erictapen ];