Skip to content

Commit

Permalink
reformat codebase with nix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 14, 2023
1 parent 05446b1 commit 49d51e9
Show file tree
Hide file tree
Showing 13 changed files with 1,074 additions and 1,046 deletions.
202 changes: 108 additions & 94 deletions checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,158 +2,172 @@
system,
packages,
pkgs,
}:

let
}: let
phpPackages = builtins.filter (name: builtins.match "php[0-9]+" name != null) (builtins.attrNames packages);

checks = {
php = {
description = "Build PHP";
drv = { php, ... }: php;
drv = {php, ...}: php;
};

imagick = {
description = "Build Imagick extension";
drv = { php, ... }: php.extensions.imagick;
drv = {php, ...}: php.extensions.imagick;
};

redis = {
description = "Build Redis extension";
drv = { php, ... }: php.extensions.redis;
drv = {php, ...}: php.extensions.redis;
};

redis3 = {
description = "Build Redis 3 extension";
enabled = { php, lib, ... }: lib.versionOlder php.version "8";
drv = { php, ... }: php.extensions.redis3;
enabled = {
php,
lib,
...
}:
lib.versionOlder php.version "8";
drv = {php, ...}: php.extensions.redis3;
};

mysql = {
description = "Build MySQL extension";
enabled = { php, lib, ... }: lib.versionOlder php.version "7";
drv = { php, ... }: php.extensions.mysql;
enabled = {
php,
lib,
...
}:
lib.versionOlder php.version "7";
drv = {php, ...}: php.extensions.mysql;
};

xdebug = {
description = "Build Xdebug extension";
drv = { php, ... }: php.extensions.xdebug;
drv = {php, ...}: php.extensions.xdebug;
};

tidy = {
description = "Build Tidy extension";
drv = { php, ... }: php.extensions.tidy;
drv = {php, ...}: php.extensions.tidy;
};

composer-phar = {
description = "Check that composer PHAR works";
drv =
{ pkgs, php, ... }:
drv = {
pkgs,
php,
...
}:
pkgs.runCommand
"composer-phar-check"
{
buildInputs = [
php.packages.composer
];
}
''
composer --version
touch "$out"
'';
"composer-phar-check"
{
buildInputs = [
php.packages.composer
];
}
''
composer --version
touch "$out"
'';
};

mysqli-socket-path = {
description = "Validate php.extensions.mysqli default unix socket path";
drv =
{ pkgs, php, ... }:
drv = {
pkgs,
php,
...
}:
pkgs.runCommand
"mysqli-socket-path-check"
{
buildInputs = [
(php.withExtensions ({ all, ... }: [
all.mysqli
]))
];
}
''
php -r "echo ini_get('mysqli.default_socket') . PHP_EOL;" | grep /run/mysqld/mysqld.sock
touch "$out"
'';
"mysqli-socket-path-check"
{
buildInputs = [
(php.withExtensions ({all, ...}: [
all.mysqli
]))
];
}
''
php -r "echo ini_get('mysqli.default_socket') . PHP_EOL;" | grep /run/mysqld/mysqld.sock
touch "$out"
'';
};

pdo_mysql-socket-path = {
description = "Validate php.extensions.pdo_mysql default unix socket path";
drv =
{ pkgs, php, ... }:
drv = {
pkgs,
php,
...
}:
pkgs.runCommand
"pdo_mysql-socket-path-check"
{
buildInputs = [
(php.withExtensions ({ all, ... }: [
all.pdo_mysql
]))
];
}
''
php -r "echo ini_get('pdo_mysql.default_socket') . PHP_EOL;" | grep /run/mysqld/mysqld.sock
touch "$out"
'';
"pdo_mysql-socket-path-check"
{
buildInputs = [
(php.withExtensions ({all, ...}: [
all.pdo_mysql
]))
];
}
''
php -r "echo ini_get('pdo_mysql.default_socket') . PHP_EOL;" | grep /run/mysqld/mysqld.sock
touch "$out"
'';
};
};

inherit (pkgs) lib;

/* AttrSet<phpName, AttrSet<checkName, checkDrv>> */
checksPerVersion =
lib.listToAttrs (
builtins.map
(phpName:
let
php = packages.${phpName};
phpVersion = lib.versions.majorMinor php.version;
args = { inherit lib php pkgs system; };
supportedChecks = lib.filterAttrs (_name: { enabled ? lib.const true, ... }: enabled args) checks;
in
{
name = phpName;
value =
lib.mapAttrs
(
_name:
{
description,
drv,
...
}:

let
check = drv args;
in
check // {
passthru = check.passthru or { } // {
description = "PHP ${phpVersion}${description}";
};
}
)
supportedChecks;
}
)
phpPackages
);
# AttrSet<phpName, AttrSet<checkName, checkDrv>>
checksPerVersion = lib.listToAttrs (
builtins.map
(
phpName: let
php = packages.${phpName};
phpVersion = lib.versions.majorMinor php.version;
args = {inherit lib php pkgs system;};
supportedChecks = lib.filterAttrs (_name: {enabled ? lib.const true, ...}: enabled args) checks;
in {
name = phpName;
value =
lib.mapAttrs
(
_name: {
description,
drv,
...
}: let
check = drv args;
in
check
// {
passthru =
check.passthru
or {}
// {
description = "PHP ${phpVersion}${description}";
};
}
)
supportedChecks;
}
)
phpPackages
);
in
lib.foldAttrs
lib.foldAttrs
lib.mergeAttrs
{}
(
lib.mapAttrsToList
(
phpName:

lib.mapAttrs'
lib.mapAttrs'
(
name:

lib.nameValuePair "${phpName}-${name}"
lib.nameValuePair "${phpName}-${name}"
)
)
checksPerVersion
Expand Down
19 changes: 11 additions & 8 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
src = ./.;
}).defaultNix
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
) {
src = ./.;
})
.defaultNix
16 changes: 11 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
utils.url = "github:numtide/flake-utils";
};

outputs = { self, flake-compat, nixpkgs, utils }:
# For each supported platform,
utils.lib.eachDefaultSystem (system:
let
outputs = {
self,
flake-compat,
nixpkgs,
utils,
}:
# For each supported platform,
utils.lib.eachDefaultSystem (
system: let
# Let’s merge the package set from Nixpkgs with our custom PHP versions.
pkgs = import nixpkgs.outPath {
config = {
Expand All @@ -38,7 +43,8 @@
inherit packages pkgs system;
};
}
) // {
)
// {
overlays.default = import ./pkgs/phps.nix nixpkgs.outPath;
};
}
60 changes: 33 additions & 27 deletions pkgs/composer/2.2.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
{ mkDerivation, fetchurl, makeWrapper, unzip, lib, php }:
let
{
mkDerivation,
fetchurl,
makeWrapper,
unzip,
lib,
php,
}: let
pname = "composer";
version = "2.2.12";
in
mkDerivation {
inherit pname version;
mkDerivation {
inherit pname version;

src = fetchurl {
url = "https://getcomposer.org/download/${version}/composer.phar";
sha256 = "sha256-HOkGh+s/iamcBZ1F3UGdCEMO0klGhUS5MrHa1/si3aA=";
};
src = fetchurl {
url = "https://getcomposer.org/download/${version}/composer.phar";
sha256 = "sha256-HOkGh+s/iamcBZ1F3UGdCEMO0klGhUS5MrHa1/si3aA=";
};

dontUnpack = true;
dontUnpack = true;

nativeBuildInputs = [ makeWrapper ];
nativeBuildInputs = [makeWrapper];

installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -D $src $out/libexec/composer/composer.phar
makeWrapper ${php}/bin/php $out/bin/composer \
--add-flags "$out/libexec/composer/composer.phar" \
--prefix PATH : ${lib.makeBinPath [ unzip ]}
runHook postInstall
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -D $src $out/libexec/composer/composer.phar
makeWrapper ${php}/bin/php $out/bin/composer \
--add-flags "$out/libexec/composer/composer.phar" \
--prefix PATH : ${lib.makeBinPath [unzip]}
runHook postInstall
'';

meta = with lib; {
description = "Dependency Manager for PHP";
license = licenses.mit;
homepage = "https://getcomposer.org/";
changelog = "https://github.com/composer/composer/releases/tag/${version}";
maintainers = with maintainers; [ offline ] ++ teams.php.members;
};
}
meta = with lib; {
description = "Dependency Manager for PHP";
license = licenses.mit;
homepage = "https://getcomposer.org/";
changelog = "https://github.com/composer/composer/releases/tag/${version}";
maintainers = with maintainers; [offline] ++ teams.php.members;
};
}
Loading

0 comments on commit 49d51e9

Please sign in to comment.