16 Aug 2024 |
nebucatnetzer13 | Ah sorry I have two derivations, thats the one for production dependencies | 07:56:56 |
nebucatnetzer13 | {
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 | This 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 | However I don't need it to work exactly this way. This was just me trying to hack something together. | 07:59:12 |
nebucatnetzer13 | In a Python project with poetry2nix I can do this for example:
https://github.com/Nebucatnetzer/sort-of-pastebin/blob/main/flake.nix#L54-L67 | 08:04:30 |
nebucatnetzer13 | One is the dev environment which which I can run the tests and the other is the final application. | 08:05:07 |
nebucatnetzer13 | Which I ten use like this to do the tests:
https://github.com/Nebucatnetzer/sort-of-pastebin/blob/main/.github/workflows/tests.yml | 08:05:49 |
nebucatnetzer13 | And when they succeed I build the container | 08:06:02 |
nebucatnetzer13 | https://github.com/Nebucatnetzer/sort-of-pastebin/blob/main/.github/workflows/build_containers.yml | 08:06:10 |
Pol | But you're using nix develop . | 08:09:59 |
Pol | buildComposerProject does not create a development shell (to be used with nix develop ). | 08:10:25 |
nebucatnetzer13 | Is there a way to do that? | 08:15:32 |
Pol | Creating a devshell containing your tools ? | 08:23:39 |
Pol | Yeah it's quite easy to do | 08:23:46 |
Pol | That's the easiest thing to do in Nix I believe. | 08:23:56 |
nebucatnetzer13 | yeah but especially with the content of composer.lock | 08:24:36 |
Pol | mmh I don't think it has been done yet | 08:25:05 |
nebucatnetzer13 | ah okay, because the rest I have already working | 08:25:29 |
Pol | But you'll find all the most used tools already in nixpkgs (phpunit, psalm, phpstan, etc etc) | 08:25:42 |
Pol | I know that you could do 2 derivations | 08:26:34 |
Pol | For example: | 08:26:38 |
Pol |
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 |
Pol |
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 |
Pol | Then you create a devshell and use the attribute inputsFrom = [ my-app-dev ]; | 08:28:12 |
Pol | That might work. | 08:28:22 |
Pol | To be tested. | 08:28:27 |
nebucatnetzer13 | 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. | 08:30:12 |
rikudou@lemmings.world | Added php84 to https://history.nix-packages.com/search?packageName=php%2Ftag | 08:33:04 |
Pol | 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 |
Pol | 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 |