This commit is contained in:
Lukas Wurzinger 2025-04-13 17:13:51 +02:00
commit 300f0c30ee
No known key found for this signature in database
6 changed files with 295 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.direnv/

147
flake.lock Normal file
View file

@ -0,0 +1,147 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1743550720,
"narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "c621e8422220273271f52058f618c94e405bb0f5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1744463964,
"narHash": "sha256-LWqduOgLHCFxiTNYi3Uj5Lgz0SR+Xhw3kr/3Xd0GPTM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2631b0b7abcea6e640ce31cd78ea58910d31e650",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1743296961,
"narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1744502386,
"narHash": "sha256-QAd1L37eU7ktL2WeLLLTmI6P9moz9+a/ONO8qNBYJgM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f6db44a8daa59c40ae41ba6e5823ec77fe0d2124",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"phps": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": "nixpkgs_2",
"utils": "utils"
},
"locked": {
"lastModified": 1744527323,
"narHash": "sha256-2EyP6SxJsmBFMHArrTGw1J+Ned3aRMUZzbzmJZHDbNo=",
"owner": "fossar",
"repo": "nix-phps",
"rev": "f6b53caf2b1c2d592cbac5156f729ef79495992a",
"type": "github"
},
"original": {
"owner": "fossar",
"repo": "nix-phps",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"phps": "phps"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

54
flake.nix Normal file
View file

@ -0,0 +1,54 @@
{
description = "PHP for me";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
phps.url = "github:fossar/nix-phps";
};
nixConfig = {
extra-substituters = "https://fossar.cachix.org";
extra-trusted-public-keys = "fossar.cachix.org-1:Zv6FuqIboeHPWQS7ysLCJ7UT7xExb4OE8c4LyGb5AsE=";
};
outputs = {
self,
flake-parts,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux"];
flake.nixosModules = let
myphps = import ./nixos self;
in {
inherit myphps;
default = myphps;
};
perSystem = {
pkgs,
inputs',
...
}: {
packages = let
myphp = pkgs.callPackage ./packages/myphp/package.nix {};
myphps =
builtins.mapAttrs (
_: php:
myphp.override {
inherit php;
}
)
inputs'.phps.packages;
in
myphps
// {
symfony-cli = pkgs.callPackage ./packages/symfony-cli/package.nix {
phps = myphps;
};
};
};
};
}

34
nixos/default.nix Normal file
View file

@ -0,0 +1,34 @@
phps: {
lib,
config,
...
}: let
cfg = config.programs.phps;
inherit (lib) types;
in {
options.services.phps = {
enable = lib.mkEnableOption "phps";
phps = lib.mkOption {
description = ''
PHPs to use.
'';
default = phps;
type = types.attrsOf types.package;
};
prefix = lib.mkOption {
description = ''
The prefix for every PHP installation.
'';
default = "/var/lib/phps";
type = types.str;
};
};
config = {
systemd.tmpfiles.settings =
builtins.mapAttrs (name: drv: {
"${cfg.prefix}/${name}"."L+".argument = drv.outPath;
})
phps;
};
}

View file

@ -0,0 +1,37 @@
{
lib,
php,
symlinkJoin,
}: let
extraConfig = ''
memory_limit = -1
xdebug.mode = develop,coverage,gcstats,profile,debug,trace
xdebug.discover_client_host = 1
xdebug.client_host = localhost
'';
# Build PHP environment with required extensions
phpEnv = php.buildEnv {
extensions = {
enabled,
all,
}:
enabled
++ [all.xdebug]
++ (
if (lib.versionAtLeast php.version "8")
then [all.amqp]
else []
);
inherit extraConfig;
};
in
# Bundle composer alongside this PHP package
symlinkJoin {
inherit (phpEnv) name version meta passthru;
paths = [
phpEnv
phpEnv.packages.composer
];
}

View file

@ -0,0 +1,22 @@
{
lib,
phps,
symlinkJoin,
symfony-cli,
makeWrapper,
}: let
package = symfony-cli;
in
# Tell Symfony's CLI where it can access the different PHP versions
symlinkJoin {
inherit (package) pname version meta;
paths = [package];
buildInputs = [makeWrapper];
postBuild = ''
wrapProgram $out/bin/${package.meta.mainProgram} \
--suffix PATH : ${lib.makeBinPath (builtins.attrValues phps)}
'';
}