add phpipam module

This commit is contained in:
Sean Buckley 2021-02-22 15:49:54 -05:00
parent ca3d772875
commit a6e97617b8
2 changed files with 118 additions and 0 deletions

View file

@ -30,6 +30,7 @@ in
./modules/baseline.nix ./modules/baseline.nix
./modules/cli.nix ./modules/cli.nix
./modules/flakes.nix ./modules/flakes.nix
./modules/phpipam.nix
./modules/scansnap_s1300.nix ./modules/scansnap_s1300.nix
./modules/scroll-boost ./modules/scroll-boost
./modules/status-on-console.nix ./modules/status-on-console.nix

117
modules/phpipam.nix Normal file
View file

@ -0,0 +1,117 @@
{ config, pkgs, lib, ... }:
let
cfg = config.sconfig.phpipam;
version = "1.4.2";
phpipamHtdocs = pkgs.stdenv.mkDerivation {
inherit version;
pname = "phpipam-htdocs";
src = pkgs.fetchFromGitHub {
owner = "phpipam";
repo = "phpipam";
rev = "v${version}";
sha256 = "1mm2f8a63m3rvhwbls4099dskr42rip3khbqiq3vix5r1647wg71";
};
installPhase = ''
cp -r "$src" "$out"
chmod +w "$out"
mv "$out/config.docker.php" "$out/config.php"
'';
};
in
{
options.sconfig.phpipam = {
enable = lib.mkEnableOption "Enable phpipam";
domainName = lib.mkOption {
type = lib.types.str;
default = "localhost";
};
useTLS = lib.mkOption {
type = lib.types.bool;
default = false;
};
certificatePath = lib.mkOption {
type = lib.types.str;
default = "/etc/nixos/phpipam.crt";
};
certificateKeyPath = lib.mkOption {
type = lib.types.str;
default = "/etc/nixos/phpipam.key";
};
};
config = lib.mkIf cfg.enable {
systemd.services = {
phpipam_ping = {
script = "exec ${pkgs.php}/bin/php ${phpipamHtdocs}/functions/scripts/pingCheck.php";
environment.IPAM_DATABASE_USER = "nginx";
serviceConfig.User = "nginx";
startAt = "*:0/15";
};
phpipam_discovery = {
script = "exec ${pkgs.php}/bin/php ${phpipamHtdocs}/functions/scripts/discoveryCheck.php";
environment.IPAM_DATABASE_USER = "nginx";
serviceConfig.User = "nginx";
startAt = "*:0/15";
};
};
services = {
phpfpm.pools.www = {
user = "nginx";
group = "nginx";
phpEnv.IPAM_DATABASE_USER = "nginx";
phpEnv.PHP_INI_SCAN_DIR = "$PHP_INI_SCAN_DIR";
phpOptions = "date.timezone = America/New_York";
settings = {
"pm" = "ondemand";
"pm.max_children" = "8";
"listen.group" = "nginx";
"php_admin_value[error_log]" = "stderr";
"catch_workers_output" = "yes";
};
};
nginx = {
enable = true;
virtualHosts."${cfg.domainName}" = {
addSSL = cfg.useTLS;
sslCertificate = cfg.certificatePath;
sslCertificateKey = cfg.certificateKeyPath;
extraConfig = "access_log syslog:server=unix:/dev/log;";
root = phpipamHtdocs;
locations."/".extraConfig = ''
try_files $uri $uri/ /index.php; index index.php;
'';
locations."/api/".extraConfig = ''
try_files $uri $uri/ /api/index.php;
'';
locations."~ \\.php$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools.www.socket};
fastcgi_index index.php;
try_files $uri $uri/ index.php = 404;
include ${pkgs.nginx}/conf/fastcgi.conf;
'';
};
};
mysql = {
enable = true;
package = pkgs.mariadb;
ensureDatabases = [ "phpipam" ];
ensureUsers = [{ name = "nginx"; ensurePermissions = { "phpipam.*" = "ALL PRIVILEGES"; }; }];
};
};
};
}