1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.icecream.scheduler;
7in {
8
9 ###### interface
10
11 options = {
12
13 services.icecream.scheduler = {
14 enable = mkEnableOption "Icecream Scheduler";
15
16 netName = mkOption {
17 type = types.nullOr types.str;
18 default = null;
19 description = ''
20 Network name for the icecream scheduler.
21
22 Uses the default ICECREAM if null.
23 '';
24 };
25
26 port = mkOption {
27 type = types.port;
28 default = 8765;
29 description = ''
30 Server port to listen for icecream daemon requests.
31 '';
32 };
33
34 openFirewall = mkOption {
35 type = types.bool;
36 description = ''
37 Whether to automatically open the daemon port in the firewall.
38 '';
39 };
40
41 openTelnet = mkOption {
42 type = types.bool;
43 default = false;
44 description = ''
45 Whether to open the telnet TCP port on 8766.
46 '';
47 };
48
49 persistentClientConnection = mkOption {
50 type = types.bool;
51 default = false;
52 description = ''
53 Whether to prevent clients from connecting to a better scheduler.
54 '';
55 };
56
57 package = mkPackageOption pkgs "icecream" { };
58
59 extraArgs = mkOption {
60 type = types.listOf types.str;
61 default = [];
62 description = "Additional command line parameters";
63 example = [ "-v" ];
64 };
65 };
66 };
67
68 ###### implementation
69
70 config = mkIf cfg.enable {
71 networking.firewall.allowedTCPPorts = mkMerge [
72 (mkIf cfg.openFirewall [ cfg.port ])
73 (mkIf cfg.openTelnet [ 8766 ])
74 ];
75
76 systemd.services.icecc-scheduler = {
77 description = "Icecream scheduling server";
78 after = [ "network.target" ];
79 wantedBy = [ "multi-user.target" ];
80
81 serviceConfig = {
82 ExecStart = escapeShellArgs ([
83 "${getBin cfg.package}/bin/icecc-scheduler"
84 "-p" (toString cfg.port)
85 ]
86 ++ optionals (cfg.netName != null) [ "-n" (toString cfg.netName) ]
87 ++ optional cfg.persistentClientConnection "-r"
88 ++ cfg.extraArgs);
89
90 DynamicUser = true;
91 };
92 };
93 };
94
95 meta.maintainers = with lib.maintainers; [ emantor ];
96}