1 { config, lib, pkgs, ... }:
6 cfg = config.services.flexget;
8 ymlFile = pkgs.writeText "flexget.yml" ''
11 ${optionalString cfg.systemScheduler "schedules: no"}
13 configFile = "${toString cfg.homeDir}/flexget.yml";
17 enable = mkEnableOption (lib.mdDoc "Run FlexGet Daemon");
21 example = "some_user";
23 description = lib.mdDoc "The user under which to run flexget.";
27 default = "/var/lib/deluge";
28 example = "/home/flexget";
30 description = lib.mdDoc "Where files live.";
37 description = lib.mdDoc "When to perform a {command}`flexget` run. See {command}`man 7 systemd.time` for the format.";
40 systemScheduler = mkOption {
44 description = lib.mdDoc "When true, execute the runs via the flexget-runner.timer. If false, you have to specify the settings yourself in the YML file.";
50 description = lib.mdDoc "The YAML configuration for FlexGet.";
55 config = mkIf cfg.enable {
57 environment.systemPackages = [ pkg ];
61 description = "FlexGet Daemon";
65 Environment = "TZ=${config.time.timeZone}";
66 ExecStartPre = "${pkgs.coreutils}/bin/install -m644 ${ymlFile} ${configFile}";
67 ExecStart = "${pkg}/bin/flexget -c ${configFile} daemon start";
68 ExecStop = "${pkg}/bin/flexget -c ${configFile} daemon stop";
69 ExecReload = "${pkg}/bin/flexget -c ${configFile} daemon reload";
70 Restart = "on-failure";
72 WorkingDirectory = toString cfg.homeDir;
74 wantedBy = [ "multi-user.target" ];
77 flexget-runner = mkIf cfg.systemScheduler {
78 description = "FlexGet Runner";
79 after = [ "flexget.service" ];
80 wants = [ "flexget.service" ];
83 ExecStart = "${pkg}/bin/flexget -c ${configFile} execute";
85 WorkingDirectory = toString cfg.homeDir;
90 systemd.timers.flexget-runner = mkIf cfg.systemScheduler {
91 description = "Run FlexGet every ${cfg.interval}";
92 wantedBy = [ "timers.target" ];
95 OnUnitInactiveSec = cfg.interval;
96 Unit = "flexget-runner.service";