Personal Nix flake
nixos home-manager nix
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(syncthing): Migrate syncthing to home configuration

+103 -192
+100 -103
nix/home/modules/syncthing/default.nix
··· 2 2 config, 3 3 lib, 4 4 pkgs, 5 + self, 5 6 osConfig ? {}, 6 7 ... 7 8 }: let 8 - syncthing = osConfig.services.syncthing.package or config.services.syncthing.package; 9 + inherit (self.lib.secrets.helpers) mkHostSecret; 9 10 syncthingtray = config.services.syncthing.tray.package; 10 11 cfg = config.my.syncthing; 11 12 in { 12 - options.my.syncthing.enable = 13 - lib.mkEnableOption "syncthing" 14 - // {default = osConfig.my.syncthing.enable or false;}; 13 + options.my.syncthing = { 14 + enable = 15 + lib.mkEnableOption "syncthing" 16 + // {default = osConfig.my.syncthing.enable or false;}; 17 + host = lib.mkOption { 18 + type = with lib.types; nullOr str; 19 + default = osConfig.networking.hostName or null; 20 + }; 21 + }; 15 22 16 23 config = lib.mkIf cfg.enable { 17 - home.packages = [syncthingtray]; 24 + assertions = [ 25 + { 26 + assertion = cfg.host != null; 27 + message = "config.my.syncthing.host must be set"; 28 + } 29 + ]; 30 + 31 + my.secretDefinitions = let 32 + owner = 33 + if (osConfig != {}) 34 + then config.home.username 35 + else "0"; 36 + in 37 + lib.mkIf (cfg.host != null) { 38 + "host.syncthing-cert" = mkHostSecret cfg.host "syncthing-cert" { 39 + inherit owner; 40 + }; 41 + "host.syncthing-key" = mkHostSecret cfg.host "syncthing-key" { 42 + inherit owner; 43 + }; 44 + }; 45 + 18 46 services.syncthing = { 19 - enable = osConfig == {}; 47 + enable = true; 20 48 tray.enable = true; 49 + cert = config.my.secrets."host.syncthing-cert".path; 50 + key = config.my.secrets."host.syncthing-key".path; 51 + settings = { 52 + gui.theme = "dark"; 53 + options = { 54 + localAnnounceEnabled = true; 55 + relaysEnabled = true; 56 + urAccepted = -1; # For no and don't ask again 57 + }; 58 + startBrowser = false; 59 + folders = let 60 + computers = ["desktop" "laptop" "steamdeck"]; 61 + phones = ["galaxyS23"]; 62 + servers = ["server"]; 63 + allDevices = computers ++ phones ++ servers; 64 + trashVersioning = { 65 + type = "trashcan"; 66 + params.cleanoutDays = "30"; 67 + }; 68 + in { 69 + "~/Sync" = { 70 + id = "default"; 71 + label = "Default Folder"; 72 + type = "sendreceive"; 73 + versioning = null; 74 + devices = allDevices; 75 + }; 76 + "~/Notes/Logseq" = { 77 + id = "6ymhp-fehcm"; 78 + label = "Notes/Logseq"; 79 + type = "sendreceive"; 80 + versioning = trashVersioning; 81 + devices = allDevices; 82 + }; 83 + "~/Notes/Obsidian" = { 84 + id = "tgnpg-efws9"; 85 + label = "Notes/Obsidian"; 86 + type = "sendreceive"; 87 + versioning = trashVersioning; 88 + devices = allDevices; 89 + }; 90 + "~/.steam/steam/userdata/85204334/config/grid" = { 91 + id = "steam-custom-icons"; 92 + label = "Steam/Custom Icons"; 93 + type = "sendreceive"; 94 + versioning = null; 95 + devices = computers ++ servers; 96 + }; 97 + }; 98 + devices = { 99 + desktop.id = "Q7UXFUW-Q4QWALL-AVBRBPW-Y2S44CV-IR4H3V4-OT2GH4V-6WCXBR4-STJXFQJ"; 100 + desktop.name = "Desktop"; 101 + laptop.id = "VFFQPOF-XAPVKHO-4PUSIVT-ACYNHAZ-GOQBWC6-SEYBXGE-2MBBMRS-TJRD4QL"; 102 + laptop.name = "Laptop"; 103 + pixel7.id = "PDMAJC4-SIXM4NI-UDMSLPU-3QSBSM2-ZUBLQDU-MNCR2HH-XUJIG52-PH4IKQC"; 104 + pixel7.name = "Pixel 7 Pro"; 105 + galaxyS23.id = "DPARDTW-7LHI6VK-CRKEYI4-VK6BWWP-DMW6KOG-6LWAT4O-QFGDFPR-XVO6RAF"; 106 + galaxyS23.name = "Galaxy S23"; 107 + server.id = "X5LHXQ6-NOCD2NO-RQ7FPLO-WFLLFRE-5BTTVL6-XLH3DAV-4ZIYI47-EEOVYAK"; 108 + server.name = "Server"; 109 + steamdeck.id = "OBZRWRW-B7DYVZC-RL5JV3D-6YNWG4O-MAIN2GY-KTEBY6V-DWQK36S-5E2O7AB"; 110 + steamdeck.name = "Steam Deck"; 111 + }; 112 + }; 21 113 }; 114 + 115 + home.packages = [syncthingtray]; 22 116 systemd.user.services.syncthingtray = { 23 117 Service.ExecStart = lib.mkForce (pkgs.writeShellScript "syncthingtray-wait" '' 24 118 ${syncthingtray}/bin/syncthingtray --wait 25 119 ''); 26 - Service.ExecStartPre = pkgs.writeShellScript "setup-syncthingtray" '' 27 - cat <<EOF >> ~/.config/syncthingtray.ini 28 - [General] 29 - v=${syncthingtray.version} 30 - 31 - [startup] 32 - considerForReconnect=false 33 - considerLauncherForReconnect=false 34 - showButton=false 35 - showLauncherButton=false 36 - stopOnMetered=false 37 - stopServiceOnMetered=false 38 - syncthingArgs="serve --no-browser --logflags=3" 39 - syncthingAutostart=false 40 - syncthingPath=syncthing 41 - syncthingUnit=syncthing.service 42 - systemUnit=false 43 - useLibSyncthing=false 44 - 45 - [tray] 46 - connections\1\apiKey=@ByteArray($(${syncthing}/bin/syncthing cli config dump-json | nu --stdin --commands 'from json | get gui.apiKey')) 47 - connections\1\authEnabled=false 48 - connections\1\autoConnect=true 49 - connections\1\devStatsPollInterval=60000 50 - connections\1\diskEventLimit=200 51 - connections\1\errorsPollInterval=30000 52 - connections\1\httpsCertPath=/home/lpchaim/.config/syncthing/https-cert.pem 53 - connections\1\label=Primary instance 54 - connections\1\longPollingTimeout=0 55 - connections\1\password= 56 - connections\1\pauseOnMetered=false 57 - connections\1\reconnectInterval=30000 58 - connections\1\requestTimeout=0 59 - connections\1\statusComputionFlags=59 60 - connections\1\syncthingUrl=http://127.0.0.1:8384 61 - connections\1\trafficPollInterval=5000 62 - connections\1\userName= 63 - connections\size=1 64 - dbusNotifications=true 65 - distinguishTrayIcons=false 66 - frameStyle=16 67 - ignoreInavailabilityAfterStart=15 68 - notifyOnDisconnect=true 69 - notifyOnErrors=true 70 - notifyOnLauncherErrors=true 71 - notifyOnLocalSyncComplete=false 72 - notifyOnNewDeviceConnects=false 73 - notifyOnNewDirectoryShared=false 74 - notifyOnRemoteSyncComplete=false 75 - positioning\assumedIconPos=@Point(0 0) 76 - positioning\useAssumedIconPosition=false 77 - positioning\useCursorPos=true 78 - preferIconsFromTheme=false 79 - showSyncthingNotifications=true 80 - showTabTexts=true 81 - showTraffic=true 82 - 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" 83 - statusIconsRenderSize=@Size(32 32) 84 - statusIconsStrokeWidth=0 85 - tabPos=1 86 - 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" 87 - trayIconsRenderSize=@Size(32 32) 88 - trayIconsStrokeWidth=0 89 - trayMenuSize=@Size(575 475) 90 - usePaletteForStatusIcons=false 91 - usePaletteForTrayIcons=false 92 - windowType=0 93 - 94 - [webview] 95 - customCommand= 96 - disabled=false 97 - mode=0 98 - qt\customfont=false 99 - qt\customicontheme=false 100 - qt\customlocale=false 101 - qt\custompalette=false 102 - qt\customstylesheet=false 103 - qt\customwidgetstyle=false 104 - qt\font="Sans Serif,9,-1,5,400,0,0,0,0,0,0,0,0,0,0,1" 105 - qt\icontheme=hicolor 106 - qt\iconthemepath= 107 - qt\locale=en_US 108 - 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) 109 - qt\plugindir= 110 - qt\stylesheetpath= 111 - qt\trpath= 112 - qt\widgetstyle= 113 - EOF 114 - ''; 115 - Unit.X-Restart-Triggers = [ 116 - syncthing 117 - syncthingtray 118 - "syncthing.systemunit.service" 119 - "syncthing-init.systemunit.service" 120 - "syncthing-relay.systemunit.service" 121 - ]; 122 - Unit.X-SwitchMethod = "restart"; 123 120 }; 124 121 }; 125 122 }
+3 -89
nix/nixos/modules/syncthing/default.nix
··· 1 1 { 2 2 config, 3 - inputs, 4 3 lib, 5 4 ... 6 5 }: let 7 - inherit (config.my.config) name; 8 - inherit (inputs.self.lib.secrets.helpers) mkHostSecret; 9 6 cfg = config.my.syncthing; 10 - home = config.home-manager.users.lpchaim.home.homeDirectory; 11 7 in { 12 8 options.my.syncthing.enable = lib.mkEnableOption "syncthing"; 13 9 14 10 config = lib.mkIf cfg.enable { 15 - my.secretDefinitions = { 16 - "host.syncthing-cert" = mkHostSecret config "syncthing-cert" { 17 - mode = "0440"; 18 - }; 19 - "host.syncthing-key" = mkHostSecret config "syncthing-key" { 20 - mode = "0440"; 21 - }; 22 - }; 23 - 24 - systemd.services.syncthing.preStart = let 25 - paths = builtins.attrNames config.services.syncthing.settings.folders; 26 - commands = map (p: "mkdir -p '${p}'") paths; 27 - script = builtins.concatStringsSep "\n" commands; 28 - in 29 - script; 30 - 31 - services.syncthing = { 32 - enable = true; 33 - relay.enable = true; 34 - openDefaultPorts = true; 35 - user = name.user; 36 - group = name.user; 37 - cert = config.my.secrets."host.syncthing-cert".path; 38 - key = config.my.secrets."host.syncthing-key".path; 39 - dataDir = "${home}/Syncthing"; 40 - configDir = "${home}/.config/syncthing"; 41 - settings = { 42 - gui.theme = "black"; 43 - options.relaysEnabled = true; 44 - options.urAccepted = -1; # For no and don't ask again 45 - options.localAnnounceEnabled = true; 46 - startBrowser = false; 47 - folders = let 48 - computers = ["desktop" "laptop" "steamdeck" "server"]; 49 - phones = ["pixel7" "galaxyS23"]; 50 - allDevices = computers ++ phones; 51 - trashVersioning = { 52 - type = "trashcan"; 53 - params.cleanoutDays = "30"; 54 - }; 55 - in { 56 - "${home}/Sync" = { 57 - id = "default"; 58 - label = "Default Folder"; 59 - type = "sendreceive"; 60 - versioning = null; 61 - devices = allDevices; 62 - }; 63 - "${home}/Notes/Logseq" = { 64 - id = "6ymhp-fehcm"; 65 - label = "Notes/Logseq"; 66 - type = "sendreceive"; 67 - versioning = trashVersioning; 68 - devices = allDevices; 69 - }; 70 - "${home}/Notes/Obsidian" = { 71 - id = "tgnpg-efws9"; 72 - label = "Obsidian"; 73 - type = "sendreceive"; 74 - versioning = trashVersioning; 75 - devices = allDevices; 76 - }; 77 - "${home}/.steam/steam/userdata/85204334/config/grid" = { 78 - id = "steam-custom-icons"; 79 - label = "Steam/Custom Icons"; 80 - type = "sendreceive"; 81 - versioning = null; 82 - devices = computers; 83 - }; 84 - }; 85 - devices = { 86 - desktop.id = "Q7UXFUW-Q4QWALL-AVBRBPW-Y2S44CV-IR4H3V4-OT2GH4V-6WCXBR4-STJXFQJ"; 87 - desktop.name = "Desktop"; 88 - laptop.id = "VFFQPOF-XAPVKHO-4PUSIVT-ACYNHAZ-GOQBWC6-SEYBXGE-2MBBMRS-TJRD4QL"; 89 - laptop.name = "Laptop"; 90 - pixel7.id = "PDMAJC4-SIXM4NI-UDMSLPU-3QSBSM2-ZUBLQDU-MNCR2HH-XUJIG52-PH4IKQC"; 91 - pixel7.name = "Pixel 7 Pro"; 92 - galaxyS23.id = "DPARDTW-7LHI6VK-CRKEYI4-VK6BWWP-DMW6KOG-6LWAT4O-QFGDFPR-XVO6RAF"; 93 - galaxyS23.name = "Galaxy S23"; 94 - server.id = "X5LHXQ6-NOCD2NO-RQ7FPLO-WFLLFRE-5BTTVL6-XLH3DAV-4ZIYI47-EEOVYAK"; 95 - server.name = "Server"; 96 - steamdeck.id = "OBZRWRW-B7DYVZC-RL5JV3D-6YNWG4O-MAIN2GY-KTEBY6V-DWQK36S-5E2O7AB"; 97 - steamdeck.name = "Steam Deck"; 98 - }; 99 - }; 11 + networking.firewall = { 12 + allowedTCPPorts = [22000]; 13 + allowedUDPPorts = [21027 22000]; 100 14 }; 101 15 }; 102 16 }