I’m trying to modify a package by adding some files to the final derivation, which I then want to pass to a service’s package option. In my case it’s Keycloak (a webapp) where I would like to include some custom stylesheets (although I’m hoping to come up with some more general solution in the end).
After a bit of testing, this seems to work (I have a stuff folder containing testfile.txt next to this nix code):
In the end, the Keycloak derivation that is running has the testfile.txt file in the corresponding folder in /nix/store. My question is now: is this the recommended / ideal way to do this or am I missing something here? In particular, I’m interested in whether the patchPhase defined in the original Keycloak package (should there be any) will be overwritten or if it is merely extended with my command.
The problem with this is that it will just create a symlink to the build directory, unless the packages is copying everything at the root of the build directory into the output, this probably won’t show up in your realised package.
My question is now: is this the recommended / ideal way to do this or am I missing something here?
In general, you should avoid defining “phases”, as the defaults usually handle many things. In the case of the patchPhase, the default patchPhase will also patch shebangs for certain files, as well as apply any of the patches defined in patches. Instead, you should use something like postPatch to do additional patching.
Also, for “installing” additional items (in this case, you want an additional file), I would use something like postInstall to then install additional items.
Finally, you could also use buildEnv to merge all of these packages together, and this is nicer on the “rebuild” aspects, as you just merge the existing packages together, instead of modifying one, and having to rebuild it
let
keycloakAdditions = ./stuff;
keycloakEnv = pkgs.buildEnv {
name = "keycloak-env";
paths = [ pkgs.keycloak keycloakAdditions ];
}
in {
services.keycloak.package = keycloakEnv;
...
}