]> git.scottworley.com Git - syncthing-autoregister/commitdiff
Option for file to write into
authorScott Worley <scottworley@scottworley.com>
Mon, 27 Jul 2020 21:13:02 +0000 (14:13 -0700)
committerScott Worley <scottworley@scottworley.com>
Mon, 27 Jul 2020 21:13:02 +0000 (14:13 -0700)
modules/syncthing-autoregister.nix

index 158cd520f5c2d787c6168fa0990fc2f1c5d657b2..6276352f67b558773e4349017f694e151e0aa20d 100644 (file)
@@ -4,14 +4,34 @@ let
   cfg = config.services.syncthing.autoRegister;
   localpkgs = import ../. { inherit pkgs; };
   register-script = pkgs.writeShellScript "syncthing-autoregister-script" ''
   cfg = config.services.syncthing.autoRegister;
   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
+    ${localpkgs.syncthing-set-id}/bin/syncthing-set-id ${
+      escapeShellArg cfg.path
+    }
   '';
 in {
   options = {
     services.syncthing.autoRegister = {
       enable = mkEnableOption ''
   '';
 in {
   options = {
     services.syncthing.autoRegister = {
       enable = mkEnableOption ''
-        Automatically write the local syncthing device id to /tmp/syncthing-auto-register-test-device-ids.nix
+        Automatically write the local syncthing device id to the nix module
+        file <option>services.syncthing.autoRegister.path</option>.
       '';
       '';
+      path = mkOption {
+        type = types.path;
+        default = "/tmp/syncthing-auto-register-test-device-ids.nix";
+        description = ''
+          Path of nix module file to write our syncthing
+          device id into.  It will be written into
+          services.syncthing.declarative.devices.<hostname>.id.  This file
+          can be imported as a NixOS module.
+
+          We recommend using a separate file just for this purpose.  I.e.,
+          don't point this at your main NixOS config.  Instead, import this
+          file from your main NixOS config.  (The current nix-configuration
+          read-modify-write implementation only supports attrsets of strings;
+          it does not support functions, which you probably use in your
+          main configuration.)
+        '';
+      };
     };
   };
   config = mkIf cfg.enable {
     };
   };
   config = mkIf cfg.enable {