mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
chore: nf-fmt-nix
This commit is contained in:
parent
37137017c2
commit
c8bc78fb88
4 changed files with 152 additions and 140 deletions
|
|
@ -13,9 +13,11 @@ let
|
||||||
inherit (lib.strings) hasPrefix;
|
inherit (lib.strings) hasPrefix;
|
||||||
in {
|
in {
|
||||||
options = with lib.types; {
|
options = with lib.types; {
|
||||||
enable = mkEnableOption "camera" // {
|
enable =
|
||||||
default = true;
|
mkEnableOption "camera"
|
||||||
};
|
// {
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
type = attrsOf (oneOf [str int bool]);
|
type = attrsOf (oneOf [str int bool]);
|
||||||
description = "https://motion-project.github.io/motion_config.html";
|
description = "https://motion-project.github.io/motion_config.html";
|
||||||
|
|
@ -45,125 +47,126 @@ let
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in {
|
in
|
||||||
pkgs,
|
{
|
||||||
config,
|
pkgs,
|
||||||
gensokyo-zone,
|
config,
|
||||||
utils,
|
gensokyo-zone,
|
||||||
lib,
|
utils,
|
||||||
...
|
lib,
|
||||||
}: let
|
...
|
||||||
inherit (lib.options) mkOption mkPackageOption mkEnableOption;
|
}: let
|
||||||
inherit (lib.modules) mkIf mkMerge mkAfter mkOptionDefault;
|
inherit (lib.options) mkOption mkPackageOption mkEnableOption;
|
||||||
inherit (lib.attrsets) attrValues mapAttrsToList;
|
inherit (lib.modules) mkIf mkMerge mkAfter mkOptionDefault;
|
||||||
inherit (lib.lists) filter;
|
inherit (lib.attrsets) attrValues mapAttrsToList;
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib.lists) filter;
|
||||||
cfg = config.services.motion;
|
inherit (lib.meta) getExe;
|
||||||
lib'motion = config.lib.motion;
|
cfg = config.services.motion;
|
||||||
in {
|
lib'motion = config.lib.motion;
|
||||||
options.services.motion = with lib.types; {
|
|
||||||
enable = mkEnableOption "motion";
|
|
||||||
package = mkPackageOption pkgs "motion" {};
|
|
||||||
cameras = mkOption {
|
|
||||||
type = attrsOf (submoduleWith {
|
|
||||||
modules = [ cameraModule ];
|
|
||||||
specialArgs = {
|
|
||||||
inherit pkgs gensokyo-zone lib'motion;
|
|
||||||
nixosConfig = config;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
dataDir = mkOption {
|
|
||||||
type = path;
|
|
||||||
default = "/var/lib/motion";
|
|
||||||
};
|
|
||||||
user = mkOption {
|
|
||||||
type = str;
|
|
||||||
default = "motion";
|
|
||||||
};
|
|
||||||
group = mkOption {
|
|
||||||
type = str;
|
|
||||||
default = "motion";
|
|
||||||
};
|
|
||||||
settings = mkOption {
|
|
||||||
type = attrsOf (oneOf [str int bool]);
|
|
||||||
description = "https://motion-project.github.io/motion_config.html";
|
|
||||||
};
|
|
||||||
extraArgs = mkOption {
|
|
||||||
type = listOf str;
|
|
||||||
default = [];
|
|
||||||
};
|
|
||||||
extraConfig = mkOption {
|
|
||||||
type = lines;
|
|
||||||
default = "";
|
|
||||||
};
|
|
||||||
configText = mkOption {
|
|
||||||
type = lines;
|
|
||||||
internal = true;
|
|
||||||
};
|
|
||||||
configFile = mkOption {
|
|
||||||
type = path;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
config.services.motion = let
|
|
||||||
configFile = pkgs.writeText "motion.conf" cfg.configText;
|
|
||||||
enableIPv6 = mkIf config.networking.enableIPv6 (mkOptionDefault true);
|
|
||||||
enabledCameras = filter (camera: camera.enable) (attrValues cfg.cameras);
|
|
||||||
in {
|
in {
|
||||||
settings = {
|
options.services.motion = with lib.types; {
|
||||||
target_dir = mkOptionDefault cfg.dataDir;
|
enable = mkEnableOption "motion";
|
||||||
ipv6_enabled = enableIPv6;
|
package = mkPackageOption pkgs "motion" {};
|
||||||
webcontrol_ipv6 = enableIPv6;
|
cameras = mkOption {
|
||||||
};
|
type = attrsOf (submoduleWith {
|
||||||
configFile = mkOptionDefault "${configFile}";
|
modules = [cameraModule];
|
||||||
configText = mkMerge (
|
specialArgs = {
|
||||||
(lib'motion.mkMotionSettings cfg.settings)
|
inherit pkgs gensokyo-zone lib'motion;
|
||||||
++ [cfg.extraConfig]
|
nixosConfig = config;
|
||||||
++ map (camera: mkAfter "camera ${camera.configFile}") enabledCameras
|
};
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
config.users = mkIf cfg.enable {
|
dataDir = mkOption {
|
||||||
users.motion = {
|
type = path;
|
||||||
uid = 916;
|
default = "/var/lib/motion";
|
||||||
group = "motion";
|
};
|
||||||
home = cfg.dataDir;
|
user = mkOption {
|
||||||
extraGroups = ["video"];
|
type = str;
|
||||||
};
|
default = "motion";
|
||||||
groups.motion = {
|
};
|
||||||
gid = config.users.users.motion.uid;
|
group = mkOption {
|
||||||
};
|
type = str;
|
||||||
};
|
default = "motion";
|
||||||
config.systemd.services.motion = let
|
};
|
||||||
cliArgs =
|
settings = mkOption {
|
||||||
[
|
type = attrsOf (oneOf [str int bool]);
|
||||||
(getExe cfg.package)
|
description = "https://motion-project.github.io/motion_config.html";
|
||||||
"-n"
|
};
|
||||||
"-c"
|
extraArgs = mkOption {
|
||||||
cfg.configFile
|
type = listOf str;
|
||||||
]
|
default = [];
|
||||||
++ cfg.extraArgs;
|
};
|
||||||
in
|
extraConfig = mkOption {
|
||||||
mkIf cfg.enable {
|
type = lines;
|
||||||
wantedBy = ["multi-user.target"];
|
default = "";
|
||||||
after = ["network.target"];
|
};
|
||||||
serviceConfig = {
|
configText = mkOption {
|
||||||
Type = mkOptionDefault "exec";
|
type = lines;
|
||||||
Restart = mkOptionDefault "on-failure";
|
internal = true;
|
||||||
User = mkOptionDefault cfg.user;
|
};
|
||||||
Group = mkOptionDefault cfg.group;
|
configFile = mkOption {
|
||||||
ExecStart = [
|
type = path;
|
||||||
(utils.escapeSystemdExecArgs cliArgs)
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config.lib.motion = {
|
config.services.motion = let
|
||||||
mkMotionValue = value:
|
configFile = pkgs.writeText "motion.conf" cfg.configText;
|
||||||
if value == true
|
enableIPv6 = mkIf config.networking.enableIPv6 (mkOptionDefault true);
|
||||||
then "on"
|
enabledCameras = filter (camera: camera.enable) (attrValues cfg.cameras);
|
||||||
else if value == false
|
in {
|
||||||
then "off"
|
settings = {
|
||||||
else toString value;
|
target_dir = mkOptionDefault cfg.dataDir;
|
||||||
mkMotionSetting = key: value: "${key} ${lib'motion.mkMotionValue value}";
|
ipv6_enabled = enableIPv6;
|
||||||
mkMotionSettings = mapAttrsToList lib'motion.mkMotionSetting;
|
webcontrol_ipv6 = enableIPv6;
|
||||||
};
|
};
|
||||||
}
|
configFile = mkOptionDefault "${configFile}";
|
||||||
|
configText = mkMerge (
|
||||||
|
(lib'motion.mkMotionSettings cfg.settings)
|
||||||
|
++ [cfg.extraConfig]
|
||||||
|
++ map (camera: mkAfter "camera ${camera.configFile}") enabledCameras
|
||||||
|
);
|
||||||
|
};
|
||||||
|
config.users = mkIf cfg.enable {
|
||||||
|
users.motion = {
|
||||||
|
uid = 916;
|
||||||
|
group = "motion";
|
||||||
|
home = cfg.dataDir;
|
||||||
|
extraGroups = ["video"];
|
||||||
|
};
|
||||||
|
groups.motion = {
|
||||||
|
gid = config.users.users.motion.uid;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config.systemd.services.motion = let
|
||||||
|
cliArgs =
|
||||||
|
[
|
||||||
|
(getExe cfg.package)
|
||||||
|
"-n"
|
||||||
|
"-c"
|
||||||
|
cfg.configFile
|
||||||
|
]
|
||||||
|
++ cfg.extraArgs;
|
||||||
|
in
|
||||||
|
mkIf cfg.enable {
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
after = ["network.target"];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = mkOptionDefault "exec";
|
||||||
|
Restart = mkOptionDefault "on-failure";
|
||||||
|
User = mkOptionDefault cfg.user;
|
||||||
|
Group = mkOptionDefault cfg.group;
|
||||||
|
ExecStart = [
|
||||||
|
(utils.escapeSystemdExecArgs cliArgs)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config.lib.motion = {
|
||||||
|
mkMotionValue = value:
|
||||||
|
if value == true
|
||||||
|
then "on"
|
||||||
|
else if value == false
|
||||||
|
then "off"
|
||||||
|
else toString value;
|
||||||
|
mkMotionSetting = key: value: "${key} ${lib'motion.mkMotionValue value}";
|
||||||
|
mkMotionSettings = mapAttrsToList lib'motion.mkMotionSetting;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,8 @@ in {
|
||||||
protocol = "http";
|
protocol = "http";
|
||||||
prometheus.exporter.enable = let
|
prometheus.exporter.enable = let
|
||||||
sslPort = config.ports.asterisk-ssl;
|
sslPort = config.ports.asterisk-ssl;
|
||||||
in mkAlmostOptionDefault (!sslPort.enable || !sslPort.prometheus.exporter.enable);
|
in
|
||||||
|
mkAlmostOptionDefault (!sslPort.enable || !sslPort.prometheus.exporter.enable);
|
||||||
};
|
};
|
||||||
asterisk-ssl = {
|
asterisk-ssl = {
|
||||||
port = mkAlmostOptionDefault 8089;
|
port = mkAlmostOptionDefault 8089;
|
||||||
|
|
|
||||||
|
|
@ -155,12 +155,16 @@ let
|
||||||
default = "/metrics";
|
default = "/metrics";
|
||||||
};
|
};
|
||||||
ssl = {
|
ssl = {
|
||||||
enable = mkEnableOption "HTTPS" // {
|
enable =
|
||||||
default = any (port: port.ssl) (attrValues exporterPorts);
|
mkEnableOption "HTTPS"
|
||||||
};
|
// {
|
||||||
insecure = mkEnableOption "self-signed SSL" // {
|
default = any (port: port.ssl) (attrValues exporterPorts);
|
||||||
default = true;
|
};
|
||||||
};
|
insecure =
|
||||||
|
mkEnableOption "self-signed SSL"
|
||||||
|
// {
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,21 @@ in {
|
||||||
serviceAttr = "motion";
|
serviceAttr = "motion";
|
||||||
assertions = let
|
assertions = let
|
||||||
# in motion.conf, `0` represents the port being disabled
|
# in motion.conf, `0` represents the port being disabled
|
||||||
configPort = port: if port.enable then port.port else 0;
|
configPort = port:
|
||||||
in mkIf config.enable [
|
if port.enable
|
||||||
(nixosConfig: {
|
then port.port
|
||||||
assertion = configPort config.ports.default == nixosConfig.services.motion.settings.webcontrol_port or 0;
|
else 0;
|
||||||
message = "webcontrol port mismatch";
|
in
|
||||||
})
|
mkIf config.enable [
|
||||||
(nixosConfig: {
|
(nixosConfig: {
|
||||||
assertion = configPort config.ports.stream == nixosConfig.services.motion.settings.stream_port or 0;
|
assertion = configPort config.ports.default == nixosConfig.services.motion.settings.webcontrol_port or 0;
|
||||||
message = "stream port mismatch";
|
message = "webcontrol port mismatch";
|
||||||
})
|
})
|
||||||
];
|
(nixosConfig: {
|
||||||
|
assertion = configPort config.ports.stream == nixosConfig.services.motion.settings.stream_port or 0;
|
||||||
|
message = "stream port mismatch";
|
||||||
|
})
|
||||||
|
];
|
||||||
};
|
};
|
||||||
defaults.port.listen = mkAlmostOptionDefault "lan";
|
defaults.port.listen = mkAlmostOptionDefault "lan";
|
||||||
ports = {
|
ports = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue