Gives us a start for workign on pelecan in nixos
This commit is contained in:
silver 2024-12-04 20:09:32 +00:00
parent 9001157fc6
commit b13683e40c
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
6 changed files with 309 additions and 0 deletions

View file

@ -0,0 +1,64 @@
{ inputs, pkgs, lib, config, ... }:
with lib; let
cfg = config.modules.pelican-panel;
dir = "/var/www/pelican";
in {
options = {
modules.pelican-panel = {
enable = mkEnableOption "Pelican Panel";
};
};
config = mkIf cfg.enable {
environment.systemPackages = [
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-install.nix { inherit pkgs; inherit dir; } )
( import ./pelican-update.nix { inherit pkgs; inherit dir; } )
];
systemd.timers."pelican-cron" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "1m";
Unit = "pelican-cron.service";
};
};
systemd.services."pelican-cron" = {
script = ''
${pkgs.php83}/bin/php ${dir}/artisan schedule:run >> /dev/null 2>&1
'';
serviceConfig = {
Type = "oneshot";
};
};
systemd.services.pelican-queue = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "nginx";
Group = "nginx";
Restart = "always";
ExecStart = "${pkgs.php83}/bin/php ${dir}/artisan queue:work --tries=3";
startLimitInterval = 180;
startLimitBurst = 30;
RestartSec = "5";
};
};
};
}

View file

@ -0,0 +1,28 @@
{ pkgs, dir }:
pkgs.writeShellScriptBin "pelican-install" ''
DIR=${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 nginx:nginx $DIR
echo "Pelican panel installed successfully"
''

View file

@ -0,0 +1,46 @@
{ pkgs, dir }:
pkgs.writeShellScriptBin "pelican-update" ''
DIR=${dir}
echo "Updateing Pelican panel in $DIR ..."
if [ -d $DIR ]; then
echo "Directory $DIR found, entering maintenance mode ..."
else
echo "Directory $DIR does not exist, exiting"
exit 1
fi
cd $DIR
php artisan down
echo "Downloading Pelican panel update ..."
curl -L https://github.com/pelican-dev/panel/releases/latest/download/panel.tar.gz | tar -xzv
echo "Setting permissions ..."
chmod -R 755 storage/* bootstrap/cache
echo "Updating Pelican panel using composer ..."
yes | composer install --no-dev --optimize-autoloader
echo "Clearing compiled template cache ..."
php artisan view:clear
php artisan config:clear
echo "Optimizing Pelican panel ..."
php artisan filament:optimize
echo "Updating the database ..."
php artisan migrate --seed --force
echo "Setting permissions ..."
chown -R nginx:nginx $DIR
echo "Restart Pelican queue service ..."
systemctl restart pelican-queue.service
echo "Exiting maintenance mode ..."
php artisan up
echo "Pelican panel updated successfully"
''