forked from nyanloutre/nixos-config
102 lines
2.8 KiB
Nix
102 lines
2.8 KiB
Nix
{ lib, config, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.site-musique;
|
|
in
|
|
{
|
|
options.services.site-musique = {
|
|
enable = mkEnableOption "Site musique";
|
|
|
|
port = mkOption {
|
|
type = types.int;
|
|
example = 54321;
|
|
description = "Local listening port";
|
|
};
|
|
|
|
domaine = mkOption {
|
|
type = types.str;
|
|
example = "example.com";
|
|
description = "Domaine à utiliser";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.haproxy-acme.services = {
|
|
${cfg.domaine} = { ip = "127.0.0.1"; port = cfg.port; auth = false; };
|
|
};
|
|
|
|
services.nginx.virtualHosts = {
|
|
"musique" = {
|
|
listen = [ { addr = "127.0.0.1"; port = cfg.port; } ];
|
|
locations."/" = {
|
|
root = "/run/site-musique/result";
|
|
index = "index.php";
|
|
extraConfig = ''
|
|
location ~* \.php$ {
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
fastcgi_pass unix:/run/phpfpm/musique;
|
|
include ${pkgs.nginx}/conf/fastcgi_params;
|
|
include ${pkgs.nginx}/conf/fastcgi.conf;
|
|
}
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
services.phpfpm.poolConfigs.musique = ''
|
|
listen = /run/phpfpm/musique
|
|
listen.owner = nginx
|
|
listen.group = nginx
|
|
listen.mode = 0660
|
|
user = nginx
|
|
pm = dynamic
|
|
pm.max_children = 75
|
|
pm.start_servers = 2
|
|
pm.min_spare_servers = 1
|
|
pm.max_spare_servers = 20
|
|
pm.max_requests = 500
|
|
php_admin_value[error_log] = 'stderr'
|
|
php_admin_flag[log_errors] = on
|
|
catch_workers_output = yes
|
|
'';
|
|
|
|
systemd.services.build-site-musique = {
|
|
description = "Compilation du site de la musique";
|
|
requires = ["network-online.target"];
|
|
path = with pkgs;[ git nix ];
|
|
environment = { HOME = "/var/lib/site-musique"; NIX_PATH = "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs"; };
|
|
|
|
serviceConfig = {
|
|
DynamicUser = true;
|
|
RuntimeDirectory = "site-musique";
|
|
RuntimeDirectoryPreserve = "yes";
|
|
CacheDirectory = "site-musique";
|
|
Type = "oneshot";
|
|
ExecStart = "${pkgs.writeShellScriptBin "build.sh" ''
|
|
set -x
|
|
set -e
|
|
GIT_CLONE_DIR=/var/cache/site-musique
|
|
|
|
if [ ! -d $GIT_CLONE_DIR/.git ]; then
|
|
git clone --depth 1 https://gitlab.com/nyanloutre/site-musique.git $GIT_CLONE_DIR
|
|
else
|
|
git -C $GIT_CLONE_DIR pull
|
|
fi
|
|
|
|
NIXPKGS_ALLOW_UNFREE=1 nix-build -o /run/site-musique/result $GIT_CLONE_DIR
|
|
''}/bin/build.sh";
|
|
};
|
|
};
|
|
|
|
systemd.timers.build-site-musique = {
|
|
description = "Timer de compilation du site de la musique";
|
|
requires = ["network-online.target"];
|
|
wantedBy = ["multi-user.target"];
|
|
timerConfig = { OnCalendar = "*:0/5"; Unit = "build-site-musique.service"; };
|
|
};
|
|
};
|
|
}
|