diff --git a/README.md b/README.md index d80425e..c20e564 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# pterodactyl-wings +# pterodactyl diff --git a/flake.nix b/flake.nix index aaae941..28030db 100644 --- a/flake.nix +++ b/flake.nix @@ -14,7 +14,60 @@ packages."aarch64-linux".default = self.packages."aarch64-linux".pterodactyl-wings; nixosModules.pterodactyl-panel = ./modules/panel.nix; - nixosModules.pterodactyl-wings = ./modules/wings.nix; + nixosModules.pterodactyl-wings = { 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 = self.packages.${pkgs.system}.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" ]; + }; + }; + }; + nixosModules.default = self.nixosModules.pterodactyl-wings; }; } diff --git a/modules/wings.nix b/modules/wings.nix index 36709e0..3247de2 100644 --- a/modules/wings.nix +++ b/modules/wings.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, pkgs, self, ... }: with lib; let configuration = '' @@ -16,7 +16,7 @@ in { }; pkg = mkOption { type = types.package; - default = pkgs.pterodactyl-wings; + default = self.packages.${pkgs.system}.pterodactyl-wings; }; };