about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorZhaofeng Li <hello@zhaofeng.li>2021-07-18 21:34:45 -0700
committerZhaofeng Li <hello@zhaofeng.li>2021-07-19 02:30:25 -0700
commit94536fd6e33afaedab5ddfc36831cfc1c5b87508 (patch)
tree5a5035ba26872000498f9769e971d8e212c38658 /nixos
parent942d45f74e994725c27d085a30c25d6615780bdc (diff)
downloadnixlib-94536fd6e33afaedab5ddfc36831cfc1c5b87508.tar
nixlib-94536fd6e33afaedab5ddfc36831cfc1c5b87508.tar.gz
nixlib-94536fd6e33afaedab5ddfc36831cfc1c5b87508.tar.bz2
nixlib-94536fd6e33afaedab5ddfc36831cfc1c5b87508.tar.lz
nixlib-94536fd6e33afaedab5ddfc36831cfc1c5b87508.tar.xz
nixlib-94536fd6e33afaedab5ddfc36831cfc1c5b87508.tar.zst
nixlib-94536fd6e33afaedab5ddfc36831cfc1c5b87508.zip
nixos/klipper: Allow specifying arbitrary user/group
This paves the way for alternative integrations such as
Moonraker.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/misc/klipper.nix45
1 files changed, 38 insertions, 7 deletions
diff --git a/nixos/modules/services/misc/klipper.nix b/nixos/modules/services/misc/klipper.nix
index 2f04c011a650..df5b527a069a 100644
--- a/nixos/modules/services/misc/klipper.nix
+++ b/nixos/modules/services/misc/klipper.nix
@@ -17,6 +17,26 @@ in
         description = "Allows Octoprint to control Klipper.";
       };
 
+      user = mkOption {
+        type = types.nullOr types.str;
+        default = null;
+        description = ''
+          User account under which Klipper runs.
+
+          If null is specified (default), a temporary user will be created by systemd.
+        '';
+      };
+
+      group = mkOption {
+        type = types.nullOr types.str;
+        default = null;
+        description = ''
+          Group account under which Klipper runs.
+
+          If null is specified (default), a temporary user will be created by systemd.
+        '';
+      };
+
       settings = mkOption {
         type = format.type;
         default = { };
@@ -30,13 +50,24 @@ in
 
   ##### implementation
   config = mkIf cfg.enable {
-    assertions = [{
-      assertion = cfg.octoprintIntegration -> config.services.octoprint.enable;
-      message = "Option klipper.octoprintIntegration requires Octoprint to be enabled on this system. Please enable services.octoprint to use it.";
-    }];
+    assertions = [
+      {
+        assertion = cfg.octoprintIntegration -> config.services.octoprint.enable;
+        message = "Option klipper.octoprintIntegration requires Octoprint to be enabled on this system. Please enable services.octoprint to use it.";
+      }
+      {
+        assertion = cfg.user != null -> cfg.group != null;
+        message = "Option klipper.group is not set when a user is specified.";
+      }
+    ];
 
     environment.etc."klipper.cfg".source = format.generate "klipper.cfg" cfg.settings;
 
+    services.klipper = mkIf cfg.octoprintIntegration {
+      user = config.services.octoprint.user;
+      group = config.services.octoprint.group;
+    };
+
     systemd.services.klipper = {
       description = "Klipper 3D Printer Firmware";
       wantedBy = [ "multi-user.target" ];
@@ -47,9 +78,9 @@ in
         RuntimeDirectory = "klipper";
         SupplementaryGroups = [ "dialout" ];
         WorkingDirectory = "${package}/lib";
-      } // (if cfg.octoprintIntegration then {
-        Group = config.services.octoprint.group;
-        User = config.services.octoprint.user;
+      } // (if cfg.user != null then {
+        Group = cfg.group;
+        User = cfg.user;
       } else {
         DynamicUser = true;
         User = "klipper";