services: setup fava service

This commit is contained in:
Antoine Martin 2021-08-07 15:19:45 +02:00
parent 38672b1a5f
commit bd5aa2cef5
3 changed files with 89 additions and 0 deletions

View file

@ -75,6 +75,12 @@ in
enable = true;
};
fava = {
enable = true;
port = 8084;
filePath = "accounts/current.beancount";
};
gitea = {
enable = true;
privatePort = 8082;

View file

@ -5,6 +5,7 @@
./bitwarden_rs.nix
./borg-backup.nix
./fail2ban.nix
./fava.nix
./gitea
./jellyfin.nix
./lohr.nix

82
services/fava.nix Normal file
View file

@ -0,0 +1,82 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.my.services.fava;
my = config.my;
domain = config.networking.domain;
secrets = config.my.secrets;
in
{
options.my.services.fava = {
enable = lib.mkEnableOption "Fava";
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 = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Environment = [];
ExecStart = "${pkgs.unstable.fava}/bin/fava -H 127.0.0.1 -p ${toString cfg.port} ${cfg.filePath}";
WorkingDirectory = cfg.home;
User = "fava";
Group = "fava";
};
path = with pkgs; [];
};
users.users.fava = {
isSystemUser = true;
home = cfg.home;
createHome = true;
group = "fava";
};
users.groups.fava = { };
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}";
};
};
};
};
}