]> git.scottworley.com Git - syncthing-autoregister/blame - modules/syncthing-autoregister.nix
Option for file to write into
[syncthing-autoregister] / modules / syncthing-autoregister.nix
CommitLineData
b00b144b 1{ config, lib, pkgs, ... }:
7fb0951b 2with lib;
b00b144b 3let
7fb0951b 4 cfg = config.services.syncthing.autoRegister;
b00b144b
SW
5 localpkgs = import ../. { inherit pkgs; };
6 register-script = pkgs.writeShellScript "syncthing-autoregister-script" ''
320df276
SW
7 ${localpkgs.syncthing-set-id}/bin/syncthing-set-id ${
8 escapeShellArg cfg.path
9 }
b00b144b
SW
10 '';
11in {
7fb0951b
SW
12 options = {
13 services.syncthing.autoRegister = {
14 enable = mkEnableOption ''
320df276
SW
15 Automatically write the local syncthing device id to the nix module
16 file <option>services.syncthing.autoRegister.path</option>.
7fb0951b 17 '';
320df276
SW
18 path = mkOption {
19 type = types.path;
20 default = "/tmp/syncthing-auto-register-test-device-ids.nix";
21 description = ''
22 Path of nix module file to write our syncthing
23 device id into. It will be written into
24 services.syncthing.declarative.devices.<hostname>.id. This file
25 can be imported as a NixOS module.
26
27 We recommend using a separate file just for this purpose. I.e.,
28 don't point this at your main NixOS config. Instead, import this
29 file from your main NixOS config. (The current nix-configuration
30 read-modify-write implementation only supports attrsets of strings;
31 it does not support functions, which you probably use in your
32 main configuration.)
33 '';
34 };
7fb0951b
SW
35 };
36 };
37 config = mkIf cfg.enable {
b00b144b
SW
38 systemd.services.syncthing-autoregister = {
39 after = [ "syncthing.service" "syncthing-init.service" ];
40 wantedBy = [ "multi-user.target" ];
41 environment.NIX_PATH = config.environment.variables.NIX_PATH;
42 serviceConfig = {
43 User = config.services.syncthing.user;
44 RemainAfterExit = true;
45 Type = "oneshot";
46 ExecStart = register-script;
47 };
48 };
49 };
50}
51