Skip to content

Commit

Permalink
feat: Add basic declarative syncthing configuration
Browse files Browse the repository at this point in the history
Syncs default folder and custom Steam artwork with my server for now

Also adds syncthingtray
  • Loading branch information
lpchaim committed Oct 6, 2024
1 parent b4b4dda commit 23028dd
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .sops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ creation_rules:
- *raspberrypi
- *steamdeck
- *wsl
- path_regex: secrets/hosts/[^/]+\.(yaml|json|env|ini)$
key_groups:
- age:
- *master1
- *master2
- *desktop
105 changes: 105 additions & 0 deletions modules/home/syncthing/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
lib,
pkgs,
...
} @ args: let
# inherit (inputs.home-manager.lib) hm;
inherit (pkgs) syncthingtray;
syncthing = args.osConfig.services.syncthing.package;
in
lib.mkIf (args ? osConfig && args.osConfig.services.syncthing.enable) {
services.syncthing.tray.enable = true;
systemd.user.services.syncthingtray = {
Service.ExecStartPre = pkgs.writeShellScript "setup-syncthingtray" ''
cat <<EOF >> ~/.config/syncthingtray.ini
[General]
v=${pkgs.syncthingtray.version}
[startup]
considerForReconnect=false
considerLauncherForReconnect=false
showButton=false
showLauncherButton=false
stopOnMetered=false
stopServiceOnMetered=false
syncthingArgs="serve --no-browser --logflags=3"
syncthingAutostart=false
syncthingPath=syncthing
syncthingUnit=syncthing.service
systemUnit=false
useLibSyncthing=false
[tray]
connections\1\apiKey=@ByteArray($(${syncthing}/bin/syncthing cli config dump-json | nu --stdin --commands 'from json | get gui.apiKey'))
connections\1\authEnabled=false
connections\1\autoConnect=true
connections\1\devStatsPollInterval=60000
connections\1\diskEventLimit=200
connections\1\errorsPollInterval=30000
connections\1\httpsCertPath=/home/lpchaim/.config/syncthing/https-cert.pem
connections\1\label=Primary instance
connections\1\longPollingTimeout=0
connections\1\password=
connections\1\pauseOnMetered=false
connections\1\reconnectInterval=30000
connections\1\requestTimeout=0
connections\1\statusComputionFlags=59
connections\1\syncthingUrl=http://127.0.0.1:8384
connections\1\trafficPollInterval=5000
connections\1\userName=
connections\size=1
dbusNotifications=true
distinguishTrayIcons=false
frameStyle=16
ignoreInavailabilityAfterStart=15
notifyOnDisconnect=true
notifyOnErrors=true
notifyOnLauncherErrors=true
notifyOnLocalSyncComplete=false
notifyOnNewDeviceConnects=false
notifyOnNewDirectoryShared=false
notifyOnRemoteSyncComplete=false
positioning\assumedIconPos=@Point(0 0)
positioning\useAssumedIconPosition=false
positioning\useCursorPos=true
preferIconsFromTheme=false
showSyncthingNotifications=true
showTabTexts=true
showTraffic=true
statusIcons="#ff26b6db,#ff0882c8,#ffffffff;#ffdb3c26,#ffc80828,#ffffffff;#ffc9ce3b,#ffebb83b,#ffffffff;#ff2d9d69,#ff2d9d69,#ffffffff;#ff26b6db,#ff0882c8,#ffffffff;#ff26b6db,#ff0882c8,#ffffffff;#ffa9a9a9,#ff58656c,#ffffffff;#ffa9a9a9,#ff58656c,#ffffffff"
statusIconsRenderSize=@Size(32 32)
statusIconsStrokeWidth=0
tabPos=1
trayIcons="#ff26b6db,#ff0882c8,#ffffffff;#ffdb3c26,#ffc80828,#ffffffff;#ffc9ce3b,#ffebb83b,#ffffffff;#ff2d9d69,#ff2d9d69,#ffffffff;#ff26b6db,#ff0882c8,#ffffffff;#ff26b6db,#ff0882c8,#ffffffff;#ffa9a9a9,#ff58656c,#ffffffff;#ffa9a9a9,#ff58656c,#ffffffff"
trayIconsRenderSize=@Size(32 32)
trayIconsStrokeWidth=0
trayMenuSize=@Size(575 475)
usePaletteForStatusIcons=false
usePaletteForTrayIcons=false
windowType=0
[webview]
customCommand=
disabled=false
mode=0
qt\customfont=false
qt\customicontheme=false
qt\customlocale=false
qt\custompalette=false
qt\customstylesheet=false
qt\customwidgetstyle=false
qt\font="Sans Serif,9,-1,5,400,0,0,0,0,0,0,0,0,0,0,1"
qt\icontheme=hicolor
qt\iconthemepath=
qt\locale=en_US
qt\palette=@Variant(\0\0\0\x44\x1\x1\xff\xff\0\0\0\0\0\0\0\0\x1\x1\xff\xff\xef\xef\xef\xef\xef\xef\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\xcb\x4\xcb\x4\xcb\x4\0\0\x1\x1\xff\xff\x9f\xf4\x9f\xf4\x9f\xf4\0\0\x1\x1\xff\xff\xb8\x90\xb8\x90\xb8\x90\0\0\x1\x1\xff\xff\0\0\0\0\0\0\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\0\0\0\0\0\0\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\xef\xef\xef\xef\xef\xef\0\0\x1\x1\xff\xffv{v{v{\0\0\x1\x1\xff\xff\x30\x30\x8c\x8c\xc6\xc6\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\0\0\0\0\xff\xff\0\0\x1\x1\xff\xff\xff\xff\0\0\xff\xff\0\0\x1\x1\xff\xff\xf7\xf7\xf7\xf7\xf7\xf7\0\0\x1\x1\xff\xff\xbe\xbe\xbe\xbe\xbe\xbe\0\0\x1\x1\xff\xff\xef\xef\xef\xef\xef\xef\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\xcb\x4\xcb\x4\xcb\x4\0\0\x1\x1\xff\xff\xbe\xbe\xbe\xbe\xbe\xbe\0\0\x1\x1\xff\xff\xb8\x90\xb8\x90\xb8\x90\0\0\x1\x1\xff\xff\xbe\xbe\xbe\xbe\xbe\xbe\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\xbe\xbe\xbe\xbe\xbe\xbe\0\0\x1\x1\xff\xff\xef\xef\xef\xef\xef\xef\0\0\x1\x1\xff\xff\xef\xef\xef\xef\xef\xef\0\0\x1\x1\xff\xff\xb1\xb8\xb1\xb8\xb1\xb8\0\0\x1\x1\xff\xff\x91\x91\x91\x91\x91\x91\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\0\0\0\0\xff\xff\0\0\x1\x1\xff\xff\xff\xff\0\0\xff\xff\0\0\x1\x1\xff\xff\xf7\xf7\xf7\xf7\xf7\xf7\0\0\x1\x1\xff\xff\0\0\0\0\0\0\0\0\x1\x1\xff\xff\xef\xef\xef\xef\xef\xef\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\xcb\x4\xcb\x4\xcb\x4\0\0\x1\x1\xff\xff\x9f\xf4\x9f\xf4\x9f\xf4\0\0\x1\x1\xff\xff\xb8\x90\xb8\x90\xb8\x90\0\0\x1\x1\xff\xff\0\0\0\0\0\0\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\0\0\0\0\0\0\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\xef\xef\xef\xef\xef\xef\0\0\x1\x1\xff\xffv{v{v{\0\0\x1\x1\xff\xff\x30\x30\x8c\x8c\xc6\xc6\0\0\x1\x1\xff\xff\xff\xff\xff\xff\xff\xff\0\0\x1\x1\xff\xff\0\0\0\0\xff\xff\0\0\x1\x1\xff\xff\xff\xff\0\0\xff\xff\0\0\x1\x1\xff\xff\xf7\xf7\xf7\xf7\xf7\xf7\0\0)
qt\plugindir=
qt\stylesheetpath=
qt\trpath=
qt\widgetstyle=
EOF
'';
Unit.X-Restart-Triggers = [syncthing syncthingtray];
Unit.X-SwitchMethod = "restart";
};
}
72 changes: 72 additions & 0 deletions modules/nixos/syncthing/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
config,
inputs,
lib,
...
}: let
inherit (lib.lpchaim.shared) defaults;

home = "/home/${defaults.name.user}";
sopsFile = "${inputs.self}/secrets/hosts/${config.networking.hostName}.yaml";
in
lib.mkIf (lib.pathExists sopsFile) {
sops.secrets = {
"syncthing/cert" = {
inherit sopsFile;
mode = "0440";
};
"syncthing/key" = {
inherit sopsFile;
mode = "0440";
};
};

systemd.services.syncthing.preStart = let
paths = builtins.attrNames config.services.syncthing.settings.folders;
commands = map (p: "mkdir -p '${p}'") paths;
script = builtins.concatStringsSep "\n" commands;
in
script;

services.syncthing = {
enable = true;
relay.enable = true;
openDefaultPorts = true;
user = defaults.name.user;
group = defaults.name.user;
cert = config.sops.secrets."syncthing/cert".path;
key = config.sops.secrets."syncthing/key".path;
dataDir = "${home}/Syncthing";
configDir = "${home}/.config/syncthing";
settings = {
gui.theme = "black";
options.relaysEnabled = true;
options.urAccepted = -1;
startBrowser = false;
folders = let
allDevices = builtins.attrNames config.services.syncthing.settings.devices;
in {
"${home}/Sync" = {
id = "default";
label = "Default Folder";
type = "sendreceive";
versioning = null;
devices = allDevices;
};
"${home}/.steam/steam/userdata/85204334/config/grid" = {
id = "steam-custom-icons";
label = "Steam/Custom Icons";
type = "sendreceive";
versioning = null;
devices = allDevices;
};
};
devices = {
desktop.id = "Q7UXFUW-Q4QWALL-AVBRBPW-Y2S44CV-IR4H3V4-OT2GH4V-6WCXBR4-STJXFQJ";
desktop.name = "Desktop";
server.id = "X5LHXQ6-NOCD2NO-RQ7FPLO-WFLLFRE-5BTTVL6-XLH3DAV-4ZIYI47-EEOVYAK";
server.name = "Server";
};
};
};
}
4 changes: 2 additions & 2 deletions secrets/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ sops:
d0tBMXZkQnpCenZHdW9SMUs0dUlsTWcKEgypYl2f9UteYvnNlyS30OG3wZXPUEt0
9rwMktnBaYvS8aekWw+zUy+WJZ3YtRDFm4fqykG12mvV1eAqq/Tq9Q==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2024-09-28T15:34:06Z"
mac: ENC[AES256_GCM,data:vYvdgzvBEGN2p/mMdirv8jn30JXf+unMTjHD5IWHrGijXQVvCkAbGK0c54Y/90uDl9M7eCLzZUzMD0NIKuz+8cEOVW6TSvt8RxcCeCIIHEbp9SxgiYWU6CPGzpC+1dofqsyAPdfMXeszE7LkDD/DCmaA4E/zJVC0lPbsxtdP5QQ=,iv:sKjjXLkm430AuZ8oFiXSYwda26+bcq7WgMazfcKEnko=,tag:eStzVW7As3MJ+J+PYc78AQ==,type:str]
lastmodified: "2024-10-06T02:48:47Z"
mac: ENC[AES256_GCM,data:WdoGJf0CyNCCcY4fiy8sSjxA/JK0+KtqpkLGWOAEin9CLtU5N4Uhhs3CbIR2p03+fdyObt9dTGgrWFsDQrrTeLy+RNwOpLTDf9gPNQXc+c+psc/6sSme6L0x6Hi9vW622UC7qkcheTCJTi4131bdRjXsEb2B8k/dy8NVTh8ImUY=,iv:tP7Fk97+MoXWpyQ2Fcpk1VTuSSIVbJ/0cELlF5b4iHs=,tag:0bDM3sw6CX12L5qG+hT7EA==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.9.0
41 changes: 41 additions & 0 deletions secrets/hosts/desktop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
syncthing:
cert: ENC[AES256_GCM,data:0WeUAZidnJXEDumpWQ+h/UsW6ae3kCPLtJKKbqK3IktVrkklE/3RPli+1q4IRZq0wvXwLIGFKYkynCZhxgM286ITo9rbCKv+Jg7Nz/1gNeExZ+dWgAlHwy5PTYBwp0TTBjwUxjxsIvpphvJwWil7LPbabBaeTY3sHmYvIcAD1hycQDwsLQL0h6Lj6dEZrzQYOg+NsdT9eL28xA1x4Ij/U3qAMHZViY2INpo1ZK+QBEQ3eIIF4/wyPFqHZxk6JqNYTiHr1K0d1HWFHrCWRI/Vke3nKFifnQ3OWAFGhr6edfFTQj9y8wZwZHUEBaNhmUwYdTOWoByL6uCzSiwOUwAz69Bfxt1yrPPEwmpZYwZ6ULmfFKTCtVJX1dIwna6xbVfDZiHrI6lWpKDfrTecDb28tXoKQHG9FauQwf/9XTc4Ny/LaHM0Pu/ovSE3R3aEF2rtELnMWRizr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44/AwqiMWGygBBM,iv:ez/v3hepUx5WcxUfYhSFHn6qdz1i9v+bVSgC/GFKYLE=,tag:MS8TPXwRzQ8JgmZVQicfWQ==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age1tq2gcmu4hd4sd89hl7szhd0z8vg6tx9hk3xsvuljm9gsj7n0l4nsl6ad4u
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBKdXc3R1NzOExVVTZhY0xJ
OUhXNkZiN2pEdDFRUEJwMWM5cmYzSGFNVTFJCmlIQ1M0cEVJV0MySTM2amVhczJI
YTFyR0ZyQ0dXV2xYUXJncHROTzBIWHcKLS0tIGpaM1A4TkllQTFFSEgrUFpVTWZC
ZkZBSFRGSjBjZUlseXNpeGlDVzdRcE0KPs1GIdC02sW1+xw7dfx0ruXcR5VMhnxy
86ioofd+eTyDXr7qAPZ/NBbwN5G/IMT0xxCzsX3oZ1PjM4VKre7eqQ==
-----END AGE ENCRYPTED FILE-----
- recipient: age10fa7ce7w6q0ppk5l2gvg6d02g9cmj26rpt00ct54d4latqsnwajs90a43h
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBpbElDNG9VNkhiUzF4VXJB
K1JMb2ZHSCtsTHdjeFJzMEpiRmxGQUl6NVhVCnZNS3AwWTNITERueGpGZEFjckF2
aStwcUs3QTk4YTY5Q08wWm1IeG1aZUUKLS0tIDdITEdUamZIM0N4bk10Vk92V0lJ
bTY5dnczdTdkRVBVT0t1ZklyUDd6YWsKwwuYi45ibAA0WEXBYupTeeo2DUy2ZhGW
XUglq1UB4Jynps8D7BlFrCnvdJ/d2rfQXkfYZ5MV6MSqtpbChNCCHA==
-----END AGE ENCRYPTED FILE-----
- recipient: age1a90s9rr2t82vlx4q757pvqm88nh572567hssycczv2t5rjhzudmsvqdjuv
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSB3aEpjdmxqbTAxbDAzWUxH
RzhCZVl2Z2FtRmtxQkRvbkpJNkxIQnJjR0QwCldPSUVTM3NNVS9iS2g0bm12Zkxj
WGZLalJKeUZVL0dGeDZZR3Fob092UlUKLS0tIDJkL1dwYVRDbThFb3JnbkRqbmlN
cWRIeElnNWZqSzRZQWI3eEUvRVd5UjQKcN7ne7wQXcvKhqrNS1xe4wISn2Ykb5Yx
EITcdR6FSX/v4TvTGxFiq5SJkxbssVzadoIzyPIxGiYaoeMY/hdCjw==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2024-10-06T00:19:47Z"
mac: ENC[AES256_GCM,data:T6EAlyxfQHNvEvqPo9RjHLkyTpSDo3w85MNnTjJoKH9MCcshb1UjbNacQ2NZa95562BTndKB+LU4U6iUf0P9q4nBif3M7GxXyFyObmflqOTpZvxKelsYawqF5aNRnQmAT2voen0EoQ9VYp7XLYKaeZgP5tk4qGqKfcvwmYzPI2c=,iv:XtyEWIwto7kQD1ba21YxWdzQaF3XPTrhvSLuzmvxWnc=,tag:yQvcEp/20xj1coTsg0nHuw==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.9.0

0 comments on commit 23028dd

Please sign in to comment.