To reproduce:
$ nix run nixpkgs/3b32825de172d0bc85664f495edb096b10862524#ast-grep \
-- scan --update-all --inline-rules '
id: nix-x86_64-darwin
language: nix
rule:
any:
- pattern: "\"x86_64-darwin\""
kind: list_expression > string_expression
- pattern:
context: "{ \"x86_64-darwin\" = $EXPR; }"
selector: binding
- pattern:
context: "{ x86_64-darwin = $EXPR; }"
selector: binding
fix:
template: ""
' pkgs
$ nix run nixpkgs/3b32825de172d0bc85664f495edb096b10862524#ast-grep \
-- scan --update-all --inline-rules '
id: json-first-x86_64-darwin
language: json
rule:
kind: object > pair:nth-child(1)
has:
pattern: "\"x86_64-darwin\""
field: key
fix:
template: ""
expandEnd: { regex: "," }
' pkgs
$ nix run nixpkgs/3b32825de172d0bc85664f495edb096b10862524#ast-grep \
-- scan --update-all --inline-rules '
id: json-x86_64-darwin
language: json
rule:
kind: object > pair
has:
pattern: "\"x86_64-darwin\""
field: key
fix:
template: ""
expandStart: { regex: "," }
' pkgs
$ git restore pkgs/by-name/om/omnix/package.nix
$ git diff --name-only -z \
| nix shell nixpkgs/3b32825de172d0bc85664f495edb096b10862524#gnused \
-c xargs -0 sed -i '/^$/N; /^\n\? \+$/d'
$ treefmt
130 lines
3.6 KiB
Nix
130 lines
3.6 KiB
Nix
{
|
|
lib,
|
|
stdenv,
|
|
fetchurl,
|
|
buildFHSEnv,
|
|
git,
|
|
installShellFiles,
|
|
testers,
|
|
graphite-cli,
|
|
}:
|
|
|
|
let
|
|
selectSystem =
|
|
attrs:
|
|
attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
|
|
suffix = selectSystem {
|
|
x86_64-linux = "linux-x64";
|
|
aarch64-linux = "linux-arm64";
|
|
aarch64-darwin = "darwin-arm64";
|
|
};
|
|
|
|
version = "1.8.6";
|
|
|
|
meta = {
|
|
changelog = "https://graphite.dev/docs/cli-changelog";
|
|
description = "CLI that makes creating stacked git changes fast & intuitive";
|
|
downloadPage = "https://www.npmjs.com/package/@withgraphite/graphite-cli";
|
|
homepage = "https://graphite.dev/docs/graphite-cli";
|
|
license = lib.licenses.unfree; # no license specified
|
|
mainProgram = "gt";
|
|
maintainers = with lib.maintainers; [ joshheinrichs-shopify ];
|
|
platforms = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
"aarch64-darwin"
|
|
];
|
|
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
|
|
};
|
|
|
|
passthru = {
|
|
updateScript = ./update.sh;
|
|
tests.version = testers.testVersion {
|
|
package = graphite-cli;
|
|
command = "gt --version";
|
|
};
|
|
};
|
|
|
|
shellCompletions = ''
|
|
installShellCompletion --cmd gt \
|
|
--bash <($out/bin/gt completion) \
|
|
--zsh <(ZSH_NAME=zsh $out/bin/gt completion) \
|
|
--fish <($out/bin/gt fish)
|
|
'';
|
|
|
|
unwrapped = stdenv.mkDerivation {
|
|
pname = "graphite-cli-unwrapped";
|
|
inherit version meta passthru;
|
|
strictDeps = true;
|
|
|
|
src = fetchurl {
|
|
url = "https://registry.npmjs.org/@withgraphite/graphite-cli-${suffix}/-/graphite-cli-${suffix}-${version}.tgz";
|
|
hash = selectSystem {
|
|
x86_64-linux = "sha256-YnG3iw35ZEyGbB9vGdcnj0qkvUfyLuaIEB5l09hkRck=";
|
|
aarch64-linux = "sha256-Z4yY26hXf8++TX5tJcqufsAULTn9oUL90d9tDZj5d/k=";
|
|
aarch64-darwin = "sha256-6eogi8fMOD5IgRyEdPRxdDa17WytB1JwTpKRzyyhQ2Q=";
|
|
};
|
|
};
|
|
|
|
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
|
|
git
|
|
installShellFiles
|
|
];
|
|
|
|
dontConfigure = true;
|
|
dontBuild = true;
|
|
# Skip fixup on all platforms: strip discards the vercel/pkg virtual
|
|
# filesystem appended to the binary (see the comment below), leaving a
|
|
# binary that fails at runtime with "Pkg: Error reading from file."
|
|
dontFixup = true;
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
install -Dm755 bin/gt $out/bin/gt
|
|
runHook postInstall
|
|
'';
|
|
|
|
# gt tries to create ~/.config/graphite/aliases on startup and exits 1
|
|
# with no output when HOME is not writable, which would leave the
|
|
# completion files empty.
|
|
postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
|
|
export HOME=$(mktemp -d)
|
|
${shellCompletions}
|
|
'';
|
|
};
|
|
in
|
|
# The binary is built with vercel/pkg, which appends a virtual filesystem to
|
|
# the executable at fixed byte offsets. patchelf and strip shift those offsets,
|
|
# corrupting the embedded data, so the binary must remain completely unmodified.
|
|
# On Linux we use buildFHSEnv to provide /lib64/ld-linux-*.so.* and shared
|
|
# libraries without touching the binary. On Darwin this isn't needed.
|
|
if stdenv.hostPlatform.isLinux then
|
|
(buildFHSEnv {
|
|
pname = "graphite-cli";
|
|
inherit version passthru;
|
|
|
|
targetPkgs = pkgs: [
|
|
unwrapped
|
|
pkgs.stdenv.cc.cc.lib
|
|
git
|
|
];
|
|
|
|
runScript = "gt";
|
|
|
|
extraInstallCommands = ''
|
|
ln -s $out/bin/graphite-cli $out/bin/gt
|
|
source ${installShellFiles}/nix-support/setup-hook
|
|
${shellCompletions}
|
|
'';
|
|
|
|
meta = meta // {
|
|
platforms = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
];
|
|
};
|
|
}).overrideAttrs
|
|
{ strictDeps = true; }
|
|
else
|
|
unwrapped
|