lol

octoprint service: init

+121
+2
nixos/modules/misc/ids.nix
··· 251 251 cfdyndns = 227; 252 252 gammu-smsd = 228; 253 253 pdnsd = 229; 254 + octoprint = 230; 254 255 255 256 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! 256 257 ··· 478 479 rmilter = 226; 479 480 cfdyndns = 227; 480 481 pdnsd = 229; 482 + octoprint = 230; 481 483 482 484 # When adding a gid, make sure it doesn't match an existing 483 485 # uid. Users and groups with the same name should have equal
+1
nixos/modules/module-list.nix
··· 229 229 ./services/misc/nix-gc.nix 230 230 ./services/misc/nixos-manual.nix 231 231 ./services/misc/nix-ssh-serve.nix 232 + ./services/misc/octoprint.nix 232 233 ./services/misc/parsoid.nix 233 234 ./services/misc/phd.nix 234 235 ./services/misc/plex.nix
+118
nixos/modules/services/misc/octoprint.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + 7 + cfg = config.services.octoprint; 8 + 9 + cfgUpdate = pkgs.writeText "octoprint-config.yaml" (builtins.toJSON { 10 + plugins.cura.cura_engine = "${pkgs.curaengine}/bin/CuraEngine"; 11 + server.host = cfg.host; 12 + server.port = cfg.port; 13 + webcam.ffmpeg = "${pkgs.ffmpeg}/bin/ffmpeg"; 14 + }); 15 + 16 + pluginsEnv = pkgs.python.buildEnv.override { 17 + extraLibs = cfg.plugins pkgs.octoprint-plugins; 18 + }; 19 + 20 + in 21 + { 22 + ##### interface 23 + 24 + options = { 25 + 26 + services.octoprint = { 27 + 28 + enable = mkEnableOption "OctoPrint, web interface for 3D printers"; 29 + 30 + host = mkOption { 31 + type = types.str; 32 + default = "0.0.0.0"; 33 + description = '' 34 + Host to bind OctoPrint to. 35 + ''; 36 + }; 37 + 38 + port = mkOption { 39 + type = types.int; 40 + default = 5000; 41 + description = '' 42 + Port to bind OctoPrint to. 43 + ''; 44 + }; 45 + 46 + user = mkOption { 47 + type = types.str; 48 + default = "octoprint"; 49 + description = "User for the daemon."; 50 + }; 51 + 52 + group = mkOption { 53 + type = types.str; 54 + default = "octoprint"; 55 + description = "Group for the daemon."; 56 + }; 57 + 58 + stateDir = mkOption { 59 + type = types.path; 60 + default = "/var/lib/octoprint"; 61 + description = "State directory of the daemon."; 62 + }; 63 + 64 + plugins = mkOption { 65 + default = plugins: []; 66 + example = literalExample "plugins: [ m3d-fio ]"; 67 + description = "Additional plugins."; 68 + }; 69 + 70 + }; 71 + 72 + }; 73 + 74 + ##### implementation 75 + 76 + config = mkIf cfg.enable { 77 + 78 + users.extraUsers = optionalAttrs (cfg.user == "octoprint") (singleton 79 + { name = "octoprint"; 80 + group = cfg.group; 81 + uid = config.ids.uids.octoprint; 82 + }); 83 + 84 + users.extraGroups = optionalAttrs (cfg.group == "octoprint") (singleton 85 + { name = "octoprint"; 86 + gid = config.ids.gids.octoprint; 87 + }); 88 + 89 + systemd.services.octoprint = { 90 + description = "OctoPrint, web interface for 3D printers"; 91 + wantedBy = [ "multi-user.target" ]; 92 + after = [ "network.target" ]; 93 + path = [ pluginsEnv ]; 94 + environment.PYTHONPATH = makeSearchPath pkgs.python.sitePackages [ pluginsEnv ]; 95 + 96 + preStart = '' 97 + mkdir -p "${cfg.stateDir}" 98 + if [ -e "${cfg.stateDir}/config.yaml" ]; then 99 + ${pkgs.yaml-merge}/bin/yaml-merge "${cfg.stateDir}/config.yaml" "${cfgUpdate}" > "${cfg.stateDir}/config.yaml.tmp" 100 + mv "${cfg.stateDir}/config.yaml.tmp" "${cfg.stateDir}/config.yaml" 101 + else 102 + cp "${cfgUpdate}" "${cfg.stateDir}/config.yaml" 103 + chmod 600 "${cfg.stateDir}/config.yaml" 104 + fi 105 + chown -R ${cfg.user}:${cfg.group} "${cfg.stateDir}" 106 + ''; 107 + 108 + serviceConfig = { 109 + ExecStart = "${pkgs.octoprint}/bin/octoprint -b ${cfg.stateDir}"; 110 + User = cfg.user; 111 + Group = cfg.group; 112 + PermissionsStartOnly = true; 113 + }; 114 + }; 115 + 116 + }; 117 + 118 + }