From f42cc7b10e43d41f6c50a2ae79dd403d6a532b23 Mon Sep 17 00:00:00 2001 From: xenofem Date: Thu, 9 May 2024 18:46:45 -0400 Subject: [PATCH] nixos module for actual --- flake.nix | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/flake.nix b/flake.nix index 456cc35..d1280ba 100644 --- a/flake.nix +++ b/flake.nix @@ -122,5 +122,48 @@ "${pname}" = package; default = package; }; + nixosModules.default = { lib, config, ... }: + with lib; + let + cfg = config.services.actual-server; + dataDir = "/var/lib/actual"; + cfgFile = writeText "actual.json" (builtins.toJSON { + inherit dataDir; + inherit (cfg) hostname port; + serverFiles = "${dataDir}/server-files"; + userFiles = "${dataDir}/user-files"; + }); + in { + options.services.actual = { + enable = mkEnableOption "Actual budget server"; + hostname = mkOption { type = types.str; default = "127.0.0.1"; }; + port = mkOption { type = types.port; default = 5006; }; + }; + config = mkIf cfg.enable { + users.users.actual = { + name = "actual"; + group = "actual"; + isSystemUser = true; + }; + + users.groups.actual = {}; + + systemd.services.actual-server = { + description = "Actual budget server"; + documentation = [ "https://actualbudget.org/docs/" ]; + wantedBy = [ "multi-user.target" ]; + after = [ "networking.target" ]; + serviceConfig = { + ExecStart = "${package}/bin/actual"; + Restart = "always"; + User = "actual"; + Group = "actual"; + PrivateTmp = true; + StateDirectory = "actual"; + }; + environment.ACTUAL_CONFIG_PATH = "${cfgFile}"; + }; + }; + }; }; }