2022-04-10 11:54:58 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(lib)
|
2022-01-11 16:08:21 +01:00
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
2022-04-10 11:54:58 +02:00
|
|
|
;
|
2022-01-11 16:08:21 +01:00
|
|
|
|
2021-08-07 15:19:45 +02:00
|
|
|
cfg = config.my.services.fava;
|
|
|
|
my = config.my;
|
|
|
|
domain = config.networking.domain;
|
|
|
|
secrets = config.my.secrets;
|
2022-04-10 11:54:58 +02:00
|
|
|
in {
|
|
|
|
options.my.services.fava = let
|
|
|
|
inherit (lib) types;
|
|
|
|
in {
|
2022-01-11 16:08:21 +01:00
|
|
|
enable = mkEnableOption "Fava";
|
2021-08-07 15:19:45 +02:00
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/fava";
|
|
|
|
example = "/var/lib/fava";
|
|
|
|
description = "Home for the fava service, where data will be stored";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port for Fava";
|
|
|
|
};
|
|
|
|
|
|
|
|
filePath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "my_dir/money.beancount";
|
|
|
|
description = "File to load in Fava";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.fava = {
|
2022-04-10 11:54:58 +02:00
|
|
|
wantedBy = ["multi-user.target"];
|
2021-08-07 15:19:45 +02:00
|
|
|
serviceConfig = {
|
|
|
|
Environment = [];
|
2021-11-17 02:29:06 +01:00
|
|
|
ExecStart = "${pkgs.fava}/bin/fava -H 127.0.0.1 -p ${toString cfg.port} ${cfg.home}/${cfg.filePath}";
|
2021-08-07 15:19:45 +02:00
|
|
|
WorkingDirectory = cfg.home;
|
|
|
|
User = "fava";
|
|
|
|
Group = "fava";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.fava = {
|
|
|
|
isSystemUser = true;
|
|
|
|
home = cfg.home;
|
|
|
|
createHome = true;
|
|
|
|
group = "fava";
|
|
|
|
};
|
2022-04-10 11:54:58 +02:00
|
|
|
users.groups.fava = {};
|
2021-08-07 15:19:45 +02:00
|
|
|
|
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
"fava.${domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = domain;
|
|
|
|
|
|
|
|
listen = [
|
|
|
|
# FIXME: hardcoded tailscale IP
|
|
|
|
{
|
|
|
|
addr = "100.80.61.67";
|
|
|
|
port = 443;
|
|
|
|
ssl = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
addr = "100.80.61.67";
|
|
|
|
port = 80;
|
|
|
|
ssl = false;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|