diff --git a/modules/nixos/motion.nix b/modules/nixos/motion.nix index 7af6caa7..28832dcc 100644 --- a/modules/nixos/motion.nix +++ b/modules/nixos/motion.nix @@ -13,9 +13,11 @@ let inherit (lib.strings) hasPrefix; in { options = with lib.types; { - enable = mkEnableOption "camera" // { - default = true; - }; + enable = + mkEnableOption "camera" + // { + default = true; + }; settings = mkOption { type = attrsOf (oneOf [str int bool]); description = "https://motion-project.github.io/motion_config.html"; @@ -45,125 +47,126 @@ let ); }; }; -in { - pkgs, - config, - gensokyo-zone, - utils, - lib, - ... -}: let - inherit (lib.options) mkOption mkPackageOption mkEnableOption; - inherit (lib.modules) mkIf mkMerge mkAfter mkOptionDefault; - inherit (lib.attrsets) attrValues mapAttrsToList; - inherit (lib.lists) filter; - inherit (lib.meta) getExe; - cfg = config.services.motion; - lib'motion = config.lib.motion; -in { - 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 + { + pkgs, + config, + gensokyo-zone, + utils, + lib, + ... + }: let + inherit (lib.options) mkOption mkPackageOption mkEnableOption; + inherit (lib.modules) mkIf mkMerge mkAfter mkOptionDefault; + inherit (lib.attrsets) attrValues mapAttrsToList; + inherit (lib.lists) filter; + inherit (lib.meta) getExe; + cfg = config.services.motion; + lib'motion = config.lib.motion; in { - settings = { - target_dir = mkOptionDefault cfg.dataDir; - ipv6_enabled = enableIPv6; - 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) - ]; + 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.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; - }; -} + 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 { + settings = { + target_dir = mkOptionDefault cfg.dataDir; + ipv6_enabled = enableIPv6; + 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; + }; + } diff --git a/modules/system/exports/freepbx.nix b/modules/system/exports/freepbx.nix index 01c41bd4..fd34af34 100644 --- a/modules/system/exports/freepbx.nix +++ b/modules/system/exports/freepbx.nix @@ -47,7 +47,8 @@ in { protocol = "http"; prometheus.exporter.enable = let sslPort = config.ports.asterisk-ssl; - in mkAlmostOptionDefault (!sslPort.enable || !sslPort.prometheus.exporter.enable); + in + mkAlmostOptionDefault (!sslPort.enable || !sslPort.prometheus.exporter.enable); }; asterisk-ssl = { port = mkAlmostOptionDefault 8089; diff --git a/modules/system/exports/monitoring.nix b/modules/system/exports/monitoring.nix index 902a2af6..9386b938 100644 --- a/modules/system/exports/monitoring.nix +++ b/modules/system/exports/monitoring.nix @@ -155,12 +155,16 @@ let default = "/metrics"; }; ssl = { - enable = mkEnableOption "HTTPS" // { - default = any (port: port.ssl) (attrValues exporterPorts); - }; - insecure = mkEnableOption "self-signed SSL" // { - default = true; - }; + enable = + mkEnableOption "HTTPS" + // { + default = any (port: port.ssl) (attrValues exporterPorts); + }; + insecure = + mkEnableOption "self-signed SSL" + // { + default = true; + }; }; }; }; diff --git a/modules/system/exports/motion.nix b/modules/system/exports/motion.nix index 2fc71159..7e0bf946 100644 --- a/modules/system/exports/motion.nix +++ b/modules/system/exports/motion.nix @@ -12,17 +12,21 @@ in { serviceAttr = "motion"; assertions = let # in motion.conf, `0` represents the port being disabled - configPort = port: if port.enable then port.port else 0; - in mkIf config.enable [ - (nixosConfig: { - assertion = configPort config.ports.default == nixosConfig.services.motion.settings.webcontrol_port or 0; - message = "webcontrol port mismatch"; - }) - (nixosConfig: { - assertion = configPort config.ports.stream == nixosConfig.services.motion.settings.stream_port or 0; - message = "stream port mismatch"; - }) - ]; + configPort = port: + if port.enable + then port.port + else 0; + in + mkIf config.enable [ + (nixosConfig: { + assertion = configPort config.ports.default == nixosConfig.services.motion.settings.webcontrol_port or 0; + 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"; ports = {