testing
This commit is contained in:
parent
6fbd9b2a6c
commit
548a9369ab
6 changed files with 205 additions and 73 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/result
|
12
flake.nix
12
flake.nix
|
@ -11,9 +11,13 @@
|
|||
);
|
||||
|
||||
packages = nixpkgs.lib.genAttrs [ "x86_64-linux" ] (
|
||||
system: nixpkgs.lib.genAttrs [ "pterodactyl" "php" "wings" ] (
|
||||
package: import ./packages/${package}.nix { pkgs = import nixpkgs { inherit system; }; };
|
||||
)
|
||||
});
|
||||
system: let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in rec {
|
||||
php = import ./packages/php.nix { inherit pkgs; };
|
||||
pterodactyl = import ./packages/pterodactyl.nix { inherit pkgs php; };
|
||||
wings = import ./packages/wings.nix { inherit pkgs; };
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,20 +2,36 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.pterodactyl;
|
||||
|
||||
flakePkgs = flake.outputs.packages.${pkgs.system};
|
||||
thisConfig = config.services.pterodactyl;
|
||||
|
||||
defaultUser = "pterodactyl";
|
||||
in {
|
||||
options.services.pterodactyl = {
|
||||
enable = lib.mkEnableOption "Enable the pterodacytl game server panel";
|
||||
|
||||
proxy = {
|
||||
enable = lib.mkEnableOption "Automatically configure Nginx to serve the panel";
|
||||
serverName = lib.mkOption {
|
||||
pkg = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
description = "The package in which to source the php files used by pterodactyl";
|
||||
default = flake.outputs.packages.${pkgs.system}.pterodactyl;
|
||||
};
|
||||
|
||||
dataDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The directory in which to store stateful data";
|
||||
default = "/var/lib/pterodactyl";
|
||||
};
|
||||
|
||||
server = {
|
||||
enable = lib.mkEnableOption ''
|
||||
Automatically configure Nginx to serve the panel
|
||||
|
||||
If you need more control over the nginx proxy, for now you must leave this option disabled
|
||||
and write your own nginx configuration. Feel free to copy ours as a starting point.
|
||||
'';
|
||||
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The canonical domain on which the panel will be hosted";
|
||||
description = "The canonical domain name on which the panel will be hosted";
|
||||
default = "localhost";
|
||||
example = "pterodactyl.example.com";
|
||||
};
|
||||
|
@ -27,27 +43,64 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The user that owns the files managed by the panel.
|
||||
If you change this, make sure their files are accessible by your www user
|
||||
(probably "nginx").
|
||||
'';
|
||||
default = defaultUser;
|
||||
example = defaultUser;
|
||||
};
|
||||
php = {
|
||||
socket = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
description = "The location of the unix socket used by php-fpm";
|
||||
default = config.services.phpfpm.pools.pterodactyl.socket;
|
||||
};
|
||||
|
||||
pkg = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
description = "The package in which to source the php files used by pterodactyl";
|
||||
default = flakePkgs.pterodactyl;
|
||||
};
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The user that the php-fpm processes will run under. See also the `group` option.
|
||||
|
||||
dataDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The directory in which to store stateful data";
|
||||
default = "/var/lib/pterodactyl";
|
||||
If you change this, make sure the unix socket is accessible by your www user
|
||||
(probably "nginx").
|
||||
'';
|
||||
default = defaultUser;
|
||||
};
|
||||
|
||||
group = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The group that the php-fpm processes will run under. See also the `user` option.
|
||||
|
||||
If you change this, make sure the unix socket is accessible by your www user
|
||||
(probably "nginx").
|
||||
'';
|
||||
default = defaultUser;
|
||||
};
|
||||
|
||||
home = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
description = ''
|
||||
Where Pterodactyl stores its stateful data is hardcoded to be right next to its php
|
||||
scripts. But since we'd like to store the latter in the nix store and the nix store is
|
||||
immutable, we have to find a workaround.
|
||||
|
||||
So, the directory pointed to by this option will be where we instruct php to find its
|
||||
scripts and data. And the actual files will be simlinked to from this directory, so we can
|
||||
actually store them in a different location.
|
||||
'';
|
||||
default = "/var/lib/pterodactyl/";
|
||||
};
|
||||
|
||||
manageHome = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Whether or not to automatically create the symlinks
|
||||
|
||||
See services.pterodactyl.php.home for details.
|
||||
'';
|
||||
default = true;
|
||||
};
|
||||
|
||||
pkg = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
description = "The php package to use";
|
||||
default = flake.outputs.packages.${pkgs.system}.php;
|
||||
};
|
||||
};
|
||||
|
||||
redis = {
|
||||
|
@ -67,29 +120,37 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
users = lib.mkIf (cfg.user == defaultUser) {
|
||||
users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
createHome = true;
|
||||
home = cfg.dataDir;
|
||||
group = cfg.user;
|
||||
config = lib.mkIf thisConfig.enable {
|
||||
users = {
|
||||
users = {
|
||||
${thisConfig.php.user} = lib.mkIf (thisConfig.php.user == defaultUser) {
|
||||
isSystemUser = true;
|
||||
createHome = true;
|
||||
home = thisConfig.php.home;
|
||||
group = thisConfig.php.group;
|
||||
};
|
||||
|
||||
${config.services.nginx.user} = lib.mkIf (thisConfig.php.group == defaultUser) {
|
||||
extraGroups = [ thisConfig.php.group ];
|
||||
};
|
||||
};
|
||||
|
||||
groups.${cfg.user} = { };
|
||||
|
||||
users.${config.services.nginx.user}.extraGroups = [ cfg.user ];
|
||||
groups = {
|
||||
${thisConfig.php.group} = lib.mkIf (thisConfig.php.group == defaultUser) {};
|
||||
};
|
||||
};
|
||||
|
||||
services.redis.servers.${cfg.redis.name} = lib.mkIf cfg.redis.configureLocally {
|
||||
services.redis.servers.${thisConfig.redis.name} = lib.mkIf thisConfig.redis.configureLocally {
|
||||
enable = true;
|
||||
port = cfg.redis.port;
|
||||
port = thisConfig.redis.port;
|
||||
};
|
||||
|
||||
services.nginx = lib.mkIf cfg.proxy.enable {
|
||||
services.nginx = lib.mkIf thisConfig.server.enable {
|
||||
enable = true;
|
||||
|
||||
virtualHosts."${cfg.serverName}" = {
|
||||
virtualHosts."pterodactyl" = {
|
||||
serverName = thisConfig.server.name;
|
||||
|
||||
root = "${config.services.pterodactyl.pkg}/public";
|
||||
|
||||
extraConfig = ''
|
||||
|
@ -101,7 +162,7 @@ in {
|
|||
include ${pkgs.nginx}/conf/fastcgi_params;
|
||||
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass unix:${config.services.phpfpm.pools.pterodactyl.socket};
|
||||
fastcgi_pass unix:${thisConfig.php.socket};
|
||||
|
||||
fastcgi_index index.php;
|
||||
|
||||
|
@ -127,7 +188,7 @@ in {
|
|||
};
|
||||
|
||||
services.phpfpm.pools.pterodactyl = {
|
||||
user = cfg.user;
|
||||
user = thisConfig.php.user;
|
||||
settings = {
|
||||
"listen.owner" = config.services.nginx.user;
|
||||
"pm" = "dynamic";
|
||||
|
@ -145,21 +206,80 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
systemd.services.pteroq = {
|
||||
enable = true;
|
||||
description = "Pterodactyl Queue Worker";
|
||||
after = [ "redis-${cfg.redis.name}.service" ];
|
||||
unitConfig = { StartLimitInterval = 180; };
|
||||
serviceConfig = {
|
||||
User = cfg.user;
|
||||
Group = cfg.user;
|
||||
Restart = "always";
|
||||
ExecStart =
|
||||
"${flakePkgs.php}/bin/php ${cfg.pkg}/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3";
|
||||
StartLimitBurst = 30;
|
||||
RestartSec = "5s";
|
||||
|
||||
systemd = {
|
||||
tmpfiles.settings."10-pterodactyl" = lib.mkIf thisConfig.php.manageHome (let
|
||||
home = thisConfig.php.home;
|
||||
src = "${thisConfig.pkg}/share/php/pterodactyl-panel";
|
||||
data = thisConfig.dataDir;
|
||||
|
||||
user = thisConfig.php.user;
|
||||
group = thisConfig.php.group;
|
||||
in {
|
||||
"${data}/cache" = { "d" = { inherit group user; mode = "750"; }; };
|
||||
"${data}/storage" = { "d" = { inherit group user; mode = "750"; }; };
|
||||
});
|
||||
|
||||
services = {
|
||||
pterodactyl-setup = {
|
||||
description = "Setup the necessary files for the pterodactyl panel to work";
|
||||
|
||||
before = [ "pteroq.system" ]
|
||||
++ if thisConfig.server.enable then [ "nginx.service" ] else [];
|
||||
wantedBy = [ "multi-user.target" "pteroq.system" ]
|
||||
++ if thisConfig.server.enable then [ "nginx.service" ] else [];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
|
||||
User = thisConfig.php.user;
|
||||
Group = thisConfig.php.group;
|
||||
|
||||
ExecStart = "/bin/bash ${pkgs.writeScript "pterodactyl-setup.sh" ''
|
||||
#!/bin/bash
|
||||
|
||||
SRC="${thisConfig.pkg}/share/php/pterodactyl-panel/";
|
||||
HOME="${thisConfig.php.home}";
|
||||
|
||||
USER="${thisConfig.php.user}";
|
||||
GROUP="${thisConfig.php.group}";
|
||||
|
||||
rm $HOME/* -r;
|
||||
|
||||
mkdir -p -m 0770 "$HOME";
|
||||
mkdir -p -m 0550 "$HOME/bootstrap"
|
||||
|
||||
for file in app bootstrap config database public resources routes vendor artisan bootstrap/app.php; do
|
||||
cp -r "$SRC/$file" "$HOME"
|
||||
chmod -R 0550 "$HOME/$file"
|
||||
done;
|
||||
|
||||
ln -sf "${thisConfig.dataDir}/cache" "$HOME/bootstrap/cache";
|
||||
ln -sf "${thisConfig.dataDir}/storage" "$HOME/storage";
|
||||
''}";
|
||||
};
|
||||
};
|
||||
|
||||
pteroq = {
|
||||
enable = true;
|
||||
description = "Pterodactyl Queue Worker";
|
||||
after = [ "redis-${thisConfig.redis.name}.service" ];
|
||||
unitConfig = { StartLimitInterval = 180; };
|
||||
serviceConfig = {
|
||||
User = thisConfig.php.user;
|
||||
Group = thisConfig.php.group;
|
||||
|
||||
WorkingDirectory = thisConfig.php.home;
|
||||
|
||||
ExecStart = "${thisConfig.php.pkg}/bin/php ${thisConfig.php.home}/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3";
|
||||
|
||||
Restart = "always";
|
||||
RestartSec = "5s";
|
||||
StartLimitBurst = 30;
|
||||
};
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
};
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{ pkgs }:
|
||||
{ pkgs ? import <nixpkgs> }:
|
||||
|
||||
pkgs.php83.buildEnv {
|
||||
extensions = { enabled, all, }: enabled ++ (with all; [
|
||||
redis
|
||||
# xdebug
|
||||
xdebug
|
||||
]);
|
||||
|
||||
# extraConfig = ''
|
||||
# xdebug.mode=debug
|
||||
# '';
|
||||
extraConfig = ''
|
||||
xdebug.mode=debug
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
{ pkgs }:
|
||||
{ pkgs ? import <nixpkgs>, php ? pkgs.php }:
|
||||
|
||||
let
|
||||
php.buildComposerProject2 (finalAttrs: {
|
||||
pname = "pterodactyl-panel";
|
||||
version = "1.11.11";
|
||||
in pkgs.fetchzip {
|
||||
url = "https://github.com/pterodactyl/panel/releases/download/v${ version }/panel.tar.gz";
|
||||
hash = "sha256-0nOHtReVUVXYQY/glS4x0gkbhetoXSWg4rRwOJlkcM8=";
|
||||
stripRoot = false;
|
||||
}
|
||||
|
||||
src = pkgs.fetchzip {
|
||||
url = "https://github.com/pterodactyl/panel/releases/download/v${finalAttrs.version}/panel.tar.gz";
|
||||
hash = "sha256-0nOHtReVUVXYQY/glS4x0gkbhetoXSWg4rRwOJlkcM8=";
|
||||
stripRoot = false;
|
||||
};
|
||||
|
||||
vendorHash = "sha256-WBzGGWCWNqvU4Ws7wBh8Ads7RBawBaxN1QNIUI4ivOQ=";
|
||||
|
||||
inherit php;
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs }:
|
||||
{ pkgs ? import <nixpkgs> }:
|
||||
|
||||
let
|
||||
version = "1.11.13";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue