1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/modules/moodle-dl.nix

96 lines
2.8 KiB
Nix
Raw Permalink Normal View History

2022-03-10 21:52:12 +01:00
{
config,
lib,
pkgs,
...
}:
2025-12-27 22:22:54 +01:00
with lib;
let
cfg = config.services.moodle-dl;
2025-12-27 22:22:54 +01:00
json = pkgs.formats.json { };
moodle-dl-json = json.generate "moodle-dl.json" cfg.settings;
stateDirectoryDefault = "/var/lib/moodle-dl";
2025-12-27 22:22:54 +01:00
in
{
options = {
services.moodle-dl = {
enable = mkEnableOption "moodle-dl, a Moodle downloader";
settings = mkOption {
2025-12-27 22:22:54 +01:00
default = { };
type = json.type;
description = ''
Configuration for moodle-dl. For a full example, see
<link xlink:href="https://github.com/C0D3D3V/Moodle-Downloader-2/wiki/Config.json"/>.
'';
};
tokensFile = mkOption {
type = types.path;
description = ''
Path to a JSON file containing a "token" key and, optionally, a "telegram"."token" key.
'';
};
notifyOnly = mkOption {
default = false;
type = types.bool;
description = ''
Whether to notify about changes without downloading any files.
'';
};
startAt = mkOption {
type = with types; either str (listOf str);
description = "When to run moodle-dl. See systemd.time(7) for the format.";
};
directory = mkOption {
default = stateDirectoryDefault;
type = types.path;
description = ''
The path moodle-dl should download course files to. If left
as the default value this directory will automatically be created before
moodle-dl runs, otherwise the sysadmin is responsible for ensuring
the directory exists with appropriate ownership and permissions.
'';
};
package = mkOption {
default = pkgs.moodle-dl;
type = types.package;
description = "The moodle-dl package to use.";
};
};
};
config = mkIf cfg.enable {
users.users.moodle-dl = {
isSystemUser = true;
home = cfg.directory;
group = "moodle-dl";
};
2025-12-27 22:22:54 +01:00
users.groups.moodle-dl = { };
systemd.services.moodle-dl = {
description = "A Moodle downloader that downloads course content";
2025-12-27 22:22:54 +01:00
wants = [ "network-online.target" ];
serviceConfig = mkMerge [
{
Type = "oneshot";
User = config.users.users.moodle-dl.name;
Group = config.users.groups.moodle-dl.name;
WorkingDirectory = cfg.directory;
ExecStart = "${cfg.package}/bin/moodle-dl ${lib.optionalString cfg.notifyOnly "--without-downloading-files"}";
ExecStartPre = pkgs.writers.writeDash "moodle-dl-config" "${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${toString moodle-dl-json} ${toString cfg.tokensFile} > ${cfg.directory}/config.json";
}
2025-12-27 22:22:54 +01:00
(mkIf (cfg.directory == stateDirectoryDefault) { StateDirectory = "moodle-dl"; })
];
inherit (cfg) startAt;
};
};
2025-12-27 22:22:54 +01:00
meta.maintainers = [ maintainers.kmein ];
}