This commit is contained in:
2024-03-21 16:29:09 -05:00
parent ceada8a46b
commit 51e7f52bb0
10 changed files with 584 additions and 76 deletions

103
pkgs/warp/default.nix Normal file
View File

@@ -0,0 +1,103 @@
{ lib
, stdenvNoCC
, stdenv
, fetchurl
, autoPatchelfHook
, undmg
, zstd
, curl
, fontconfig
, libglvnd
, libxkbcommon
, vulkan-loader
, xdg-utils
, xorg
, zlib
}:
let
pname = "warp-terminal";
versions = lib.importJSON ./versions.json;
passthru.updateScript = ./update.sh;
linux = stdenv.mkDerivation (finalAttrs: {
inherit pname meta passthru;
inherit (versions.linux) version;
src = fetchurl {
inherit (versions.linux) hash;
url = "https://releases.warp.dev/stable/v${finalAttrs.version}/warp-terminal-v${finalAttrs.version}-1-x86_64.pkg.tar.zst";
};
sourceRoot = ".";
postPatch = ''
substituteInPlace usr/bin/warp-terminal \
--replace-fail /opt/ $out/opt/
'';
nativeBuildInputs = [ autoPatchelfHook zstd ];
buildInputs = [
curl
fontconfig
stdenv.cc.cc.lib # libstdc++.so libgcc_s.so
zlib
];
runtimeDependencies = [
libglvnd # for libegl
libxkbcommon
stdenv.cc.libc
vulkan-loader
xdg-utils
xorg.libX11
xorg.libxcb
xorg.libXcursor
xorg.libXi
];
installPhase = ''
runHook preInstall
mkdir $out
cp -r opt usr/* $out
runHook postInstall
'';
});
darwin = stdenvNoCC.mkDerivation (finalAttrs: {
inherit pname meta passthru;
inherit (versions.darwin) version;
src = fetchurl {
inherit (versions.darwin) hash;
url = "https://releases.warp.dev/stable/v${finalAttrs.version}/Warp.dmg";
};
sourceRoot = ".";
nativeBuildInputs = [ undmg ];
installPhase = ''
runHook preInstall
mkdir -p $out/Applications
cp -r *.app $out/Applications
runHook postInstall
'';
});
meta = with lib; {
description = "Rust-based terminal";
homepage = "https://www.warp.dev";
license = licenses.unfree;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
maintainers = with maintainers; [ emilytrau Enzime imadnyc ];
platforms = platforms.darwin ++ [ "x86_64-linux" ];
};
in
if stdenvNoCC.isDarwin
then darwin
else linux

74
pkgs/warp/update.sh Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p cacert curl jq nix moreutils --pure
#shellcheck shell=bash
set -eu -o pipefail
dirname="$(dirname "$0")"
err() {
echo "$*" >&2
exit 1
}
json_get() {
jq -r "$1" < "$dirname/versions.json"
}
json_set() {
jq --arg x "$2" "$1 = \$x" < "$dirname/versions.json" | sponge "$dirname/versions.json"
}
resolve_url() {
local pkg sfx url
local -i i max_redirects
case "$1" in
darwin)
pkg=macos
sfx=dmg
;;
linux)
pkg=pacman
sfx=pkg.tar.zst
;;
*)
err "Unexpected download type: $1"
;;
esac
url="https://app.warp.dev/download?package=${pkg}"
((max_redirects = 15))
for ((i = 0; i < max_redirects; i++)); do
url=$(curl -s -o /dev/null -w '%{redirect_url}' "${url}")
[[ ${url} != *.${sfx} ]] || break
done
((i < max_redirects)) || { err "too many redirects"; }
echo "${url}"
}
get_version() {
echo "$1" | grep -oP -m 1 '(?<=/v)[\d.\w]+(?=/)'
}
# nix-prefect-url seems to be uncompressing the archive then taking the hash
# so just get the hash from fetchurl
sri_get() {
local ouput sri
output=$(nix-build --expr \
'with import <nixpkgs>{};
fetchurl {
url = "'"$1"'";
}' 2>&1 || true)
sri=$(echo "$output" | awk '/^\s+got:\s+/{ print $2 }')
[[ -z "$sri" ]] && err "$output"
echo "$sri"
}
for sys in darwin linux; do
url=$(resolve_url ${sys})
version=$(get_version "${url}")
if [[ ${version} != "$(json_get ".${sys}.version")" ]]; then
sri=$(sri_get "${url}")
json_set ".${sys}.version" "${version}"
json_set ".${sys}.hash" "${sri}"
fi
done

10
pkgs/warp/versions.json Normal file
View File

@@ -0,0 +1,10 @@
{
"darwin": {
"hash": "sha256-GgaRlROSWYZgFlH0bH6PTnRE3L/bb0kX0P6m7nmPlsY=",
"version": "0.2024.03.12.08.02.stable_01"
},
"linux": {
"hash": "sha256-9reFBIu32TzxE46c3PBVzkZYaMV4HVDASvTAVQltYN0=",
"version": "0.2024.03.12.08.02.stable_01"
}
}