Add support for simple web server

This commit is contained in:
2025-04-04 15:40:50 +02:00
parent d5d1218f5c
commit 900145a4d0
9 changed files with 1410 additions and 197 deletions

View File

@@ -5,7 +5,7 @@ self: {
system,
...
}: let
cfg = config.programs.actual-importer;
cfg = config.services.actual-importer;
appConfig = (pkgs.formats.yaml {}).generate "actual-importer.config.yaml" cfg.config;
@@ -13,14 +13,32 @@ self: {
name = "actual-importer";
runtimeInputs = [self.packages.${system}.default];
text = ''
actual-importer -c "${appConfig}" "$@";
actual-importer "$@" -c "${appConfig}";
'';
};
in
with lib; {
options.programs.actual-importer = {
options.services.actual-importer = {
enable = mkEnableOption "actual-importer";
server = {
enable = mkEnableOption "actual-importer server";
port = mkOption {
type = types.port;
description = "The port on which importer will be listening on";
default = 3000;
example = 8080;
};
openFirewall = mkOption {
type = types.bool;
description = "Whether the configured port should be opened on firewall";
default = false;
example = true;
};
};
config = mkOption {
type = types.attrs;
description = "The actual-importer config which will be eventually converted to yaml";
@@ -49,5 +67,21 @@ in
config = mkIf cfg.enable {
environment.systemPackages = [app];
systemd.services.actual-importer-server = mkIf cfg.server.enable {
enable = true;
description = "ActualBudget importer server";
wants = ["network.target"];
after = ["network.target"];
wantedBy = ["multi-user.target"];
serviceConfig = {
ExecStart = "${self.packages.${system}.default}/bin/actual-importer serve ${toString cfg.server.port} -c ${appConfig}";
};
};
networking.firewall.allowedTCPPorts = mkIf cfg.server.openFirewall [cfg.server.port];
};
}