refactor(actualbudget): split service and guest config
This commit is contained in:
@@ -1,23 +1,43 @@
|
|||||||
args@{ my, ... }:
|
{
|
||||||
# Actual Budget in a NixOS guest, with durable state bind-mounted from the host.
|
config,
|
||||||
my.guest {
|
lib,
|
||||||
name = "actualbudget";
|
my,
|
||||||
interior = {
|
...
|
||||||
users.users.actual = {
|
}:
|
||||||
isSystemUser = true;
|
let
|
||||||
uid = 20001;
|
cfg = config.guests.actualbudget;
|
||||||
group = "storage";
|
dataDir = "/data";
|
||||||
};
|
in
|
||||||
|
{
|
||||||
services.actual = {
|
imports = [
|
||||||
enable = true;
|
(my.guest {
|
||||||
openFirewall = true;
|
name = "actualbudget";
|
||||||
user = "actual";
|
interior = {
|
||||||
group = "storage";
|
modules.services.actualbudget = {
|
||||||
settings = {
|
enable = true;
|
||||||
port = 5006;
|
inherit dataDir;
|
||||||
dataDir = "/data";
|
};
|
||||||
};
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
options.guests.actualbudget = {
|
||||||
|
dataPath = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = null;
|
||||||
|
example = "/srv/actualbudget";
|
||||||
|
description = "Host path bind-mounted as Actual Budget's data directory.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} args
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = cfg.dataPath != null;
|
||||||
|
message = "guests.actualbudget.dataPath must point at the host directory that stores Actual Budget data.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
guests.actualbudget.mounts.${dataDir}.hostPath = cfg.dataPath;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@
|
|||||||
autoStart = false;
|
autoStart = false;
|
||||||
vlan = 20;
|
vlan = 20;
|
||||||
mac = "BC:24:11:C1:CD:28";
|
mac = "BC:24:11:C1:CD:28";
|
||||||
mounts."/data".hostPath = "/pikachu/data/actualbudget";
|
dataPath = "/pikachu/data/actualbudget";
|
||||||
limits = {
|
limits = {
|
||||||
memory = "2G";
|
memory = "2G";
|
||||||
cpu = "200%";
|
cpu = "200%";
|
||||||
|
|||||||
61
modules/services/actualbudget.nix
Normal file
61
modules/services/actualbudget.nix
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.modules.services.actualbudget;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.modules.services.actualbudget = {
|
||||||
|
enable = lib.mkEnableOption "Actual Budget";
|
||||||
|
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 5006;
|
||||||
|
description = "Port Actual Budget listens on.";
|
||||||
|
};
|
||||||
|
|
||||||
|
dataDir = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "/data";
|
||||||
|
description = "Directory where Actual Budget stores server and user files.";
|
||||||
|
};
|
||||||
|
|
||||||
|
user = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "actual";
|
||||||
|
description = "User account that runs Actual Budget.";
|
||||||
|
};
|
||||||
|
|
||||||
|
uid = lib.mkOption {
|
||||||
|
type = lib.types.ints.positive;
|
||||||
|
default = 20001;
|
||||||
|
description = "Fixed uid for the Actual Budget service user.";
|
||||||
|
};
|
||||||
|
|
||||||
|
group = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "storage";
|
||||||
|
description = "Group account that owns Actual Budget's writable state.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
users.users.${cfg.user} = {
|
||||||
|
isSystemUser = true;
|
||||||
|
uid = cfg.uid;
|
||||||
|
group = cfg.group;
|
||||||
|
};
|
||||||
|
|
||||||
|
services.actual = {
|
||||||
|
enable = true;
|
||||||
|
openFirewall = true;
|
||||||
|
user = cfg.user;
|
||||||
|
group = cfg.group;
|
||||||
|
settings = {
|
||||||
|
inherit (cfg) port dataDir;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user