From 7fb0951bc9caf6bd5cf71439638beea3499a0acc Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Mon, 27 Jul 2020 13:58:29 -0700 Subject: [PATCH] Enable option for auto-registration --- modules/syncthing-autoregister.nix | 11 ++++++++++- tests/automatic-enrollment.nix | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/syncthing-autoregister.nix b/modules/syncthing-autoregister.nix index d1f0a7c..158cd52 100644 --- a/modules/syncthing-autoregister.nix +++ b/modules/syncthing-autoregister.nix @@ -1,11 +1,20 @@ { 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 ''; in { - config = { + options = { + services.syncthing.autoRegister = { + enable = mkEnableOption '' + Automatically write the local syncthing device id to /tmp/syncthing-auto-register-test-device-ids.nix + ''; + }; + }; + config = mkIf cfg.enable { systemd.services.syncthing-autoregister = { after = [ "syncthing.service" "syncthing-init.service" ]; wantedBy = [ "multi-user.target" ]; diff --git a/tests/automatic-enrollment.nix b/tests/automatic-enrollment.nix index cac1b28..9577510 100644 --- a/tests/automatic-enrollment.nix +++ b/tests/automatic-enrollment.nix @@ -9,6 +9,9 @@ import ({ pkgs, lib, ... }: services.syncthing = { enable = true; openDefaultPorts = true; + autoRegister = { + enable = true; + }; }; environment.systemPackages = with pkgs; [ nix ]; } -- 2.44.1