nixos-config/modules/phpipam.nix

132 lines
3.5 KiB
Nix
Raw Normal View History

2021-02-22 20:49:54 +00:00
{ config, pkgs, lib, ... }:
let
cfg = config.sconfig.phpipam;
2022-05-11 15:50:57 +00:00
version = "1.5.0";
2021-02-22 20:49:54 +00:00
phpipamHtdocs = pkgs.stdenv.mkDerivation {
inherit version;
pname = "phpipam-htdocs";
src = pkgs.fetchFromGitHub {
owner = "phpipam";
repo = "phpipam";
rev = "v${version}";
2022-05-11 15:50:57 +00:00
sha256 = "sha256-dbeOx7Tvg9wu3X4FYiAEfj91MEgsb7XX0axFadV7SR8=";
2021-02-23 15:15:31 +00:00
fetchSubmodules = true;
2021-02-22 20:49:54 +00:00
};
installPhase = ''
cp -r "$src" "$out"
chmod +w "$out"
2021-10-26 19:09:44 +00:00
echo '<?php
2021-10-26 20:22:35 +00:00
require("config.dist.php");
2022-05-11 15:50:57 +00:00
$db["host"] = "localhost";
2021-10-26 19:09:44 +00:00
$db["user"] = "nginx";
require("/etc/phpipam_config.php");' >"$out/config.php"
2021-02-22 20:49:54 +00:00
'';
};
in
{
options.sconfig.phpipam = {
enable = lib.mkEnableOption "Enable phpipam";
2021-10-26 18:04:24 +00:00
configFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
description = "Path to phpipam configuration file";
default = null;
};
2021-10-05 15:26:41 +00:00
hostname = lib.mkOption {
2021-02-22 20:49:54 +00:00
type = lib.types.str;
default = "localhost";
};
2021-10-05 15:26:41 +00:00
virtualHost = lib.mkOption {
type = lib.types.attrs;
default = { };
2021-02-22 20:49:54 +00:00
};
2022-12-14 03:33:09 +00:00
phpPackage = lib.mkOption {
type = lib.types.package;
default = pkgs.php;
};
2021-02-22 20:49:54 +00:00
};
config = lib.mkIf cfg.enable {
2021-10-26 18:04:24 +00:00
environment.etc."phpipam_config.php" =
if cfg.configFile == null
then { text = ""; }
else { source = cfg.configFile; };
2022-08-01 21:36:05 +00:00
systemd = {
services.phpipam-tasks = {
script = ''
2022-12-14 03:33:09 +00:00
${cfg.phpPackage}/bin/php ${phpipamHtdocs}/functions/scripts/pingCheck.php
${cfg.phpPackage}/bin/php ${phpipamHtdocs}/functions/scripts/discoveryCheck.php
${cfg.phpPackage}/bin/php ${phpipamHtdocs}/functions/scripts/remove_offline_addresses.php
2022-08-01 21:36:05 +00:00
'';
2021-02-22 20:49:54 +00:00
serviceConfig.User = "nginx";
2022-08-01 21:36:05 +00:00
};
2022-12-23 09:10:21 +00:00
timers.phpipam-tasks = {
timerConfig.OnBootSec = 900;
timerConfig.OnUnitInactiveSec = 900;
wantedBy = [ "timers.target" ];
};
2022-08-01 21:36:05 +00:00
};
2021-02-22 20:49:54 +00:00
services = {
2022-12-14 03:33:09 +00:00
phpfpm.phpPackage = cfg.phpPackage;
2021-02-22 20:49:54 +00:00
phpfpm.pools.www = {
user = "nginx";
group = "nginx";
phpEnv.PHP_INI_SCAN_DIR = "$PHP_INI_SCAN_DIR";
2021-02-22 21:26:20 +00:00
phpOptions = ''
date.timezone = America/New_York
max_execution_time = 600
'';
2021-02-22 20:49:54 +00:00
settings = {
"pm" = "ondemand";
"pm.max_children" = "8";
"listen.group" = "nginx";
"php_admin_value[error_log]" = "stderr";
"catch_workers_output" = "yes";
};
};
nginx = {
enable = true;
2021-10-05 15:26:41 +00:00
virtualHosts."${cfg.hostname}" = lib.mkMerge [
cfg.virtualHost
{
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 ${config.services.nginx.package}/conf/fastcgi.conf;
2021-10-05 15:26:41 +00:00
'';
}
];
2021-02-22 20:49:54 +00:00
};
mysql = {
enable = true;
package = pkgs.mariadb;
ensureDatabases = [ "phpipam" ];
ensureUsers = [{ name = "nginx"; ensurePermissions = { "phpipam.*" = "ALL PRIVILEGES"; }; }];
};
};
};
}