nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 111 lines 2.7 kB view raw
1{ 2 lib, 3 stdenv, 4 glibcLocales, 5 removeReferencesTo, 6 graalvmPackages, 7}: 8 9lib.extendMkDerivation { 10 constructDrv = stdenv.mkDerivation; 11 12 excludeDrvArgNames = [ 13 "executable" 14 "extraNativeImageBuildArgs" 15 "graalvmDrv" 16 "graalvmXmx" 17 "nativeImageBuildArgs" 18 ]; 19 20 extendDrvArgs = 21 finalAttrs: 22 { 23 dontUnpack ? true, 24 strictDeps ? true, 25 __structuredAttrs ? true, 26 27 # The GraalVM derivation to use 28 graalvmDrv ? graalvmPackages.graalvm-ce, 29 30 executable ? finalAttrs.meta.mainProgram, 31 32 # Default native-image arguments. You probably don't want to set this, 33 # except in special cases. In most cases, use extraNativeBuildArgs instead 34 nativeImageBuildArgs ? [ 35 (lib.optionalString stdenv.hostPlatform.isDarwin "-H:-CheckToolchain") 36 (lib.optionalString ( 37 stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 38 ) "-H:PageSize=64K") 39 "-H:Name=${executable}" 40 "-march=compatibility" 41 "--verbose" 42 ], 43 44 # Extra arguments to be passed to the native-image 45 extraNativeImageBuildArgs ? [ ], 46 47 # XMX size of GraalVM during build 48 graalvmXmx ? "-J-Xmx6g", 49 50 env ? { }, 51 meta ? { }, 52 passthru ? { }, 53 ... 54 }@args: 55 { 56 env = { 57 LC_ALL = "en_US.UTF-8"; 58 } 59 // env; 60 61 inherit dontUnpack strictDeps __structuredAttrs; 62 63 nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ 64 graalvmDrv 65 glibcLocales 66 removeReferencesTo 67 ]; 68 69 # `nativeBuildInputs` does not allow `graalvmDrv`'s propagatedBuildInput to reach here this package. 70 # As its `propagatedBuildInputs` is required for the build process with `native-image`, we must add it here as well. 71 buildInputs = [ graalvmDrv ]; 72 73 nativeImageArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ]; 74 75 buildPhase = 76 args.buildPhase or '' 77 runHook preBuild 78 79 native-image -jar "$src" ''${nativeImageArgs[@]} 80 81 runHook postBuild 82 ''; 83 84 installPhase = 85 args.installPhase or '' 86 runHook preInstall 87 88 install -Dm755 ${executable} -t $out/bin 89 90 runHook postInstall 91 ''; 92 93 postInstall = '' 94 remove-references-to -t ${graalvmDrv} $out/bin/${executable} 95 ${args.postInstall or ""} 96 ''; 97 98 disallowedReferences = [ graalvmDrv ]; 99 100 passthru = { 101 inherit graalvmDrv; 102 } 103 // passthru; 104 105 meta = { 106 # default to graalvm's platforms 107 inherit (graalvmDrv.meta) platforms; 108 } 109 // meta; 110 }; 111}