further modularization + systemd template

This commit is contained in:
2024-05-11 21:35:31 -06:00
parent 0380c32b9a
commit 02d600cc73
16 changed files with 149 additions and 85 deletions

46
modules/scripts/base.nix Normal file
View File

@@ -0,0 +1,46 @@
{ config, lib, pkgs, ... }: {
options.my.script = {
name = lib.mkOption {
type = lib.types.str;
default = "my-script";
description = "Name of the script.";
};
timer = lib.mkOption {
type = lib.types.str;
default = "*:0/10";
description = "Systemd timer schedule.";
};
description = lib.mkOption {
type = lib.types.str;
default = "A service that runs a script.";
description = "Description of the service.";
};
package = lib.mkOption {
type = lib.types.package;
default = pkgs.writeScriptBin "my-script" "echo Hello World";
description = "Package containing the executable script.";
};
};
config = {
users.users.jawz.packages = [ config.my.script.package ];
systemd.user = with config.my.script; {
services."${name}" = {
restartIfChanged = true;
description = description;
wantedBy = [ "default.target" ];
path = [ pkgs.nix package ];
serviceConfig = {
Restart = "on-failure";
RestartSec = 30;
ExecStart = "${package}/bin/${name}";
};
};
timers."${name}" = {
enable = true;
description = description;
wantedBy = [ "timers.target" ];
timerConfig = { OnCalendar = timer; };
};
};
};
}

13
modules/scripts/tasks.nix Normal file
View File

@@ -0,0 +1,13 @@
{ config, lib, pkgs, ... }: {
imports = [ ./base.nix ];
options.my.scripts.tasks.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.scripts.tasks.enable {
my.script = {
name = "tasks";
timer = "*:0/10";
description = "runs a bunch of organizing tasks on selected directories";
package = (pkgs.writeScriptBin "tasks"
(builtins.readFile ../../scripts/tasks.sh));
};
};
}