nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 318 lines 7.9 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 buildPackages, 6 alsa-lib, 7 at-spi2-atk, 8 at-spi2-core, 9 atk, 10 cairo, 11 cups, 12 dbus, 13 dpkg, 14 expat, 15 fontconfig, 16 freetype, 17 gdk-pixbuf, 18 glib, 19 adwaita-icon-theme, 20 gsettings-desktop-schemas, 21 gtk3, 22 gtk4, 23 qt6, 24 libX11, 25 libXScrnSaver, 26 libXcomposite, 27 libXcursor, 28 libXdamage, 29 libXext, 30 libXfixes, 31 libXi, 32 libXrandr, 33 libXrender, 34 libXtst, 35 libdrm, 36 libkrb5, 37 libuuid, 38 libxkbcommon, 39 libxshmfence, 40 libgbm, 41 nspr, 42 nss, 43 pango, 44 pipewire, 45 snappy, 46 udev, 47 wayland, 48 xdg-utils, 49 coreutils, 50 xorg, 51 zlib, 52 53 # Darwin dependencies 54 unzip, 55 makeWrapper, 56 57 # command line arguments which are always set e.g "--disable-gpu" 58 commandLineArgs ? "", 59 60 # Necessary for USB audio devices. 61 pulseSupport ? stdenv.hostPlatform.isLinux, 62 libpulseaudio, 63 64 # For GPU acceleration support on Wayland (without the lib it doesn't seem to work) 65 libGL, 66 67 # For video acceleration via VA-API (--enable-features=VaapiVideoDecoder,VaapiVideoEncoder) 68 libvaSupport ? stdenv.hostPlatform.isLinux, 69 libva, 70 enableVideoAcceleration ? libvaSupport, 71 72 # For Vulkan support (--enable-features=Vulkan); disabled by default as it seems to break VA-API 73 vulkanSupport ? false, 74 addDriverRunpath, 75 enableVulkan ? vulkanSupport, 76}: 77 78{ 79 pname, 80 version, 81 hash, 82 url, 83}: 84 85let 86 inherit (lib) 87 optional 88 optionals 89 makeLibraryPath 90 makeSearchPathOutput 91 makeBinPath 92 optionalString 93 strings 94 escapeShellArg 95 ; 96 97 deps = [ 98 alsa-lib 99 at-spi2-atk 100 at-spi2-core 101 atk 102 cairo 103 cups 104 dbus 105 expat 106 fontconfig 107 freetype 108 gdk-pixbuf 109 glib 110 gtk3 111 gtk4 112 libdrm 113 libX11 114 libGL 115 libxkbcommon 116 libXScrnSaver 117 libXcomposite 118 libXcursor 119 libXdamage 120 libXext 121 libXfixes 122 libXi 123 libXrandr 124 libXrender 125 libxshmfence 126 libXtst 127 libuuid 128 libgbm 129 nspr 130 nss 131 pango 132 pipewire 133 udev 134 wayland 135 xorg.libxcb 136 zlib 137 snappy 138 libkrb5 139 qt6.qtbase 140 ] 141 ++ optional pulseSupport libpulseaudio 142 ++ optional libvaSupport libva; 143 144 rpath = makeLibraryPath deps + ":" + makeSearchPathOutput "lib" "lib64" deps; 145 binpath = makeBinPath deps; 146 147 enableFeatures = 148 optionals enableVideoAcceleration [ 149 "VaapiVideoDecoder" 150 "VaapiVideoEncoder" 151 ] 152 ++ optional enableVulkan "Vulkan"; 153 154 disableFeatures = [ 155 "OutdatedBuildDetector" 156 ] # disable automatic updates 157 # The feature disable is needed for VAAPI to work correctly: https://github.com/brave/brave-browser/issues/20935 158 ++ optionals enableVideoAcceleration [ "UseChromeOSDirectVideoDecoder" ]; 159in 160stdenv.mkDerivation { 161 inherit pname version; 162 163 src = fetchurl { 164 inherit url hash; 165 }; 166 167 dontConfigure = true; 168 dontBuild = true; 169 dontPatchELF = true; 170 doInstallCheck = stdenv.hostPlatform.isLinux; 171 172 nativeBuildInputs = 173 lib.optionals stdenv.hostPlatform.isLinux [ 174 dpkg 175 # override doesn't preserve splicing https://github.com/NixOS/nixpkgs/issues/132651 176 # Has to use `makeShellWrapper` from `buildPackages` even though `makeShellWrapper` from the inputs is spliced because `propagatedBuildInputs` would pick the wrong one because of a different offset. 177 (buildPackages.wrapGAppsHook3.override { makeWrapper = buildPackages.makeShellWrapper; }) 178 ] 179 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 180 unzip 181 makeWrapper 182 ]; 183 184 buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ 185 # needed for GSETTINGS_SCHEMAS_PATH 186 glib 187 gsettings-desktop-schemas 188 gtk3 189 gtk4 190 191 # needed for XDG_ICON_DIRS 192 adwaita-icon-theme 193 ]; 194 195 installPhase = 196 lib.optionalString stdenv.hostPlatform.isLinux '' 197 runHook preInstall 198 199 mkdir -p $out $out/bin 200 201 cp -R usr/share $out 202 cp -R opt/ $out/opt 203 204 export BINARYWRAPPER=$out/opt/brave.com/brave/brave-browser 205 206 # Fix path to bash in $BINARYWRAPPER 207 substituteInPlace $BINARYWRAPPER \ 208 --replace-fail /bin/bash ${stdenv.shell} \ 209 --replace-fail 'CHROME_WRAPPER' 'WRAPPER' 210 211 ln -sf $BINARYWRAPPER $out/bin/brave 212 213 for exe in $out/opt/brave.com/brave/{brave,chrome_crashpad_handler}; do 214 patchelf \ 215 --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ 216 --set-rpath "${rpath}" $exe 217 done 218 219 # Fix paths 220 substituteInPlace $out/share/applications/{brave-browser,com.brave.Browser}.desktop \ 221 --replace-fail /usr/bin/brave-browser-stable $out/bin/brave 222 substituteInPlace $out/share/gnome-control-center/default-apps/brave-browser.xml \ 223 --replace-fail /opt/brave.com $out/opt/brave.com 224 substituteInPlace $out/share/menu/brave-browser.menu \ 225 --replace-fail /opt/brave.com $out/opt/brave.com 226 substituteInPlace $out/opt/brave.com/brave/default-app-block \ 227 --replace-fail /opt/brave.com $out/opt/brave.com 228 229 # Correct icons location 230 icon_sizes=("16" "24" "32" "48" "64" "128" "256") 231 232 for icon in ''${icon_sizes[*]} 233 do 234 mkdir -p $out/share/icons/hicolor/$icon\x$icon/apps 235 ln -s $out/opt/brave.com/brave/product_logo_$icon.png $out/share/icons/hicolor/$icon\x$icon/apps/brave-browser.png 236 done 237 238 # Replace xdg-settings and xdg-mime 239 ln -sf ${xdg-utils}/bin/xdg-settings $out/opt/brave.com/brave/xdg-settings 240 ln -sf ${xdg-utils}/bin/xdg-mime $out/opt/brave.com/brave/xdg-mime 241 242 runHook postInstall 243 '' 244 + lib.optionalString stdenv.hostPlatform.isDarwin '' 245 runHook preInstall 246 247 mkdir -p $out/{Applications,bin} 248 249 cp -r . "$out/Applications/Brave Browser.app" 250 251 makeWrapper "$out/Applications/Brave Browser.app/Contents/MacOS/Brave Browser" $out/bin/brave 252 253 runHook postInstall 254 ''; 255 256 preFixup = lib.optionalString stdenv.hostPlatform.isLinux '' 257 # Add command line args to wrapGApp. 258 gappsWrapperArgs+=( 259 --prefix LD_LIBRARY_PATH : ${rpath} 260 --prefix PATH : ${binpath} 261 --suffix PATH : ${ 262 lib.makeBinPath [ 263 xdg-utils 264 coreutils 265 ] 266 } 267 --set CHROME_WRAPPER ${pname} 268 ${optionalString (enableFeatures != [ ]) '' 269 --add-flags "--enable-features=${strings.concatStringsSep "," enableFeatures}\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+,WaylandWindowDecorations --enable-wayland-ime=true}}" 270 ''} 271 ${optionalString (disableFeatures != [ ]) '' 272 --add-flags "--disable-features=${strings.concatStringsSep "," disableFeatures}" 273 ''} 274 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto}}" 275 ${optionalString vulkanSupport '' 276 --prefix XDG_DATA_DIRS : "${addDriverRunpath.driverLink}/share" 277 ''} 278 --add-flags ${escapeShellArg commandLineArgs} 279 ) 280 ''; 281 282 installCheckPhase = '' 283 # Bypass upstream wrapper which suppresses errors 284 $out/opt/brave.com/brave/brave --version 285 ''; 286 287 passthru.updateScript = ./update.sh; 288 289 meta = { 290 homepage = "https://brave.com/"; 291 description = "Privacy-oriented browser for Desktop and Laptop computers"; 292 changelog = 293 "https://github.com/brave/brave-browser/blob/master/CHANGELOG_DESKTOP.md#" 294 + lib.replaceStrings [ "." ] [ "" ] version; 295 longDescription = '' 296 Brave browser blocks the ads and trackers that slow you down, 297 chew up your bandwidth, and invade your privacy. Brave lets you 298 contribute to your favorite creators automatically. 299 ''; 300 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; 301 license = lib.licenses.mpl20; 302 maintainers = with lib.maintainers; [ 303 uskudnik 304 rht 305 jefflabonte 306 nasirhm 307 buckley310 308 matteopacini 309 ]; 310 platforms = [ 311 "aarch64-linux" 312 "x86_64-linux" 313 "aarch64-darwin" 314 "x86_64-darwin" 315 ]; 316 mainProgram = "brave"; 317 }; 318}