nixos/services.octoprint: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-24 22:05:51 +02:00
parent a99bf84530
commit d40cf96f75

View File

@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.octoprint; cfg = config.services.octoprint;
@ -13,7 +10,7 @@ let
webcam.ffmpeg = "${pkgs.ffmpeg.bin}/bin/ffmpeg"; webcam.ffmpeg = "${pkgs.ffmpeg.bin}/bin/ffmpeg";
}; };
fullConfig = recursiveUpdate cfg.extraConfig baseConfig; fullConfig = lib.recursiveUpdate cfg.extraConfig baseConfig;
cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON fullConfig); cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON fullConfig);
@ -29,58 +26,58 @@ in
services.octoprint = { services.octoprint = {
enable = mkEnableOption "OctoPrint, web interface for 3D printers"; enable = lib.mkEnableOption "OctoPrint, web interface for 3D printers";
host = mkOption { host = lib.mkOption {
type = types.str; type = lib.types.str;
default = "0.0.0.0"; default = "0.0.0.0";
description = '' description = ''
Host to bind OctoPrint to. Host to bind OctoPrint to.
''; '';
}; };
port = mkOption { port = lib.mkOption {
type = types.port; type = lib.types.port;
default = 5000; default = 5000;
description = '' description = ''
Port to bind OctoPrint to. Port to bind OctoPrint to.
''; '';
}; };
openFirewall = mkOption { openFirewall = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Open ports in the firewall for OctoPrint."; description = "Open ports in the firewall for OctoPrint.";
}; };
user = mkOption { user = lib.mkOption {
type = types.str; type = lib.types.str;
default = "octoprint"; default = "octoprint";
description = "User for the daemon."; description = "User for the daemon.";
}; };
group = mkOption { group = lib.mkOption {
type = types.str; type = lib.types.str;
default = "octoprint"; default = "octoprint";
description = "Group for the daemon."; description = "Group for the daemon.";
}; };
stateDir = mkOption { stateDir = lib.mkOption {
type = types.path; type = lib.types.path;
default = "/var/lib/octoprint"; default = "/var/lib/octoprint";
description = "State directory of the daemon."; description = "State directory of the daemon.";
}; };
plugins = mkOption { plugins = lib.mkOption {
type = types.functionTo (types.listOf types.package); type = lib.types.functionTo (lib.types.listOf lib.types.package);
default = plugins: [ ]; default = plugins: [ ];
defaultText = literalExpression "plugins: []"; defaultText = lib.literalExpression "plugins: []";
example = literalExpression "plugins: with plugins; [ themeify stlviewer ]"; example = lib.literalExpression "plugins: with plugins; [ themeify stlviewer ]";
description = "Additional plugins to be used. Available plugins are passed through the plugins input."; description = "Additional plugins to be used. Available plugins are passed through the plugins input.";
}; };
extraConfig = mkOption { extraConfig = lib.mkOption {
type = types.attrs; type = lib.types.attrs;
default = { }; default = { };
description = "Extra options which are added to OctoPrint's YAML configuration file."; description = "Extra options which are added to OctoPrint's YAML configuration file.";
}; };
@ -91,16 +88,16 @@ in
##### implementation ##### implementation
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
users.users = optionalAttrs (cfg.user == "octoprint") { users.users = lib.optionalAttrs (cfg.user == "octoprint") {
octoprint = { octoprint = {
group = cfg.group; group = cfg.group;
uid = config.ids.uids.octoprint; uid = config.ids.uids.octoprint;
}; };
}; };
users.groups = optionalAttrs (cfg.group == "octoprint") { users.groups = lib.optionalAttrs (cfg.group == "octoprint") {
octoprint.gid = config.ids.gids.octoprint; octoprint.gid = config.ids.gids.octoprint;
}; };
@ -137,6 +134,6 @@ in
}; };
}; };
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ]; networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
}; };
} }