diff --git a/common/cloudsync.nix b/common/cloudsync.nix index e95e932..ffed584 100644 --- a/common/cloudsync.nix +++ b/common/cloudsync.nix @@ -10,12 +10,13 @@ in { nextcloud-client ]; - systemd = lib.mkMerge (lib.mapAttrsToList (local_user: paths: let + systemd.services = lib.mkMerge (lib.mapAttrsToList (local_user: user_conf: let + paths = user_conf.syncPaths; sync_script = lib.strings.concatLines (map ({local, remote}: let remote_clean = lib.strings.concatStrings (builtins.match "/*(.+)" remote); in "${cloud_cmd} /${remote_clean} ${local} ${sync_server}" ) paths); in { # user-specific sync jobs - services."nextcloud-autosync-${local_user}" = { + "nextcloud-autosync-${local_user}" = lib.mkIf ( paths != [] ) { description = "Auto sync Nextcloud"; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; @@ -29,13 +30,18 @@ in { wantedBy = ["multi-user.target"]; enable=true; }; - timers."nextcloud-autosync-${local_user}" = { + }) config.users.users ); + + systemd.timers = lib.mkMerge (lib.mapAttrsToList (local_user: user_conf: let + paths = user_conf.syncPaths; + in { # user-specific sync jobs + "nextcloud-autosync-${local_user}" = lib.mkIf ( paths != [] ) { description = "Automatic sync files with Nextcloud when booted up after 5 minutes then rerun every 60 minutes"; timerConfig.OnBootSec = "5min"; timerConfig.OnUnitActiveSec = "60min"; wantedBy = ["multi-user.target" "timers.target"]; enable = true; }; - }) cfg.cloudSync.paths ); + }) config.users.users ); }); } diff --git a/configuration.nix b/configuration.nix index f62694c..2d22a80 100644 --- a/configuration.nix +++ b/configuration.nix @@ -56,14 +56,6 @@ username = "Grimmauld"; server = "cloud.grimmauld.de"; passwordFile = config.age.secrets.nextcloud_pass.path; - paths = { - grimmauld = [ - { remote = "3d"; } - { remote = "Pictures"; } - { remote = "Documents"; } - { remote = "Videos"; } - ]; - }; }; }; diff --git a/load_common.nix b/load_common.nix index 9ccb129..9513414 100644 --- a/load_common.nix +++ b/load_common.nix @@ -2,6 +2,20 @@ with lib; let cfg = config.grimmShared; + sync_mod = types.submodule ({config, ...} : { + options = { + remote = mkOption { + type = types.nonEmptyStr; + description = "path on the cloud server"; + }; + + local = mkOption { + type = types.nonEmptyStr; + default = "$HOME/" + (lib.strings.concatStrings (builtins.match "/*(.+)" config.remote)); + description = "local path to sync"; + }; + }; + }); in { options.grimmShared = { enable = mkEnableOption "grimm-shared-common"; @@ -143,30 +157,21 @@ in { type = types.nonEmptyStr; description = "password file to use for login"; }; - - paths = mkOption { - type = let - mod = types.submodule ({config, ...} : { - options = { - remote = mkOption { - type = types.nonEmptyStr; - description = "path on the cloud server"; - }; - - local = mkOption { - type = types.nonEmptyStr; - default = "$HOME/" + (lib.strings.concatStrings (builtins.match "/*(.+)" config.remote)); - description = "local path to sync"; - }; - }; - }); - in types.attrsOf (types.listOf mod); - default = []; - description = "puts my personal config in place using above methods"; - }; }; }; + options.users.users = mkOption { + type = types.attrsOf (types.submodule { + options = { + syncPaths = mkOption { + type = types.listOf sync_mod; + default = []; + description = "paths to sync via nextcloud"; + }; + }; + }); + }; + imports = [ ./common/localisation.nix ./common/printing.nix diff --git a/modules/users.nix b/modules/users.nix index a786beb..8686f90 100644 --- a/modules/users.nix +++ b/modules/users.nix @@ -4,6 +4,14 @@ shell = pkgs.xonsh; description = "grimmauld"; extraGroups = [ "networkmanager" "kvm" "wheel" "input" "video" "lp" "scanner" "libvirt" "libvirt-qemu" "libvirtd" "pipewire" "gamemode" ]; + + syncPaths = [ + { remote = "3d"; } + { remote = "Pictures"; } + { remote = "Documents"; } + { remote = "Videos"; } + ]; + packages = with pkgs; [ webcord discord