I found a solution. I’m not sure it’s a good one.
I turned around the order of the installPhase, doing my custom logic first now, and in the archive directory as opposed to the $out$ dir. That seems to make more sense.
And I don’t refer to the keytool coming from the archive anymore. Instead, I use the keytool from the official oraclejdk11. I’m not particularly happy about this, because this only works because I’m only modifying a package that already exists - I shouldn’t have to rely on that. Also, I’m not sure why oraclejdk11 is even available on my system, without it being installed. Is that only because it’s still hanging around somewhere from a previous install? Or is this supposed to always work? Why, if so?
Here’s how it actually works. Please comment
{ pkgs ? import <nixpkgs> {}, ... }:
let
# Define the source for the custom certificate
cert1 = pkgs.fetchurl {
url = "http://cert1.crt"; # Replace with the actual path or URL to the certificate file
sha256 = "91a3b1962b..."; # Replace with the actual SHA-256 hash of the certificate file
};
cert2 = pkgs.fetchurl {
url = "http://cert2.crt";
sha256 = "fbaef2da...";
};
# Override the official Oracle JDK derivation
customOracleJdk = pkgs.oraclejdk11.overrideAttrs (oldAttrs: {
installPhase = ''
# Debugging executable
${pkgs.oraclejdk11}/bin/keytool > $out/output_of_keytool.txt; // this works!
# Import the custom certificates
${pkgs.oraclejdk11}/bin/keytool -noprompt -trustcacerts -import -alias cert1 \
-storepass changeit -keystore lib/security/cacerts -file ${cert1};
${pkgs.oraclejdk11}/bin/keytool -noprompt -trustcacerts -import -alias cert2 \
-storepass changeit -keystore lib/security/cacerts -file ${cert2};
'' + oldAttrs.installPhase;
});
in
customOracleJdk
for context, this is saved to a file like custom-jdk-11.nix and I import it into my configuration.nix like
environment.systemPackages = with pkgs; [
...
(import ./custom-jdk-11.nix { inherit pkgs; })
];