]> git.scottworley.com Git - syncthing-autoregister/blobdiff - modules/syncthing-autoregister.nix
Syncthing device-id autoregistration
[syncthing-autoregister] / modules / syncthing-autoregister.nix
diff --git a/modules/syncthing-autoregister.nix b/modules/syncthing-autoregister.nix
new file mode 100644 (file)
index 0000000..d1f0a7c
--- /dev/null
@@ -0,0 +1,22 @@
+{ config, lib, pkgs, ... }:
+let
+  localpkgs = import ../. { inherit pkgs; };
+  register-script = pkgs.writeShellScript "syncthing-autoregister-script" ''
+    ${localpkgs.syncthing-set-id}/bin/syncthing-set-id /tmp/syncthing-auto-register-test-device-ids.nix
+  '';
+in {
+  config = {
+    systemd.services.syncthing-autoregister = {
+      after = [ "syncthing.service" "syncthing-init.service" ];
+      wantedBy = [ "multi-user.target" ];
+      environment.NIX_PATH = config.environment.variables.NIX_PATH;
+      serviceConfig = {
+        User = config.services.syncthing.user;
+        RemainAfterExit = true;
+        Type = "oneshot";
+        ExecStart = register-script;
+      };
+    };
+  };
+}
+