mirror of
https://codeberg.org/icewind/flakelight-php.git
synced 2026-06-03 09:54:20 +02:00
initial version
This commit is contained in:
commit
1eceb2ce73
8 changed files with 428 additions and 0 deletions
138
flakelight-php.nix
Normal file
138
flakelight-php.nix
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
# mill-scale -- Another rust module for flakelight
|
||||
# Copyright (C) 2024 Robin Appelman <robin@icewind.nl>
|
||||
# SPDX-License-Identifier: MIT
|
||||
{
|
||||
lib,
|
||||
src,
|
||||
config,
|
||||
flakelight,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) elem readFile pathExists match any concatLists fromJSON attrNames head;
|
||||
inherit (lib) getExe map mkDefault mkIf mkMerge mkOption warnIf optionalAttrs types optionalString genAttrs hasInfix makeSearchPathOutput;
|
||||
inherit (lib.fileset) fileFilter toSource unions;
|
||||
inherit (flakelight.types) fileset function optFunctionTo;
|
||||
|
||||
phpVersions = {
|
||||
"5.6" = pkgs: pkgs.php56;
|
||||
"7.0" = pkgs: pkgs.php70;
|
||||
"7.1" = pkgs: pkgs.php71;
|
||||
"7.2" = pkgs: pkgs.php72;
|
||||
"7.3" = pkgs: pkgs.php73;
|
||||
"7.4" = pkgs: pkgs.php74;
|
||||
"8.0" = pkgs: pkgs.php80;
|
||||
"8.1" = pkgs: pkgs.php81;
|
||||
"8.2" = pkgs: pkgs.php82;
|
||||
"8.3" = pkgs: pkgs.php83;
|
||||
"8.4" = pkgs: pkgs.php84;
|
||||
};
|
||||
|
||||
filteredSrc = toSource {
|
||||
root = src;
|
||||
fileset = unions (config.extraPaths ++ [config.fileset]);
|
||||
};
|
||||
|
||||
composerJson = fromJSON (readFile config.composerJson);
|
||||
composerMeta =
|
||||
(import ./composer-meta.nix {
|
||||
inherit lib;
|
||||
allVersions = attrNames phpVersions;
|
||||
})
|
||||
composerJson;
|
||||
hasPsalm = pathExists config.psalmConfig;
|
||||
hasPhpCsFixer = pathExists config.phpCsFixerConfig;
|
||||
buildPhp = pkgs:
|
||||
(phpVersions.${head composerMeta.phpVersions} pkgs).buildEnv {
|
||||
extensions = {
|
||||
enabled,
|
||||
all,
|
||||
}:
|
||||
enabled ++ (config.phpExtensions all);
|
||||
};
|
||||
in
|
||||
warnIf (! builtins ? readFileType) "Unsupported Nix version in use."
|
||||
{
|
||||
options = {
|
||||
composerJson = mkOption {
|
||||
type = with types; path;
|
||||
default = src + /composer.json;
|
||||
};
|
||||
composerLock = mkOption {
|
||||
type = with types; path;
|
||||
default = src + /composer.lock;
|
||||
};
|
||||
psalmConfig = mkOption {
|
||||
type = with types; path;
|
||||
default = src + /psalm.xml;
|
||||
};
|
||||
phpCsFixerConfig = mkOption {
|
||||
type = with types; path;
|
||||
default = src + /.php-cs-fixer.dist.php;
|
||||
};
|
||||
extraPaths = mkOption {
|
||||
type = with types; listOf path;
|
||||
default = [];
|
||||
};
|
||||
fileset = mkOption {
|
||||
type = fileset;
|
||||
default =
|
||||
fileFilter
|
||||
(file:
|
||||
file.hasExt "php"
|
||||
|| match "snapshot__.*\.snap" file.name != null
|
||||
|| elem file.name [".php-cs-fixer.dist.php" "psalm.xml" "package.json" "package.lock"])
|
||||
src;
|
||||
};
|
||||
phpExtensions = mkOption {
|
||||
type = function;
|
||||
default = all: [];
|
||||
description = "extra php extensions to enable";
|
||||
};
|
||||
tools = mkOption {
|
||||
type = function;
|
||||
default = pkgs: [];
|
||||
description = "extra packages to make available in the dev shells";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkMerge [
|
||||
(mkIf (pathExists config.composerJson) {
|
||||
withOverlays = [
|
||||
(final: prev: {
|
||||
minPhp = buildPhp final;
|
||||
inherit (final.minPhp.packages) php-cs-fixer composer;
|
||||
})
|
||||
];
|
||||
|
||||
description = mkIf (composerMeta ? description) composerMeta.description;
|
||||
license = mkIf (composerMeta ? license) (mkDefault composerMeta.license);
|
||||
|
||||
pname = composerMeta.name;
|
||||
|
||||
outputs = {
|
||||
lib.phpVersions = composerMeta.phpVersions;
|
||||
};
|
||||
|
||||
checks = {pkgs, ...}: (optionalAttrs hasPsalm {
|
||||
psalm = pkgs.runCommand "psalm-check" {} "exit 1;";
|
||||
});
|
||||
})
|
||||
|
||||
{
|
||||
devShells = {
|
||||
default = {
|
||||
packages = pkgs: (config.tools pkgs) ++ (with pkgs; [minPhp php-cs-fixer composer]);
|
||||
};
|
||||
};
|
||||
|
||||
formatters = pkgs:
|
||||
with pkgs; ({
|
||||
"*.nix" = getExe alejandra;
|
||||
}
|
||||
// optionalAttrs hasPhpCsFixer {
|
||||
"*.php" = "${getExe php-cs-fixer} fix";
|
||||
});
|
||||
}
|
||||
];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue