1 { config, lib, pkgs, ... }:
7 cfg = config.services.octoprint;
10 plugins.curalegacy.cura_engine = "${pkgs.curaengine_stable}/bin/CuraEngine";
11 server.host = cfg.host;
12 server.port = cfg.port;
13 webcam.ffmpeg = "${pkgs.ffmpeg.bin}/bin/ffmpeg";
16 fullConfig = recursiveUpdate cfg.extraConfig baseConfig;
18 cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON fullConfig);
20 pluginsEnv = package.python.withPackages (ps: [ps.octoprint] ++ (cfg.plugins ps));
22 package = pkgs.octoprint;
30 services.octoprint = {
32 enable = mkEnableOption (lib.mdDoc "OctoPrint, web interface for 3D printers");
37 description = lib.mdDoc ''
38 Host to bind OctoPrint to.
45 description = lib.mdDoc ''
46 Port to bind OctoPrint to.
52 default = "octoprint";
53 description = lib.mdDoc "User for the daemon.";
58 default = "octoprint";
59 description = lib.mdDoc "Group for the daemon.";
64 default = "/var/lib/octoprint";
65 description = lib.mdDoc "State directory of the daemon.";
69 type = types.functionTo (types.listOf types.package);
70 default = plugins: [];
71 defaultText = literalExpression "plugins: []";
72 example = literalExpression "plugins: with plugins; [ themeify stlviewer ]";
73 description = lib.mdDoc "Additional plugins to be used. Available plugins are passed through the plugins input.";
76 extraConfig = mkOption {
79 description = lib.mdDoc "Extra options which are added to OctoPrint's YAML configuration file.";
88 config = mkIf cfg.enable {
90 users.users = optionalAttrs (cfg.user == "octoprint") {
93 uid = config.ids.uids.octoprint;
97 users.groups = optionalAttrs (cfg.group == "octoprint") {
98 octoprint.gid = config.ids.gids.octoprint;
101 systemd.tmpfiles.rules = [
102 "d '${cfg.stateDir}' - ${cfg.user} ${cfg.group} - -"
105 systemd.services.octoprint = {
106 description = "OctoPrint, web interface for 3D printers";
107 wantedBy = [ "multi-user.target" ];
108 after = [ "network.target" ];
109 path = [ pluginsEnv ];
112 if [ -e "${cfg.stateDir}/config.yaml" ]; then
113 ${pkgs.yaml-merge}/bin/yaml-merge "${cfg.stateDir}/config.yaml" "${cfgUpdate}" > "${cfg.stateDir}/config.yaml.tmp"
114 mv "${cfg.stateDir}/config.yaml.tmp" "${cfg.stateDir}/config.yaml"
116 cp "${cfgUpdate}" "${cfg.stateDir}/config.yaml"
117 chmod 600 "${cfg.stateDir}/config.yaml"
122 ExecStart = "${pluginsEnv}/bin/octoprint serve -b ${cfg.stateDir}";
125 SupplementaryGroups = [