]> git.scottworley.com Git - syncthing-autoregister/blob - modules/syncthing-autoregister.nix
158cd520f5c2d787c6168fa0990fc2f1c5d657b2
[syncthing-autoregister] / modules / syncthing-autoregister.nix
1 { config, lib, pkgs, ... }:
2 with lib;
3 let
4 cfg = config.services.syncthing.autoRegister;
5 localpkgs = import ../. { inherit pkgs; };
6 register-script = pkgs.writeShellScript "syncthing-autoregister-script" ''
7 ${localpkgs.syncthing-set-id}/bin/syncthing-set-id /tmp/syncthing-auto-register-test-device-ids.nix
8 '';
9 in {
10 options = {
11 services.syncthing.autoRegister = {
12 enable = mkEnableOption ''
13 Automatically write the local syncthing device id to /tmp/syncthing-auto-register-test-device-ids.nix
14 '';
15 };
16 };
17 config = mkIf cfg.enable {
18 systemd.services.syncthing-autoregister = {
19 after = [ "syncthing.service" "syncthing-init.service" ];
20 wantedBy = [ "multi-user.target" ];
21 environment.NIX_PATH = config.environment.variables.NIX_PATH;
22 serviceConfig = {
23 User = config.services.syncthing.user;
24 RemainAfterExit = true;
25 Type = "oneshot";
26 ExecStart = register-script;
27 };
28 };
29 };
30 }
31