1
0
Fork 0
selfhostblocks/modules/services/hledger.nix

94 lines
2.4 KiB
Nix
Raw Normal View History

2023-08-25 18:51:20 +02:00
{ config, pkgs, lib, ... }:
let
cfg = config.shb.hledger;
fqdn = "${cfg.subdomain}.${cfg.domain}";
in
{
options.shb.hledger = {
enable = lib.mkEnableOption "selfhostblocks.hledger";
subdomain = lib.mkOption {
type = lib.types.str;
description = "Subdomain under which Authelia will be served.";
example = "ha";
};
domain = lib.mkOption {
type = lib.types.str;
description = "domain under which Authelia will be served.";
example = "mydomain.com";
};
port = lib.mkOption {
type = lib.types.int;
description = "HLedger port";
default = 5000;
};
localNetworkIPRange = lib.mkOption {
type = lib.types.str;
description = "Local network range, to restrict access to the UI to only those IPs.";
default = null;
example = "192.168.1.1/24";
};
2023-09-03 00:00:41 +02:00
authEndpoint = lib.mkOption {
2023-09-03 00:00:41 +02:00
type = lib.types.str;
description = "OIDC endpoint for SSO";
example = "https://authelia.example.com";
};
2023-08-25 18:51:20 +02:00
};
config = lib.mkIf cfg.enable {
services.hledger-web = {
enable = true;
2023-09-03 00:00:41 +02:00
# Must be empty otherwise it repeats the fqdn, we get something like https://${fqdn}/${fqdn}/
baseUrl = "";
2023-08-25 18:51:20 +02:00
stateDir = "/var/lib/hledger";
journalFiles = ["hledger.journal"];
host = "127.0.0.1";
port = cfg.port;
capabilities.view = true;
capabilities.add = true;
capabilities.manage = true;
extraOptions = [
# https://hledger.org/1.30/hledger-web.html
# "--capabilities-header=HLEDGER-CAP"
"--forecast"
];
};
2023-09-03 00:00:41 +02:00
systemd.services.hledger-web = {
# If the hledger.journal file does not exist, hledger-web refuses to start, so we create an
# empty one if it does not exist yet..
preStart = ''
test -f /var/lib/hledger/hledger.journal || touch /var/lib/hledger/hledger.journal
'';
serviceConfig.StateDirectory = "hledger";
};
2023-11-17 07:46:57 +01:00
shb.nginx.autheliaProtect = [
2023-08-25 18:51:20 +02:00
{
inherit (cfg) subdomain domain authEndpoint;
2023-11-17 07:46:57 +01:00
upstream = "http://${toString config.services.hledger-web.host}:${toString config.services.hledger-web.port}";
autheliaRules = [{
domain = fqdn;
policy = "two_factor";
subject = ["group:hledger_user"];
}];
2023-08-25 18:51:20 +02:00
}
];
shb.backup.instances.hledger = {
sourceDirectories = [
config.services.hledger-web.stateDir
];
};
};
}