2016-02-14 12:58:09 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.octoprint;
|
|
|
|
|
2016-03-12 15:52:09 +01:00
|
|
|
baseConfig = {
|
2017-02-25 23:05:04 +01:00
|
|
|
plugins.cura.cura_engine = "${pkgs.curaengine_stable}/bin/CuraEngine";
|
2016-02-14 12:58:09 +01:00
|
|
|
server.host = cfg.host;
|
|
|
|
server.port = cfg.port;
|
2016-04-10 21:50:31 +02:00
|
|
|
webcam.ffmpeg = "${pkgs.ffmpeg.bin}/bin/ffmpeg";
|
2016-03-12 15:52:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
fullConfig = recursiveUpdate cfg.extraConfig baseConfig;
|
|
|
|
|
|
|
|
cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON fullConfig);
|
2016-02-14 12:58:09 +01:00
|
|
|
|
|
|
|
pluginsEnv = pkgs.python.buildEnv.override {
|
|
|
|
extraLibs = cfg.plugins pkgs.octoprint-plugins;
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
##### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.octoprint = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "OctoPrint, web interface for 3D printers";
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
description = ''
|
|
|
|
Host to bind OctoPrint to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5000;
|
|
|
|
description = ''
|
|
|
|
Port to bind OctoPrint to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "octoprint";
|
|
|
|
description = "User for the daemon.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "octoprint";
|
|
|
|
description = "Group for the daemon.";
|
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/octoprint";
|
|
|
|
description = "State directory of the daemon.";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
default = plugins: [];
|
2016-02-29 01:47:12 +01:00
|
|
|
defaultText = "plugins: []";
|
2016-02-14 12:58:09 +01:00
|
|
|
example = literalExample "plugins: [ m3d-fio ]";
|
|
|
|
description = "Additional plugins.";
|
|
|
|
};
|
|
|
|
|
2016-03-12 15:52:09 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = "Extra options which are added to OctoPrint's YAML configuration file.";
|
|
|
|
};
|
|
|
|
|
2016-02-14 12:58:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
##### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.extraUsers = optionalAttrs (cfg.user == "octoprint") (singleton
|
|
|
|
{ name = "octoprint";
|
|
|
|
group = cfg.group;
|
|
|
|
uid = config.ids.uids.octoprint;
|
|
|
|
});
|
|
|
|
|
|
|
|
users.extraGroups = optionalAttrs (cfg.group == "octoprint") (singleton
|
|
|
|
{ name = "octoprint";
|
|
|
|
gid = config.ids.gids.octoprint;
|
|
|
|
});
|
|
|
|
|
|
|
|
systemd.services.octoprint = {
|
|
|
|
description = "OctoPrint, web interface for 3D printers";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
path = [ pluginsEnv ];
|
2016-04-20 16:41:36 +02:00
|
|
|
environment.PYTHONPATH = makeSearchPathOutput "lib" pkgs.python.sitePackages [ pluginsEnv ];
|
2016-02-14 12:58:09 +01:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p "${cfg.stateDir}"
|
|
|
|
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
|
|
|
|
chown -R ${cfg.user}:${cfg.group} "${cfg.stateDir}"
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
2017-03-21 15:31:08 +01:00
|
|
|
ExecStart = "${pkgs.octoprint}/bin/octoprint serve -b ${cfg.stateDir}";
|
2016-02-14 12:58:09 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|