!jngDrdMgndWibPCYsR:nixos.org

Nix PHP

71 Members
A room for PHP developers running on Nix22 Servers

Load older messages


SenderMessageTime
16 Aug 2024
@nebucatnetzer13:matrix.orgnebucatnetzer13Ah sorry I have two derivations, thats the one for production dependencies07:56:56
@nebucatnetzer13:matrix.orgnebucatnetzer13
{
  composerDependencies,
  lib,
  php83Packages,
  root,
  stdenvNoCC,
}:
let
  fs = lib.fileset;
  sourceFiles = fs.unions [
    (root + "/composer.json")
    (root + "/composer.lock")
  ];
  composerFiles = fs.toSource {
    fileset = sourceFiles;
    inherit root;
  };
in
stdenvNoCC.mkDerivation {
  name = "composer-dev-dependencies";
  src = composerFiles;
  nativeBuildInputs = [ php83Packages.composer ];
  buildPhase = ''
    cp -r ${composerDependencies}/vendor vendor
    chmod -R 755 vendor
    export COMPOSER_HOME=$TMPDIR
    composer install --no-interaction --no-scripts --no-ansi --no-autoloader
  '';
  installPhase = ''
    mkdir -p $out/
    cp -r vendor $out/
  '';
  dontFixup = true;
  outputHashAlgo = "sha256";
  outputHashMode = "recursive";
  outputHash = "sha256-oHkogPJiwXE+XBJxh0yTsFRYptLkgCG5v6ExFuef72Y=";
}
07:57:08
@nebucatnetzer13:matrix.orgnebucatnetzer13This one depends on the previous one and that's how I noticed that the outputHash changed because I didn't push the previous derivation to the cache. Therefore the runner had to built it itself and failed because the hash didn't match.07:58:35
@nebucatnetzer13:matrix.orgnebucatnetzer13However I don't need it to work exactly this way. This was just me trying to hack something together.07:59:12
@nebucatnetzer13:matrix.orgnebucatnetzer13In a Python project with poetry2nix I can do this for example: https://github.com/Nebucatnetzer/sort-of-pastebin/blob/main/flake.nix#L54-L6708:04:30
@nebucatnetzer13:matrix.orgnebucatnetzer13One is the dev environment which which I can run the tests and the other is the final application.08:05:07
@nebucatnetzer13:matrix.orgnebucatnetzer13Which I ten use like this to do the tests: https://github.com/Nebucatnetzer/sort-of-pastebin/blob/main/.github/workflows/tests.yml08:05:49
@nebucatnetzer13:matrix.orgnebucatnetzer13And when they succeed I build the container08:06:02
@nebucatnetzer13:matrix.orgnebucatnetzer13https://github.com/Nebucatnetzer/sort-of-pastebin/blob/main/.github/workflows/build_containers.yml08:06:10
@drupol:matrix.orgPol But you're using nix develop. 08:09:59
@drupol:matrix.orgPol buildComposerProject does not create a development shell (to be used with nix develop). 08:10:25
@nebucatnetzer13:matrix.orgnebucatnetzer13Is there a way to do that?08:15:32
@drupol:matrix.orgPolCreating a devshell containing your tools ?08:23:39
@drupol:matrix.orgPolYeah it's quite easy to do08:23:46
@drupol:matrix.orgPolThat's the easiest thing to do in Nix I believe.08:23:56
@nebucatnetzer13:matrix.orgnebucatnetzer13yeah but especially with the content of composer.lock08:24:36
@drupol:matrix.orgPolmmh I don't think it has been done yet08:25:05
@nebucatnetzer13:matrix.orgnebucatnetzer13ah okay, because the rest I have already working08:25:29
@drupol:matrix.orgPol But you'll find all the most used tools already in nixpkgs (phpunit, psalm, phpstan, etc etc) 08:25:42
@drupol:matrix.orgPolI know that you could do 2 derivations08:26:34
@drupol:matrix.orgPolFor example:08:26:38
@drupol:matrix.orgPol
  1. my-app -> would be made with buildComposerProject, using regular attributes. This is ready to go in prod if needed, it doesn't contain any require-dev stuff.
08:27:14
@drupol:matrix.orgPol
  1. my-app-dev -> would also be made with buildComposerProject but this time, you can add an attribute that will install the require-dev dependencies.
08:27:54
@drupol:matrix.orgPol Then you create a devshell and use the attribute inputsFrom = [ my-app-dev ]; 08:28:12
@drupol:matrix.orgPolThat might work.08:28:22
@drupol:matrix.orgPolTo be tested.08:28:27
@nebucatnetzer13:matrix.orgnebucatnetzer13Okay, yeah that was my last idea as well, the problem with that is that the code for the project lands twice in the store right? It's not a killer, just a bit inelegant.08:30:12
@rikudou:lemmings.worldrikudou@lemmings.worldAdded php84 to https://history.nix-packages.com/search?packageName=php%2Ftag08:33:04
@drupol:matrix.orgPol
In reply to @nebucatnetzer13:matrix.org
Okay, yeah that was my last idea as well, the problem with that is that the code for the project lands twice in the store right? It's not a killer, just a bit inelegant.
Yes. I'm pretty sure there's room for improvements...
08:44:16
@drupol:matrix.orgPol
In reply to @rikudou:lemmings.world
Added php84 to https://history.nix-packages.com/search?packageName=php%2Ftag
The sort is not really optimal in the list.
08:44:52

Show newer messages


Back to Room ListRoom Version: 6