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

100 lines
2.5 KiB
Nix
Raw Normal View History

2023-08-25 18:51:20 +02:00
{ config, pkgs, lib, ... }:
let
cfg = config.shb.hledger;
2024-01-12 08:22:46 +01:00
contracts = pkgs.callPackage ../contracts {};
2023-08-25 18:51:20 +02:00
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";
};
2024-01-12 08:22:46 +01:00
ssl = lib.mkOption {
description = "Path to SSL files";
type = lib.types.nullOr contracts.ssl.certs;
default = null;
};
2023-08-25 18:51:20 +02:00
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;
2024-04-17 18:03:29 +02:00
allow = "edit";
2023-08-25 18:51:20 +02:00
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";
};
2024-05-25 00:01:45 +02:00
shb.nginx.vhosts = [
2023-08-25 18:51:20 +02:00
{
2024-01-12 08:22:46 +01:00
inherit (cfg) subdomain domain authEndpoint ssl;
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
];
};
};
}