X-Git-Url: http://git.scottworley.com/syncthing-autoregister/blobdiff_plain/b00b144bd77fdaca30cb490e78e06e41617a79ad..36008f17427b61f0b86143a260f748a534688ae8:/modules/syncthing-autoregister.nix?ds=sidebyside diff --git a/modules/syncthing-autoregister.nix b/modules/syncthing-autoregister.nix index d1f0a7c..da9df86 100644 --- a/modules/syncthing-autoregister.nix +++ b/modules/syncthing-autoregister.nix @@ -1,11 +1,39 @@ { config, lib, pkgs, ... }: +with lib; let + 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 { - config = { + options = { + services.syncthing.autoRegister = { + enable = mkEnableOption '' + Automatically write the local syncthing device id to the nix module + file . + ''; + path = mkOption { + type = types.path; + description = '' + Path of nix module file to write our syncthing + device id into. It will be written into + services.syncthing.declarative.devices..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 { systemd.services.syncthing-autoregister = { after = [ "syncthing.service" "syncthing-init.service" ]; wantedBy = [ "multi-user.target" ];