mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
refactor(openwebrx): pull out common module config
This commit is contained in:
parent
047f240b6a
commit
d92c986f8a
12 changed files with 477 additions and 166 deletions
48
modules/nixos/openwebrx.nix
Normal file
48
modules/nixos/openwebrx.nix
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.modules) mkIf mkOptionDefault mkForce;
|
||||
inherit (lib.trivial) mapNullable;
|
||||
cfg = config.services.openwebrx;
|
||||
in {
|
||||
options.services.openwebrx = with lib.types; {
|
||||
port = mkOption {
|
||||
type = port;
|
||||
default = 8073;
|
||||
readOnly = true;
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = path;
|
||||
default = "/var/lib/openwebrx";
|
||||
readOnly = true;
|
||||
};
|
||||
user = mkOption {
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
};
|
||||
group = mkOption {
|
||||
type = nullOr str;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
services.openwebrx = {
|
||||
group = mkOptionDefault (mapNullable (user: config.users.users.${user}.group) cfg.user);
|
||||
};
|
||||
|
||||
systemd.services.openwebrx = mkIf cfg.enable {
|
||||
serviceConfig = mkIf (cfg.user != null) {
|
||||
DynamicUser = mkForce false;
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
};
|
||||
};
|
||||
|
||||
environment.systemPackages = mkIf cfg.enable [
|
||||
cfg.package
|
||||
];
|
||||
};
|
||||
}
|
||||
29
modules/system/exports/openwebrx.nix
Normal file
29
modules/system/exports/openwebrx.nix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.openwebrx = { config, ... }: {
|
||||
id = mkAlmostOptionDefault "webrx";
|
||||
nixos = {
|
||||
serviceAttr = "openwebrx";
|
||||
assertions = let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.openwebrx;
|
||||
in f nixosConfig cfg;
|
||||
in mkIf config.enable [
|
||||
(mkAssertion (nixosConfig: cfg: {
|
||||
assertion = config.ports.default.port == cfg.port;
|
||||
message = "port mismatch";
|
||||
}))
|
||||
];
|
||||
};
|
||||
defaults.port.listen = mkAlmostOptionDefault "lan";
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
default = {
|
||||
port = 8073;
|
||||
protocol = "http";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue