nixpkgs/pkgs/by-name/ht/httptoolkit/package.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

102 lines
2.8 KiB
Nix

{
lib,
stdenv,
buildNpmPackage,
fetchFromGitHub,
makeWrapper,
makeDesktopItem,
copyDesktopItems,
electron,
httptoolkit-server,
}:
buildNpmPackage rec {
pname = "httptoolkit";
version = "1.19.0";
src = fetchFromGitHub {
owner = "httptoolkit";
repo = "httptoolkit-desktop";
rev = "refs/tags/v${version}";
hash = "sha256-e+ngBZMwMTvwzY1K7IaxlNoRkZUPDdJvKxvxuCsc9pw=";
};
npmDepsHash = "sha256-XgJIs4P1ezCEPPitIIfYpNkX0/3dPdajeIiDwHm7DSU=";
env = {
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
# disable code signing on Darwin
CSC_IDENTITY_AUTO_DISCOVERY = "false";
};
nativeBuildInputs = [ makeWrapper ] ++ lib.optionals stdenv.hostPlatform.isLinux [ copyDesktopItems ];
npmBuildScript = "build:src";
postBuild = ''
substituteInPlace package.json --replace-fail \
'"forceCodeSigning": true' \
'"forceCodeSigning": false'
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
npm exec electron-builder -- \
--dir \
-c.electronDist=electron-dist \
-c.electronVersion=${electron.version}
'';
installPhase = ''
runHook preInstall
${lib.optionalString stdenv.hostPlatform.isLinux ''
mkdir -p $out/share/httptoolkit
cp -r dist/*-unpacked/{locales,resources{,.pak}} $out/share/httptoolkit
ln -s ${httptoolkit-server} $out/share/httptoolkit/resources/httptoolkit-server
install -Dm644 src/icons/icon.svg $out/share/icons/hicolor/scalable/apps/httptoolkit.svg
makeWrapper ${lib.getExe electron} $out/bin/httptoolkit \
--add-flags $out/share/httptoolkit/resources/app.asar \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
--inherit-argv0
''}
${lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Applications
cp -r dist/mac*/"HTTP Toolkit.app" $out/Applications
ln -s ${httptoolkit-server} "$out/Applications/HTTP Toolkit.app/Contents/Resources/httptoolkit-server"
makeWrapper "$out/Applications/HTTP Toolkit.app/Contents/MacOS/HTTP Toolkit" $out/bin/httptoolkit
''}
runHook postInstall
'';
desktopItems = [
(makeDesktopItem {
name = "httptoolkit";
desktopName = "HTTP Toolkit";
exec = "httptoolkit %U";
terminal = false;
icon = "httptoolkit";
startupWMClass = "HTTP Toolkit";
comment = meta.description;
categories = [ "Development" ];
startupNotify = true;
})
];
meta = {
description = "HTTP(S) debugging, development & testing tool";
homepage = "https://httptoolkit.com/";
license = lib.licenses.agpl3Plus;
mainProgram = "httptoolkit";
maintainers = with lib.maintainers; [ tomasajt ];
platforms = electron.meta.platforms;
};
}