Skip to content

Commit

Permalink
pkgs: add adminer-pematon, adminer-pematon-with-adminer-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRTitor committed Nov 3, 2024
1 parent 2bc49d5 commit c6df6da
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
12 changes: 10 additions & 2 deletions flake/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ in {
# "aarch64-linux"
];

# Setting this option, allows formatting via `nix fmt`
perSystem = {pkgs, ...}: {
perSystem = {pkgs, self', ...}: {
# Setting this option, allows formatting via `nix fmt`
formatter = pkgs.alejandra;

# Packages defined in the flake, derivations usually reside in `../pkgs/`
# Use `nix flake show` to see the list of packages
# To access packages from this flake, use `self'.packages.<name>`
packages = {
fhs-shell = pkgs.callPackage ../pkgs/fhs-shell.nix {};
weather-python-script = pkgs.callPackage ../pkgs/weather-python-script.nix {};
adminer-pematon = pkgs.callPackage ../pkgs/adminer-pematon {};
adminer-pematon-with-adminer-theme = pkgs.callPackage ../pkgs/adminer-pematon-with-adminer-theme {
inherit (self'.packages) adminer-pematon;
};
};
};
}
22 changes: 22 additions & 0 deletions pkgs/adminer-pematon-with-adminer-theme/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
adminer-pematon,
fetchFromGitHub,
}:
adminer-pematon.overrideAttrs (finalAttrs: oldAttrs: {
pname = "adminer-pematon-with-adminer-theme";
adminerTheme = fetchFromGitHub {
owner = "pematon";
repo = "adminer-theme";
rev = "v1.8.1";
hash = "sha256-Ax0UfqBF7xzYDGU5OlYCxq+9SzvXw7/WI7GJiXpZXBk=";
};

# Installs the adminer theme
# Modifies the index.php to include the theme using sed
# 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
'';
})
72 changes: 72 additions & 0 deletions pkgs/adminer-pematon/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{ lib
, pkgs
, stdenvNoCC
, fetchFromGitHub
, php
, nix-update-script
, theme ? null
, plugins ? []
}:

stdenvNoCC.mkDerivation (finalAttrs: {
pname = "adminer-pematon";

version = "4.11";
src = fetchFromGitHub {
owner = "pematon";
repo = "adminer";
rev = "refs/tags/v${finalAttrs.version}";
hash = "sha256-tijqPTPEc2Sp4OORlGALKHFOpf/QJ36bbNja3d3mpOU=";
};

nativeBuildInputs = [
php
];

buildPhase = ''
runHook preBuild
php compile.php
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir $out
cp temp/export/adminer-${finalAttrs.version}.php $out/adminer.php
cp ${./index.php} $out/index.php
${lib.optionalString (theme != null) ''
cp designs/${theme}/adminer.css $out/adminer.css
''}
# Copy base plugin
mkdir -p $out/plugins
cp plugins/plugin.php $out/plugins/plugin.php
${lib.optionalString (plugins != []) ''
cp plugins/*.php $out/plugins/
cp ${pkgs.writeText "$out/plugins.json" ''
${toString (builtins.toJSON plugins)}
''} $out/plugins.json
''}
runHook postInstall
'';

passthru = {
updateScript = nix-update-script { };
};

meta = with lib; {
description = "Database management in a single PHP file";
homepage = "https://docs.adminerevo.org";
license = with licenses; [ asl20 gpl2Only ];
maintainers = with maintainers; [
shyim
];
platforms = platforms.all;
};
})
35 changes: 35 additions & 0 deletions pkgs/adminer-pematon/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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;
}
}
}

return new \AdminerPlugin($plugins);
}
}

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

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

0 comments on commit c6df6da

Please sign in to comment.