Allow specifying global default systemd dependencies

This commit is contained in:
Manuel Thalmann 2024-05-14 15:39:41 +02:00
parent e27dadb8e4
commit b7198ddeac

View file

@ -1,5 +1,8 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.rclone;
targetName = "rclone";
mkProvider =
{ secretLoader ? ({ ... }: ""), envLoader ? ({ ... }: { }), options ? {}, ... }: {
inherit
@ -9,6 +12,16 @@ let
;
};
mkSystemdDependencyOption =
{ default, ... }: lib.mkOption {
type = lib.types.attrsOf lib.types.str;
description = "The systemd services this sync depends on.";
example = {
secrets = "sops-nix.service";
};
inherit default;
};
syncProviders = {
nextcloud = mkProvider {};
proton = mkProvider {};
@ -30,12 +43,8 @@ let
default = true;
};
systemdDependencies = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
description = "The systemd services this sync depends on.";
example = {
secrets = "sops-nix.service";
};
systemdDependencies = mkSystemdDependencyOption {
default = cfg.systemdDependencies;
};
environment = lib.mkOption {
@ -61,6 +70,10 @@ in {
programs.rclone = {
enable = lib.mkEnableOption "rclone";
systemdDependencies = mkSystemdDependencyOption {
default = {};
};
configs = lib.mkOption {
type = lib.types.attrsOf syncType;
description = "The synchronizations to set up.";
@ -69,10 +82,7 @@ in {
};
};
config =
let
cfg = config.programs.rclone;
in {
config = {
home.packages = lib.optional cfg.enable pkgs.rclone;
systemd.user = lib.optionalAttrs cfg.enable {
@ -130,11 +140,16 @@ in {
in
(lib.getExe script);
};
Install = {
WantedBy = lib.optional sync.autoStart "${targetName}.target";
After = builtins.concatLists(builtins.attrValues sync.systemdDependencies);
};
};
})
cfg.configs);
targets.rclone = {
targets.${targetName} = {
Unit = {
Description = "rclone Mounts";
Documentation = "man:rclone(1)";