1
0
Fork 0
This commit is contained in:
Lukas Wurzinger 2025-01-04 23:51:35 +01:00
parent 0f6a49366e
commit 024ea1168a
No known key found for this signature in database
23 changed files with 485 additions and 101 deletions

12
modules/main-user.nix Normal file
View file

@ -0,0 +1,12 @@
{lib, ...}: let
inherit (lib) types;
in {
options = {
users.mainUser = lib.mkOption {
type = types.passwdEntry types.str;
description = ''
The main user.
'';
};
};
}

120
modules/musicomp.nix Normal file
View file

@ -0,0 +1,120 @@
{
self,
lib,
pkgs,
utils,
...
}: let
inherit (lib) types;
inherit (utils.systemdUtils.unitOptions) unitOption;
in {
options.services.musicomp.jobs = lib.mkOption {
description = ''
Periodic jobs to run with musicomp.
'';
# type = types.attrsOf (types.submodule ({name, ...}: {
type = types.attrsOf (types.submodule {
options = {
music = lib.mkOption {
type = types.str;
description = ''
Source directory.
'';
example = "/srv/music";
};
comp = lib.mkOption {
type = types.str;
description = ''
Destination directory for compressed music.
'';
example = "/srv/comp";
};
post = lib.mkOption {
type = types.lines;
default = "";
description = ''
Shell commands that are run after compression has finished.
'';
};
workers = lib.mkOption {
type = lib.types.int;
default = 0;
description = ''
Number of workers.
'';
};
timerConfig = lib.mkOption {
type = lib.types.nullOr (lib.types.attrsOf unitOption);
default = {
OnCalendar = "daily";
Persistent = true;
};
description = ''
When to run the job.
'';
};
package = lib.mkPackageOption self.packages.${pkgs.system} "musicomp" {};
inhibitsSleep = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Prevents the system from sleeping while running the job.
'';
};
};
description = ''
Periodic compression jobs to run with musicomp.
'';
default = {};
});
};
config = {
systemd.services =
lib.mapAttrs'
(
name: job:
lib.nameValuePair "musicomp-jobs-${name}" {
restartIfChanged = false;
# TODO
wants = ["network-online.target"];
after = ["network-online.target"];
script = ''
${lib.optionalString job.inhibitsSleep ''
${lib.getExe' pkgs.systemd "systemd-inhibit"} \
--mode block \
--who musicomp \
--what sleep \
--why ${lib.escapeShellArg "Scheduled musicomp ${name}"}
''}
${lib.getExe job.package} \
${lib.optionalString (job.workers > 0) "--workers ${job.workers}"} \
-- ${job.music} ${job.comp}
'';
postStop = job.post;
serviceConfig.Type = "oneshot";
}
)
config.services.musicomp.jobs;
systemd.timers =
lib.mapAttrs'
(name: job:
lib.nameValuePair "musicomp-jobs-${name}" {
wantedBy = ["timers.target"];
inherit (job) timerConfig;
})
(lib.filterAttrs (_: job: job.timerConfig != null) config.services.musicomp.jobs);
};
}

33
modules/user-types.nix Normal file
View file

@ -0,0 +1,33 @@
{
config,
lib,
...
}: {
options.users = let
inherit (lib) types;
in {
normalUsers = lib.mkOption {
type = types.listOf (types.passwdEntry types.str);
description = ''
List of normal users.
'';
};
systemUsers = lib.mkOption {
type = types.listOf (types.passwdEntry types.str);
description = ''
List of system users.
'';
};
};
config.users = let
filterUsers = pred: (lib.pipe config.users.users [
(lib.filterAttrs (_: pred))
builtins.attrNames
]);
in {
normalUsers = filterUsers (user: user.isNormalUser);
systemUsers = filterUsers (user: user.isSystemUser);
};
}