1 { config, lib, pkgs, ... }:
4 cfg = config.services.octoprint;
7 plugins.curalegacy.cura_engine = "${pkgs.curaengine_stable}/bin/CuraEngine";
8 server.host = cfg.host;
9 server.port = cfg.port;
10 webcam.ffmpeg = "${pkgs.ffmpeg.bin}/bin/ffmpeg";
13 fullConfig = lib.recursiveUpdate cfg.extraConfig baseConfig;
15 cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON fullConfig);
17 pluginsEnv = package.python.withPackages (ps: [ ps.octoprint ] ++ (cfg.plugins ps));
19 package = pkgs.octoprint;
27 services.octoprint = {
29 enable = lib.mkEnableOption "OctoPrint, web interface for 3D printers";
35 Host to bind OctoPrint to.
40 type = lib.types.port;
43 Port to bind OctoPrint to.
47 openFirewall = lib.mkOption {
48 type = lib.types.bool;
50 description = "Open ports in the firewall for OctoPrint.";
55 default = "octoprint";
56 description = "User for the daemon.";
59 group = lib.mkOption {
61 default = "octoprint";
62 description = "Group for the daemon.";
65 stateDir = lib.mkOption {
66 type = lib.types.path;
67 default = "/var/lib/octoprint";
68 description = "State directory of the daemon.";
71 plugins = lib.mkOption {
72 type = lib.types.functionTo (lib.types.listOf lib.types.package);
73 default = plugins: [ ];
74 defaultText = lib.literalExpression "plugins: []";
75 example = lib.literalExpression "plugins: with plugins; [ themeify stlviewer ]";
76 description = "Additional plugins to be used. Available plugins are passed through the plugins input.";
79 extraConfig = lib.mkOption {
80 type = lib.types.attrs;
82 description = "Extra options which are added to OctoPrint's YAML configuration file.";
91 config = lib.mkIf cfg.enable {
93 users.users = lib.optionalAttrs (cfg.user == "octoprint") {
96 uid = config.ids.uids.octoprint;
100 users.groups = lib.optionalAttrs (cfg.group == "octoprint") {
101 octoprint.gid = config.ids.gids.octoprint;
104 systemd.tmpfiles.rules = [
105 "d '${cfg.stateDir}' - ${cfg.user} ${cfg.group} - -"
106 # this will allow octoprint access to raspberry specific hardware to check for throttling
107 # read-only will not work: "VCHI initialization failed" error
108 "a /dev/vchiq - - - - u:octoprint:rw"
111 systemd.services.octoprint = {
112 description = "OctoPrint, web interface for 3D printers";
113 wantedBy = [ "multi-user.target" ];
114 after = [ "network.target" ];
115 path = [ pluginsEnv ];
118 if [ -e "${cfg.stateDir}/config.yaml" ]; then
119 ${pkgs.yaml-merge}/bin/yaml-merge "${cfg.stateDir}/config.yaml" "${cfgUpdate}" > "${cfg.stateDir}/config.yaml.tmp"
120 mv "${cfg.stateDir}/config.yaml.tmp" "${cfg.stateDir}/config.yaml"
122 cp "${cfgUpdate}" "${cfg.stateDir}/config.yaml"
123 chmod 600 "${cfg.stateDir}/config.yaml"
128 ExecStart = "${pluginsEnv}/bin/octoprint serve -b ${cfg.stateDir}";
131 SupplementaryGroups = [
137 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];