nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 182 lines 4.9 kB view raw
1{ 2 lib, 3 stdenv, 4 stdenvNoCC, 5 fetchFromGitHub, 6 7 # buildInputs 8 SDL2, 9 libcxx, 10 openal, 11 12 # nativeBuildInputs 13 cmake, 14 git, 15 pkg-config, 16 imagemagick, 17 libicns, 18 copyDesktopItems, 19 20 makeDesktopItem, 21 22 # passthru 23 callPackage, 24 symlinkJoin, 25 rsync, 26 27 appName, 28 CMAKE_BUILD_TYPE ? "RelWithDebInfo", # "Choose the type of build, recommended options are: Debug Release RelWithDebInfo" 29}: 30assert lib.assertOneOf "appName" appName [ 31 "vanillatd" 32 "vanillara" 33]; 34stdenv.mkDerivation (finalAttrs: { 35 pname = appName; 36 version = "0.0.0"; 37 38 src = fetchFromGitHub { 39 owner = "TheAssemblyArmada"; 40 repo = "Vanilla-Conquer"; 41 # FIXME: This version has format-security 42 rev = "ebc8083d5d149f98abc20f460a512a2d16fdc59f"; 43 hash = "sha256-iUF9UFc0FMvOwLkGqSyLYGy5E8YqNySqDp5VVUa+u4o="; 44 }; 45 # TODO: Remove this. Just add this flag to ignore the format-security error temporarily. 46 NIX_CFLAGS_COMPILE = "-Wno-error=format-security"; 47 48 buildInputs = [ 49 SDL2 50 libcxx 51 openal 52 ]; 53 54 nativeBuildInputs = [ 55 cmake 56 git 57 pkg-config 58 ] 59 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 60 imagemagick 61 libicns 62 ] 63 ++ lib.optionals stdenv.hostPlatform.isLinux [ 64 copyDesktopItems 65 ]; 66 67 cmakeFlags = [ 68 (lib.cmakeBool "BUILD_VANILLATD" (appName == "vanillatd")) 69 (lib.cmakeBool "BUILD_VANILLARA" (appName == "vanillara")) 70 (lib.cmakeBool "BUILD_REMASTERTD" (appName == "remastertd")) 71 (lib.cmakeBool "BUILD_REMASTERRA" (appName == "remasterra")) 72 (lib.cmakeFeature "CMAKE_BUILD_TYPE" CMAKE_BUILD_TYPE) 73 ]; 74 75 # TODO: Fix this from the upstream 76 # remove the old FindSDL2.cmake logic, use cmake's built-in SDL2 support 77 # replace ${SDL2_LIBRARY} to SDL2::SDL2 in CMakeLists.txt 78 preConfigure = '' 79 rm cmake/FindSDL2.cmake 80 sed -i 's/..SDL2_LIBRARY./SDL2::SDL2/g' CMakeLists.txt 81 ''; 82 83 installPhase = 84 if stdenv.hostPlatform.isDarwin then 85 '' 86 runHook preInstall 87 88 mkdir -p $out/Applications 89 mv ${appName}.app $out/Applications 90 91 runHook postInstall 92 '' 93 else 94 '' 95 runHook preInstall 96 97 mkdir -p $out/bin 98 mv ${appName} $out/bin/${appName} 99 install -Dm644 ../resources/${appName}_icon.svg $out/share/icons/hicolor/scalable/apps/${appName}.svg 100 101 runHook postInstall 102 ''; 103 104 desktopItems = [ 105 (makeDesktopItem { 106 name = appName; 107 desktopName = appName; 108 comment = 109 { 110 "vanillatd" = "Command & Conquer: Tiberian Dawn"; 111 "vanillara" = "Command & Conquer: Red Alert"; 112 } 113 ."${appName}"; 114 exec = appName; 115 terminal = false; 116 icon = appName; 117 startupWMClass = appName; 118 categories = [ "Game" ]; 119 }) 120 ]; 121 122 passthru = 123 let 124 packages = callPackage ./passthru-packages.nix { inherit appName; }; 125 in 126 { 127 inherit packages; 128 129 withPackages = 130 cb: 131 let 132 dataDerivation = symlinkJoin { 133 name = "${appName}-data"; 134 paths = if builtins.isFunction cb then cb packages else cb; 135 }; 136 in 137 stdenvNoCC.mkDerivation { 138 pname = "${appName}-with-packages"; 139 inherit (finalAttrs.finalPackage) version meta; 140 141 buildInputs = [ dataDerivation ] ++ finalAttrs.buildInputs; 142 nativeBuildInputs = [ rsync ]; 143 144 phases = [ "buildPhase" ]; 145 buildPhase = 146 let 147 Default_Data_Path = 148 if stdenv.hostPlatform.isDarwin then 149 "$out/Applications/${appName}.app/Contents/share/${appName}" 150 else 151 "$out/share/${appName}"; 152 in 153 '' 154 # The default Data_Path() is rely on the Program_Path(), which is the real path of executable, so we need to make executable non symlink here. 155 rsync --archive --mkpath --chmod=a+w ${finalAttrs.finalPackage}/ $out/ 156 157 # Symlink the data derivation to the default data path 158 mkdir -p ${builtins.dirOf Default_Data_Path} 159 ln -s ${dataDerivation} ${Default_Data_Path} 160 161 # Fix `error: suspicious ownership or permission on '/nix/store/xxx-0.0.0' for output 'out'; rejecting this build output` 162 chmod 755 $out 163 ''; 164 }; 165 }; 166 167 meta = { 168 description = 169 { 170 "vanillatd" = 171 "Vanilla Conquer is a modern, multi-platform source port of Command & Conquer: Tiberian Dawn"; 172 "vanillara" = 173 "Vanilla Conquer is a modern, multi-platform source port of Command & Conquer: Red Alert"; 174 } 175 ."${appName}"; 176 homepage = "https://github.com/TheAssemblyArmada/Vanilla-Conquer"; 177 license = with lib.licenses; [ gpl3Only ]; 178 sourceProvenance = with lib.sourceTypes; [ fromSource ]; 179 maintainers = with lib.maintainers; [ xiaoxiangmoe ]; 180 platforms = with lib.platforms; darwin ++ linux; 181 }; 182})