2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.octoprint;
|
|
|
|
|
|
|
|
baseConfig = {
|
|
|
|
plugins.curalegacy.cura_engine = "${pkgs.curaengine_stable}/bin/CuraEngine";
|
|
|
|
server.host = cfg.host;
|
|
|
|
server.port = cfg.port;
|
|
|
|
webcam.ffmpeg = "${pkgs.ffmpeg.bin}/bin/ffmpeg";
|
|
|
|
};
|
|
|
|
|
|
|
|
fullConfig = recursiveUpdate cfg.extraConfig baseConfig;
|
|
|
|
|
|
|
|
cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON fullConfig);
|
|
|
|
|
2020-05-03 17:38:23 +00:00
|
|
|
pluginsEnv = package.python.withPackages (ps: [ps.octoprint] ++ (cfg.plugins ps));
|
|
|
|
|
|
|
|
package = pkgs.octoprint;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
##### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.octoprint = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "OctoPrint, web interface for 3D printers";
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Host to bind OctoPrint to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-07-14 22:03:04 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 5000;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Port to bind OctoPrint to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "octoprint";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User for the daemon.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "octoprint";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Group for the daemon.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/octoprint";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "State directory of the daemon.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.functionTo (types.listOf types.package);
|
2020-04-24 23:36:52 +00:00
|
|
|
default = plugins: [];
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "plugins: []";
|
|
|
|
example = literalExpression "plugins: with plugins; [ themeify stlviewer ]";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Additional plugins to be used. Available plugins are passed through the plugins input.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra options which are added to OctoPrint's YAML configuration file.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
##### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.users = optionalAttrs (cfg.user == "octoprint") {
|
|
|
|
octoprint = {
|
|
|
|
group = cfg.group;
|
|
|
|
uid = config.ids.uids.octoprint;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups = optionalAttrs (cfg.group == "octoprint") {
|
|
|
|
octoprint.gid = config.ids.gids.octoprint;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.stateDir}' - ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.octoprint = {
|
|
|
|
description = "OctoPrint, web interface for 3D printers";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
path = [ pluginsEnv ];
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
if [ -e "${cfg.stateDir}/config.yaml" ]; then
|
|
|
|
${pkgs.yaml-merge}/bin/yaml-merge "${cfg.stateDir}/config.yaml" "${cfgUpdate}" > "${cfg.stateDir}/config.yaml.tmp"
|
|
|
|
mv "${cfg.stateDir}/config.yaml.tmp" "${cfg.stateDir}/config.yaml"
|
|
|
|
else
|
|
|
|
cp "${cfgUpdate}" "${cfg.stateDir}/config.yaml"
|
|
|
|
chmod 600 "${cfg.stateDir}/config.yaml"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
2020-05-03 17:38:23 +00:00
|
|
|
ExecStart = "${pluginsEnv}/bin/octoprint serve -b ${cfg.stateDir}";
|
2020-04-24 23:36:52 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2021-08-27 14:25:00 +00:00
|
|
|
SupplementaryGroups = [
|
|
|
|
"dialout"
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|