pterodactyl/modules/wings.nix

54 lines
1.6 KiB
Nix

{ lib, config, pkgs, ... }:
with lib;
let
configuration = ''
# managed by NixOS
'' + "${config.services.wings.configuration}";
in {
options.services.wings = {
enable = mkOption {
type = types.bool;
default = false;
};
configuration = mkOption {
type = types.str;
default = null;
};
pkg = mkOption {
type = types.package;
default = pkgs.pterodactyl-wings;
};
};
config = mkIf config.services.wings.enable {
assertions = [{
assertion = config.services.wings.configuration != null;
message = "wings is enabled, configuration must be set.";
}];
virtualisation.docker.enable = true;
environment.etc."pterodactyl/config.yml".text = configuration;
environment.systemPackages = [ config.services.wings.pkg ];
systemd.services.wings = {
enable = cfg.enable;
description = "Pterodactyl Wings daemon";
after = [ "docker.service" ];
partOf = [ "docker.service" ];
requires = [ "docker.service" ];
startLimitIntervalSec = 180;
startLimitBurst = 30;
serviceConfig = {
User = "root";
WorkingDirectory = "/run/wings";
LimitNOFILE = 4096;
PIDFile = "/var/run/wings/daemon.pid";
ExecStart =
"/bin/sh -c '/usr/bin/env mkdir /run/wings; /usr/bin/env cat /etc/pterodactyl/config.yml > /run/wings/config.yml; ${config.services.wings.pkg}/bin/wings --config /run/wings/config.yml'";
Restart = "on-failure";
RestartSec = "5s";
};
wantedBy = [ "multi-user.target" ];
};
};
}