From 0a1dcf0a6a6eb79ed2b9b5e200b3052e67324507 Mon Sep 17 00:00:00 2001 From: MFlossmann Date: Thu, 9 May 2024 19:41:05 +0200 Subject: [PATCH] add the syncthing service --- hosts/remus/home.nix | 13 +++---- modules/home/default.nix | 26 +++++++------- modules/home/features/syncthing.nix | 53 +++++++++++++++++++++++++++++ modules/nixOS/default.nix | 7 ++++ 4 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 modules/home/features/syncthing.nix diff --git a/hosts/remus/home.nix b/hosts/remus/home.nix index f93407d..91f4009 100644 --- a/hosts/remus/home.nix +++ b/hosts/remus/home.nix @@ -35,15 +35,16 @@ ]; }; - myHomeManager.bundles.desktop.enable = true; - - myHomeManager.bundles.maker.enable = true; + myHomeManager = { + bundles = { + desktop.enable = true; + maker.enable = true; + }; + syncthing.enable = true; + }; programs.zsh.enable = true; - - - # Let Home Manager install and manage itself. # programs.home-manager.enable = true; } diff --git a/modules/home/default.nix b/modules/home/default.nix index 4c7acd4..9ad5828 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -8,18 +8,18 @@ ... }: let cfg = config.myHomeManager; - # # Taking all modules in ./features and adding enables to them - # features = - # helperLib.extendModules - # (name: { - # extraOptions = { - # myHomeManager.${name}.enable = lib.mkEnableOption "enable my ${name} configuration"; - # }; - # - # configExtension = config: (lib.mkIf cfg.${name}.enable config); - # }) - # (helperLib.filesIn ./features); - # + # Taking all modules in ./features and adding enables to them + features = + helperLib.extendModules + (name: { + extraOptions = { + myHomeManager.${name}.enable = lib.mkEnableOption "enable my ${name} configuration"; + }; + + configExtension = config: (lib.mkIf cfg.${name}.enable config); + }) + (helperLib.filesIn ./features); + # Taking all module bundles in ./bundles and adding bundle.enables to them bundles = helperLib.extendModules @@ -35,7 +35,7 @@ in { imports = [ ] - # ++ features + ++ features ++ bundles ; diff --git a/modules/home/features/syncthing.nix b/modules/home/features/syncthing.nix new file mode 100644 index 0000000..9544e12 --- /dev/null +++ b/modules/home/features/syncthing.nix @@ -0,0 +1,53 @@ +{ + pkgs, + config, + lib, + inputs, + ... + }: let + saintAlphonsoID = "LHASNUO-CXALARH-XI3TU4U-OCULV72-HS3HQ35-P4FECIT-UZ5VMSZ-PMCEPQH"; + + webGuiPort = [ 8384 ]; + cfg = config; + in { + imports = []; + + options = { + rootDir = lib.mkOption { + type = lib.types.path; + default = "/home/${cfg.myNixOS.sharedSettings.mainUser}/sync"; + }; + + remoteGui = lib.mkEnableOption "Enable port for remote WebGUI"; + }; + + services.syncthing = { + enable = true; + user = cfg.myNixOS.sharedSettings.mainUser; + dataDir = config.rootDir; + configDir = "/home/${cfg.myNixOS.sharedSettings.mainUser}/.config/syncthing"; + overrideDevices = true; + overrideFolders = true; + settings = { + devices = { + "saintAlphonso" = { id = saintAlphonsoID; }; + }; + folders = { + "KeepassXC" = { + path = "/home/${cfg.myNixOS.sharedSettings.mainUser}/KeepassXC"; + devices = [ "saintAlphonso" ]; + }; + }; + }; + }; + + # # Syncthing ports: 8384 for remote access to GUI + # # 22000 TCP and/or UDP for sync traffic + # # 21027/UDP for discovery + # # source: https://docs.syncthing.net/users/firewall.html + # networking.firewall.allowedTCPPorts = + # [ 22000 ] + # ++ webGuiPort; + # + # networking.firewall.allowedUDPPorts = [ 22000 21027 ]; +} diff --git a/modules/nixOS/default.nix b/modules/nixOS/default.nix index f60319a..184ed4d 100644 --- a/modules/nixOS/default.nix +++ b/modules/nixOS/default.nix @@ -58,6 +58,13 @@ in { sharedSettings = { # put settings here that are shared between homemanager and nixos, e.g. # hyprland.enable = lib.mkEnableOption "enable hyprland"; + + mainUser = lib.mkOption { + type = lib.types.str; + default = "prunebutt"; + example = "mainUser"; + description = "The main user that runs the system"; + }; }; };