From de84111822e8a2b0d9f7a447b07428d9cbfc3aed Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 18 Jan 2026 04:43:51 +0900 Subject: [PATCH] modules/duperemove: init --- flake.nix | 1 + modules/duperemove.nix | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 modules/duperemove.nix diff --git a/flake.nix b/flake.nix index 885f952..e6adc3b 100644 --- a/flake.nix +++ b/flake.nix @@ -144,6 +144,7 @@ nixosModules = { machineVars = ./modules/machineVars.nix; socketActivation = ./modules/socketActivation.nix; + duperemove = ./modules/duperemove.nix; }; homeModules = { diff --git a/modules/duperemove.nix b/modules/duperemove.nix new file mode 100644 index 0000000..74363e9 --- /dev/null +++ b/modules/duperemove.nix @@ -0,0 +1,60 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.services.duperemove; +in +{ + options.services.duperemove = { + enable = lib.mkEnableOption "duplicate file removal timers"; + + directories = lib.mkOption { + description = ""; + type = lib.types.attrsOf (lib.types.submodule { + options = { + enable = lib.mkEnableOption "" // { + default = true; + example = false; + }; + package = lib.mkPackageOption pkgs "duperemove" { }; + onCalendar = lib.mkOption { + type = with lib.types; nullOr str; + default = "monthly"; + example = "Mon *-*-* 00:00:00"; + }; + arguments = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ str int bool ]); + default = { }; + example = { }; + }; + }; + }); + default = { }; + example = { }; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services = { + "duperemove@" = { + description = "File duplicate remover for %i"; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${lib.getExe pkgs.duperemove} /"; + + RootDirectory = "%i"; + CacheDirectory = "duperemove"; + + PrivateInternet = true; + PrivateIPC = true; + }; + }; + } // (lib.mapAttrs' (n: v: { + name = "duperemove@${n}"; + value = { + onCalendar = lib.mkIf (v.onCalendar != null) v.onCalendar; + serviceConfig.ExecStart = let + args = lib.cli.toCommandLineShellGNU { } v.arguments; + in "${lib.getExe v.package} ${args}"; + }; + }) (cfg.filterAttrs (_: d: d.enable ) cfg.directories)); + }; +}