diff --git a/applications/pelican/pelican.nix b/applications/pelican/pelican.nix index 32dadb6..4360334 100644 --- a/applications/pelican/pelican.nix +++ b/applications/pelican/pelican.nix @@ -10,6 +10,30 @@ with lib; let cfg = config.services.skynet."${name}"; php_pool = name; domain_panel = "${cfg.panel.domain.sub}.${cfg.panel.domain.base}.${cfg.panel.domain.tld}"; + + packages = let + dir = cfg.panel.dir; + in [ + pkgs.curl + pkgs.gnutar + pkgs.unzip + pkgs.gzip + pkgs.php83 + pkgs.php83Packages.composer + pkgs.php83Extensions.gd + pkgs.php83Extensions.mysqli + pkgs.php83Extensions.mbstring + pkgs.php83Extensions.bcmath + pkgs.php83Extensions.xml + pkgs.php83Extensions.curl + pkgs.php83Extensions.zip + pkgs.php83Extensions.intl + pkgs.php83Extensions.sqlite3 + (import ./pelican-panel-update.nix { + inherit pkgs; + inherit dir; + }) + ]; in { imports = [ ]; @@ -66,32 +90,7 @@ in { } ]; - environment.systemPackages = let - dir = cfg.panel.dir; - in [ - pkgs.curl - pkgs.gnutar - pkgs.unzip - pkgs.php83 - pkgs.php83Packages.composer - pkgs.php83Extensions.gd - pkgs.php83Extensions.mysqli - pkgs.php83Extensions.mbstring - pkgs.php83Extensions.bcmath - pkgs.php83Extensions.xml - pkgs.php83Extensions.curl - pkgs.php83Extensions.zip - pkgs.php83Extensions.intl - pkgs.php83Extensions.sqlite3 - (import ./pelican-panel-install.nix { - inherit pkgs; - inherit dir; - }) - (import ./pelican-panel-update.nix { - inherit pkgs; - inherit dir; - }) - ]; + environment.systemPackages = packages; systemd.timers."pelican-cron" = { wantedBy = ["timers.target"]; @@ -124,6 +123,46 @@ in { }; }; + systemd.services.pelican-panel-setup = { + wantedBy = ["pelican-queue.target" "pelican-cron.target"]; + partOf = []; + path = packages; + serviceConfig = { + Type = "oneshot"; + User = "root"; + Group = "root"; + TimeoutSec = "infinity"; + Restart = "on-failure"; + RemainAfterExit = true; + ExecStart = pkgs.writeShellScript "pelican-panel-install" '' + DIR=${cfg.panel.dir} + + echo "Installing Pelican panel to $DIR ..." + if [ -d $DIR ]; then + echo "Directory $DIR already exists, exiting" + exit 1 + fi + echo "Creating directory ..." + mkdir -p $DIR + cd $DIR + + echo "Downloading Pelican panel ..." + curl -L https://github.com/pelican-dev/panel/releases/latest/download/panel.tar.gz | tar -xzv + echo "Installing Pelican panel using composer ..." + yes | composer install --no-dev --optimize-autoloader + + echo "Setting up the environment ..." + yes "" | php artisan p:environment:setup + + echo "Setting permissions ..." + chmod -R 755 storage/* bootstrap/cache/ + chown -R ${config.services.nginx.user}:${config.services.nginx.group} $DIR + + echo "Pelican panel installed successfully" + ''; + }; + }; + services.phpfpm.pools.${php_pool} = { user = config.services.nginx.user; group = config.services.nginx.group;