Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default nix formatter and its corresponding Github action #190

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/nix-fmt-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Nix formatter checks

on:
pull_request:

jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Nix
uses: cachix/install-nix-action@v18

- name: Run nix formatter tool
run: nix fmt . -- --check
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
18 changes: 13 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,
Copy link
Member

@jtojnar jtojnar Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misaligned. Edit: Reported in kamadorueda/alejandra#372 (comment)

utils.lib.eachDefaultSystem (
system: let
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving let to the same line as parameters is IMO inconsistent with indenting function bodies and makes visually scanning code harder (especially when the parameter list is long).

# Let’s merge the package set from Nixpkgs with our custom PHP versions.
pkgs = import nixpkgs.outPath {
config = {
Expand All @@ -28,6 +33,8 @@
];
};
in rec {
formatter = pkgs.alejandra;

packages = {
inherit (pkgs) php php56 php70 php71 php72 php73 php74 php80 php81 php82;
};
Expand All @@ -36,7 +43,8 @@
inherit packages pkgs system;
};
}
) // {
)
// {
overlays.default = import ./pkgs/phps.nix nixpkgs.outPath;
};
}
Loading