From 142cc28acc25145da9a1c9d58e0035b718a151a2 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Thu, 4 Apr 2024 12:24:31 +0200 Subject: [PATCH] some initial syncthing work no idea if this works --- hosts/chmura/configuration.nix | 9 ++- hosts/del/configuration.nix | 1 + hosts/niks/configuration.nix | 1 + modules/services/default.nix | 1 + modules/services/syncthing.nix | 105 +++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 modules/services/syncthing.nix diff --git a/hosts/chmura/configuration.nix b/hosts/chmura/configuration.nix index da3a45964..6abaf3f64 100644 --- a/hosts/chmura/configuration.nix +++ b/hosts/chmura/configuration.nix @@ -81,9 +81,12 @@ in { neovim.enable = true; helix.enable = true; }; - services.ssh = { - agent.enable = false; - daemon.enable = true; + services = { + ssh = { + agent.enable = false; + daemon.enable = true; + }; + syncthing.enable = true; }; }; diff --git a/hosts/del/configuration.nix b/hosts/del/configuration.nix index a1607bc07..acd792177 100644 --- a/hosts/del/configuration.nix +++ b/hosts/del/configuration.nix @@ -359,6 +359,7 @@ }; }; pipewire.enable = true; + syncthing.enable = true; }; }; diff --git a/hosts/niks/configuration.nix b/hosts/niks/configuration.nix index 260683a92..f2a3cd7a9 100644 --- a/hosts/niks/configuration.nix +++ b/hosts/niks/configuration.nix @@ -296,6 +296,7 @@ }; }; pipewire.enable = true; + syncthing.enable = true; }; }; diff --git a/modules/services/default.nix b/modules/services/default.nix index 6b44575d5..68adb966f 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -5,5 +5,6 @@ _: { ./mpd.nix ./pipewire.nix ./ssh.nix + ./syncthing.nix ]; } diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix new file mode 100644 index 000000000..ce06636cd --- /dev/null +++ b/modules/services/syncthing.nix @@ -0,0 +1,105 @@ +{ + config, + lib, + ... +}: with lib; let + cfg = config.myOptions.services.syncthing; + username = config.myOptions.other.system.username; + hmCfg = config.home-manager.users.${username}; +in { + options.myOptions.services.syncthing = { + enable = mkEnableOption "enable syncthing"; + extraSettings = mkOption { + type = types.attrs; + description = "extra per host syncthing settings"; + default = {}; + }; + }; + + # https://wes.today/nixos-syncthing/ + config = let + port = 8384; + homeDirectory = hmCfg.home.homeDirectory; + in mkIf cfg.enable { + services.syncthing = { + enable = true; + dataDir = homeDirectory; + configDir = "${hmCfg.xdg.configHome}/syncthing"; + openDefaultPorts = true; + user = username; + group = "users"; + guiAddress = "0.0.0.0:${toString port}"; + overrideDevices = false; + overrideFolders = false; + # settings = { + # devices = { + # niks.id = "ZXGYWRF-THUTZFB-UUSUNFJ-6O4SP5X-WZH5DOJ-YC25NHH-EC55CIH-V7ZKFQG"; + # # del.id = ""; + # # chmura.id = ""; + # }; + # folders = { + # Projects = { + # path = "${homeDirectory}/Projects"; + # devices = [ "niks" /*"del" "chmura"*/ ]; + # versioning = { + # type = "staggered"; + # params = { + # cleanInterval = "3600"; + # maxAge = "15552000"; + # }; + # }; + # }; + # Studia = { + # path = "${homeDirectory}/Studia"; + # devices = [ "niks" /*"del" "chmura"*/ ]; + # versioning = { + # type = "staggered"; + # params = { + # cleanInterval = "3600"; + # maxAge = "15552000"; + # }; + # }; + # }; + # KeepassXC = { + # path = "${homeDirectory}/KeepassXC"; + # devices = [ "niks" /*"del" "chmura"*/ ]; + # versioning = { + # type = "staggered"; + # params = { + # cleanInterval = "3600"; + # maxAge = "15552000"; + # }; + # }; + # }; + # Notes = { + # path = "${homeDirectory}/Notes"; + # devices = [ "niks" /*"del" "chmura"*/ ]; + # versioning = { + # type = "staggered"; + # params = { + # cleanInterval = "3600"; + # maxAge = "15552000"; + # }; + # }; + # }; + # mieszkanie = { + # path = "${homeDirectory}/mieszkanie"; + # devices = [ "niks" /*"del" "chmura"*/ ]; + # versioning = { + # type = "staggered"; + # params = { + # cleanInterval = "3600"; + # maxAge = "15552000"; + # }; + # }; + # }; + # }; + # } // cfg.extraSettings; + }; + services.caddy = { + virtualHosts."sync.jacekpoz.pl".extraConfig = '' + reverse_proxy * localhost:${toString port} + ''; + }; + }; +}