1 { config, lib, pkgs, ... }:
6 cfg = config.services.pixiecore;
9 meta.maintainers = with maintainers; [ bbigras ];
12 services.pixiecore = {
13 enable = mkEnableOption "Pixiecore";
15 openFirewall = mkOption {
19 Open ports (67, 69, 4011 UDP and 'port', 'statusPort' TCP) in the firewall for Pixiecore.
24 description = "Which mode to use";
26 type = types.enum [ "api" "boot" "quick" ];
32 description = "Log more things that aren't directly related to booting a recognized client";
35 dhcpNoBind = mkOption {
38 description = "Handle DHCP traffic without binding to the DHCP server port";
42 description = "Which quick option to use";
44 type = types.enum [ "arch" "centos" "coreos" "debian" "fedora" "ubuntu" "xyz" ];
48 type = types.str or types.path;
50 description = "Kernel path. Ignored unless mode is set to 'boot'";
54 type = types.str or types.path;
56 description = "Initrd path. Ignored unless mode is set to 'boot'";
62 description = "Kernel commandline arguments. Ignored unless mode is set to 'boot'";
68 description = "IPv4 address to listen on";
74 description = "Port to listen on for HTTP";
77 statusPort = mkOption {
80 description = "HTTP port for status information (can be the same as --port)";
83 apiServer = mkOption {
85 example = "http://localhost:8080";
86 description = "URI to connect to the API. Ignored unless mode is set to 'api'";
89 extraArguments = mkOption {
90 type = types.listOf types.str;
92 description = "Additional command line arguments to pass to Pixiecore";
97 config = mkIf cfg.enable {
98 users.groups.pixiecore = {};
99 users.users.pixiecore = {
100 description = "Pixiecore daemon user";
105 networking.firewall = mkIf cfg.openFirewall {
106 allowedTCPPorts = [ cfg.port cfg.statusPort ];
107 allowedUDPPorts = [ 67 69 4011 ];
110 systemd.services.pixiecore = {
111 description = "Pixiecore server";
112 after = [ "network.target"];
113 wants = [ "network.target"];
114 wantedBy = [ "multi-user.target"];
118 AmbientCapabilities = [ "cap_net_bind_service" ] ++ optional cfg.dhcpNoBind "cap_net_raw";
122 if cfg.mode == "boot"
123 then [ "boot" cfg.kernel ]
124 ++ optional (cfg.initrd != "") cfg.initrd
125 ++ optionals (cfg.cmdLine != "") [ "--cmdline" cfg.cmdLine ]
126 else if cfg.mode == "quick"
127 then [ "quick" cfg.quick ]
128 else [ "api" cfg.apiServer ];
131 ${pkgs.pixiecore}/bin/pixiecore \
132 ${lib.escapeShellArgs argString} \
133 ${optionalString cfg.debug "--debug"} \
134 ${optionalString cfg.dhcpNoBind "--dhcp-no-bind"} \
135 --listen-addr ${lib.escapeShellArg cfg.listen} \
136 --port ${toString cfg.port} \
137 --status-port ${toString cfg.statusPort} \
138 ${escapeShellArgs cfg.extraArguments}