1{ 2 lib, 3 stdenv, 4 fetchurl, 5 makeWrapper, 6 makeDesktopItem, 7 jdk, 8 ant, 9 stripJavaArchivesHook, 10 gtk3, 11 gsettings-desktop-schemas, 12 p7zip, 13 autoPatchelfHook, 14 libXxf86vm, 15 libGL, 16 copyDesktopItems, 17 18 pname, 19 version, 20 src, 21 meta, 22 patches, 23}: 24 25let 26 27 # TODO: Should we move this to `lib`? Seems like its would be useful in many cases. 28 extensionOf = 29 filePath: lib.concatStringsSep "." (lib.tail (lib.splitString "." (builtins.baseNameOf filePath))); 30 31 installIcons = 32 iconName: icons: 33 lib.concatStringsSep "\n" ( 34 lib.mapAttrsToList (size: iconFile: '' 35 mkdir -p "$out/share/icons/hicolor/${size}/apps" 36 ln -s -T "${iconFile}" "$out/share/icons/hicolor/${size}/apps/${iconName}.${extensionOf iconFile}" 37 '') icons 38 ); 39 40 icons = { 41 "32x32" = fetchurl { 42 url = "http://sweethome3d.cvs.sourceforge.net/viewvc/sweethome3d/SweetHome3D/deploy/SweetHome3DIcon32x32.png"; 43 sha256 = "1r2fhfg27mx00nfv0qj66rhf719s2g1vhdis7bdc9mqk9x0mb0ir"; 44 }; 45 "48x48" = fetchurl { 46 url = "http://sweethome3d.cvs.sourceforge.net/viewvc/sweethome3d/SweetHome3D/deploy/SweetHome3DIcon48x48.png"; 47 sha256 = "1ap6d75dyqqvx21wddvn8vw2apq3v803vmbxdriwd0dw9rq3zn4g"; 48 }; 49 }; 50 51in 52stdenv.mkDerivation { 53 inherit 54 pname 55 version 56 src 57 meta 58 patches 59 ; 60 61 desktopItems = [ 62 (makeDesktopItem { 63 name = "sweethome3d"; 64 desktopName = "Sweet Home 3D"; 65 icon = "sweethome3d"; 66 comment = meta.description; 67 exec = meta.mainProgram; 68 genericName = "Computer Aided (Interior) Design"; 69 categories = [ 70 "Graphics" 71 "2DGraphics" 72 "3DGraphics" 73 ]; 74 }) 75 ]; 76 77 postPatch = '' 78 addAutoPatchelfSearchPath ${jdk}/lib/openjdk/lib/ 79 autoPatchelf lib 80 81 # Nix cannot see the runtime references to the paths we just patched in 82 # once they've been compressed into the .jar. Scan for and remember them 83 # as plain text so they don't get overlooked. 84 find . -name '*.so' | xargs strings | { grep '/nix/store' || :; } >> ./.jar-paths 85 ''; 86 87 nativeBuildInputs = [ 88 makeWrapper 89 autoPatchelfHook 90 stripJavaArchivesHook 91 copyDesktopItems 92 ]; 93 buildInputs = [ 94 ant 95 jdk 96 p7zip 97 gtk3 98 gsettings-desktop-schemas 99 libXxf86vm 100 ]; 101 102 # upstream targets Java 7 by default 103 env.ANT_ARGS = "-DappletClassSource=8 -DappletClassTarget=8 -DclassSource=8 -DclassTarget=8"; 104 105 buildPhase = '' 106 runHook preBuild 107 108 ant furniture textures help 109 mkdir -p $out/share/{java,applications} 110 mv "build/"*.jar $out/share/java/. 111 ant 112 113 runHook postBuild 114 ''; 115 116 installPhase = '' 117 runHook preInstall 118 119 mkdir -p $out/bin 120 cp install/SweetHome3D-${version}.jar $out/share/java/. 121 122 ${installIcons "sweethome3d" icons} 123 124 makeWrapper ${jdk}/bin/java $out/bin/${meta.mainProgram} \ 125 --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:${gsettings-desktop-schemas}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \ 126 --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ libGL ]}" \ 127 --add-flags "-Dsun.java2d.opengl=true -jar $out/share/java/SweetHome3D-${version}.jar -cp $out/share/java/Furniture.jar:$out/share/java/Textures.jar:$out/share/java/Help.jar -d${toString stdenv.hostPlatform.parsed.cpu.bits}" 128 129 130 # remember the store paths found inside the .jar libraries. note that 131 # which file they are in does not matter in particular, just that some 132 # file somewhere lists them in plain-text 133 mkdir -p $out/nix-support 134 cp .jar-paths $out/nix-support/depends 135 136 runHook postInstall 137 ''; 138 139 dontStrip = true; 140}