dot

NixOS dotfiles
git clone https://git.echoz.io/dot.git
Log | Files | Refs

syncthingtray-init.nix (1943B)


      1 {
      2   lib,
      3   pkgs,
      4 
      5   user,
      6   ...
      7 }:
      8 {
      9   home-manager.users.${user} =
     10     { config, ... }:
     11     {
     12       systemd.user.services = {
     13         ${config.services.syncthing.tray.package.pname}.Unit.Requires = [ "syncthingtray-init.service" ];
     14         syncthingtray-init = {
     15           Unit = {
     16             Description = "Generate syncthingtray config";
     17             After = [
     18               "syncthing.service"
     19               "graphical-session.target"
     20             ];
     21             Requires = [ "syncthing.service" ];
     22             Before = [ "${config.services.syncthing.tray.package.pname}.service" ];
     23             PartOf = [ "graphical-session.target" ];
     24           };
     25 
     26           Install.WantedBy = [ "default.target" ];
     27 
     28           Service = {
     29             Type = "oneshot";
     30             RuntimeDirectory = "syncthingtray-init";
     31             RemainAfterExit = true;
     32             ExecStart = pkgs.writeShellScript "syncthingtray-init" ''
     33               while
     34                 ! ${pkgs.libxml2}/bin/xmllint \
     35                   --xpath 'string(configuration/gui/apikey)' \
     36                   "''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing/config.xml" \
     37                   >"$RUNTIME_DIRECTORY/api_key"
     38               do ${lib.getExe' pkgs.coreutils "sleep"} 1; done
     39               cat >"''${XDG_CONFIG_HOME:-$HOME/.config}/syncthingtray.ini" <<EOF
     40               [General]
     41               v=${config.services.syncthing.tray.package.version}
     42 
     43               [tray]
     44               connections\\1\\apiKey=@ByteArray($(cat "$RUNTIME_DIRECTORY/api_key"))
     45               connections\\1\\syncthingUrl=http://127.0.0.1:8384
     46               connections\\1\\authEnabled=false
     47               connections\\1\\autoConnect=true
     48               connections\\1\\httpsCertPath=''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing/https-cert.pem
     49               connections\\1\\label=localhost
     50               connections\size=1
     51               EOF
     52             '';
     53           };
     54         };
     55       };
     56     };
     57 }