Skip to content

Commit

Permalink
configure adminer with the adminer package
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRTitor committed Nov 3, 2024
1 parent c6df6da commit dfd2d05
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
28 changes: 6 additions & 22 deletions home-manager/web-server-html/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# THIS ONLY PLACES THE CONFIG FILES, DOES NOT INSTALL NGINX
# For that see ../../dev-environment/nginx.nix
# Import of thie module is controlled by bool: servicesSettings.nginx
{pkgs, ...}:
{pkgs, self, ...}:
let
# Updated adminer
adminer-new = pkgs.fetchurl {
Expand All @@ -29,29 +29,13 @@ in {

# To use adminer, just type localhost/dbms/adminer.php in your browser
# This configuration automatically places the php file in the correct location
"Website-Instances/adminer/adminer.php".source = adminer-new;

# Adminer theme
"Website-Instances/adminer/index.php" = {
source = ./adminer/index.php;
};
"Website-Instances/adminer/css" = {
source = "${adminer-theme}/lib/css";
recursive = true;
};
"Website-Instances/adminer/fonts" = {
source = "${adminer-theme}/lib/fonts";
# Adminer pematon (new version) with adminer theme
# After any changes we need to restart the services
# systemctl restart phpfpm-mypool.service nginx.service
"Website-Instances/adminer" = {
source = self.packages.${pkgs.system}.adminer-pematon-with-adminer-theme;
recursive = true;
};
"Website-Instances/adminer/images" = {
source = "${adminer-theme}/lib/images";
recursive = true;
};
"Website-Instances/adminer/plugins/AdminerTheme.php" = {
source = "${adminer-theme}/lib/plugins/AdminerTheme.php";
};
"Website-Instances/adminer/plugins/plugin.php" = {
source = adminer-new-plugin-php;
};
};
}
4 changes: 2 additions & 2 deletions pkgs/adminer-pematon-with-adminer-theme/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ adminer-pematon.overrideAttrs (finalAttrs: oldAttrs: {
# substituteInPlace won't work here as it can't interprete \t \n
postInstall = (oldAttrs.postInstall or "") + ''
cp -r ${finalAttrs.adminerTheme}/lib/* $out/
sed -i '/return new \\AdminerPlugin($plugins);/i \\t $plugins[] = new AdminerTheme();' $out/index.php
rm $out/index.php
cp ${./index.php} $out/index.php
'';
})
44 changes: 44 additions & 0 deletions pkgs/adminer-pematon-with-adminer-theme/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace nixos {
function adminer_object() {
require_once(__DIR__ . '/plugins/plugin.php');

$plugins = [];
if (file_exists(__DIR__ . '/plugins.json')) {
$names = json_decode(file_get_contents(__DIR__ . '/plugins.json'), true);

foreach ($names as $name) {
$plugin = __DIR__ . '/plugins/' . $name . '.php';
if (is_readable($plugin)) {
require($plugin);

preg_match_all('/(\w+)/', $name, $matches);

$className = 'Adminer'. implode('', array_map('ucfirst', $matches[1]));

$plugins[] = new $className;
}
}
}

// Add AdminerTheme at the end of the plugins array
require_once(__DIR__ . '/plugins/AdminerTheme.php');
// Color variant can by specified in constructor parameter.
// or passed without a parameter to use the default color
// new \AdminerTheme("default-orange"),
// new \AdminerTheme("default-blue"),
// new \AdminerTheme("default-green", ["192.168.0.1" => "default-orange"]),
$plugins[] = new \AdminerTheme("default-green");

return new \AdminerPlugin($plugins);
}
}

namespace {
function adminer_object() {
return \nixos\adminer_object();
}

require(__DIR__ . '/adminer.php');
}

0 comments on commit dfd2d05

Please sign in to comment.