2016-02-14 11:58:09 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.octoprint;
|
|
|
|
|
2016-03-12 14:52:09 +00:00
|
|
|
baseConfig = {
|
2019-05-30 13:28:25 +00:00
|
|
|
plugins.curalegacy.cura_engine = "${pkgs.curaengine_stable}/bin/CuraEngine";
|
2016-02-14 11:58:09 +00:00
|
|
|
server.host = cfg.host;
|
|
|
|
server.port = cfg.port;
|
2016-04-10 19:50:31 +00:00
|
|
|
webcam.ffmpeg = "${pkgs.ffmpeg.bin}/bin/ffmpeg";
|
2016-03-12 14:52:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
fullConfig = recursiveUpdate cfg.extraConfig baseConfig;
|
|
|
|
|
|
|
|
cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON fullConfig);
|
2016-02-14 11:58:09 +00:00
|
|
|
|
2022-11-13 17:14:02 +00:00
|
|
|
pluginsEnv = package.python.withPackages (ps: [ ps.octoprint ] ++ (cfg.plugins ps));
|
2020-03-14 10:02:07 +00:00
|
|
|
|
|
|
|
package = pkgs.octoprint;
|
2016-02-14 11:58:09 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
##### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.octoprint = {
|
|
|
|
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "OctoPrint, web interface for 3D printers";
|
2016-02-14 11:58:09 +00:00
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2016-02-14 11:58:09 +00:00
|
|
|
Host to bind OctoPrint to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-06-18 15:27:16 +00:00
|
|
|
type = types.port;
|
2016-02-14 11:58:09 +00:00
|
|
|
default = 5000;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2016-02-14 11:58:09 +00:00
|
|
|
Port to bind OctoPrint to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-11-13 17:14:02 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Open ports in the firewall for OctoPrint.";
|
2022-11-13 17:14:02 +00:00
|
|
|
};
|
|
|
|
|
2016-02-14 11:58:09 +00:00
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "octoprint";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "User for the daemon.";
|
2016-02-14 11:58:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "octoprint";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Group for the daemon.";
|
2016-02-14 11:58:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/octoprint";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "State directory of the daemon.";
|
2016-02-14 11:58:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
2018-08-07 16:53:56 +00:00
|
|
|
type = types.functionTo (types.listOf types.package);
|
2022-11-13 17:14:02 +00:00
|
|
|
default = plugins: [ ];
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "plugins: []";
|
|
|
|
example = literalExpression "plugins: with plugins; [ themeify stlviewer ]";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Additional plugins to be used. Available plugins are passed through the plugins input.";
|
2016-02-14 11:58:09 +00:00
|
|
|
};
|
|
|
|
|
2016-03-12 14:52:09 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrs;
|
2022-11-13 17:14:02 +00:00
|
|
|
default = { };
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Extra options which are added to OctoPrint's YAML configuration file.";
|
2016-03-12 14:52:09 +00:00
|
|
|
};
|
|
|
|
|
2016-02-14 11:58:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
##### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users = optionalAttrs (cfg.user == "octoprint") {
|
|
|
|
octoprint = {
|
2016-02-14 11:58:09 +00:00
|
|
|
group = cfg.group;
|
|
|
|
uid = config.ids.uids.octoprint;
|
2019-09-14 17:51:29 +00:00
|
|
|
};
|
|
|
|
};
|
2016-02-14 11:58:09 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups = optionalAttrs (cfg.group == "octoprint") {
|
|
|
|
octoprint.gid = config.ids.gids.octoprint;
|
|
|
|
};
|
2016-02-14 11:58:09 +00:00
|
|
|
|
2019-02-24 14:08:21 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.stateDir}' - ${cfg.user} ${cfg.group} - -"
|
2023-01-29 08:11:48 +00:00
|
|
|
# this will allow octoprint access to raspberry specific hardware to check for throttling
|
|
|
|
# read-only will not work: "VCHI initialization failed" error
|
|
|
|
"a /dev/vchiq - - - - u:octoprint:rw"
|
2019-02-24 14:08:21 +00:00
|
|
|
];
|
|
|
|
|
2016-02-14 11:58:09 +00:00
|
|
|
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-03-14 10:02:07 +00:00
|
|
|
ExecStart = "${pluginsEnv}/bin/octoprint serve -b ${cfg.stateDir}";
|
2016-02-14 11:58:09 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2021-08-24 01:00:39 +00:00
|
|
|
SupplementaryGroups = [
|
|
|
|
"dialout"
|
|
|
|
];
|
2016-02-14 11:58:09 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-11-13 17:14:02 +00:00
|
|
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
|
2016-02-14 11:58:09 +00:00
|
|
|
};
|
|
|
|
}
|