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 "FlexGet daemon";
19 package = mkPackageOption pkgs "flexget" {};
23 example = "some_user";
25 description = "The user under which to run flexget.";
29 default = "/var/lib/deluge";
30 example = "/home/flexget";
32 description = "Where files live.";
39 description = "When to perform a {command}`flexget` run. See {command}`man 7 systemd.time` for the format.";
42 systemScheduler = mkOption {
46 description = "When true, execute the runs via the flexget-runner.timer. If false, you have to specify the settings yourself in the YML file.";
52 description = "The YAML configuration for FlexGet.";
57 config = mkIf cfg.enable {
59 environment.systemPackages = [ pkg ];
63 description = "FlexGet Daemon";
67 ExecStartPre = "${pkgs.coreutils}/bin/install -m644 ${ymlFile} ${configFile}";
68 ExecStart = "${pkg}/bin/flexget -c ${configFile} daemon start";
69 ExecStop = "${pkg}/bin/flexget -c ${configFile} daemon stop";
70 ExecReload = "${pkg}/bin/flexget -c ${configFile} daemon reload";
71 Restart = "on-failure";
73 WorkingDirectory = toString cfg.homeDir;
75 wantedBy = [ "multi-user.target" ];
78 flexget-runner = mkIf cfg.systemScheduler {
79 description = "FlexGet Runner";
80 after = [ "flexget.service" ];
81 wants = [ "flexget.service" ];
84 ExecStart = "${pkg}/bin/flexget -c ${configFile} execute";
86 WorkingDirectory = toString cfg.homeDir;
91 systemd.timers.flexget-runner = mkIf cfg.systemScheduler {
92 description = "Run FlexGet every ${cfg.interval}";
93 wantedBy = [ "timers.target" ];
96 OnUnitInactiveSec = cfg.interval;
97 Unit = "flexget-runner.service";