Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
166 lines (156 loc) · 5.9 KB
/
Copy pathflake.nix
File metadata and controls
166 lines (156 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
config.android_sdk.accept_license = true;
};
# The e2e harness needs a reproducible ngit-grasp binary. Build the
# published crate directly and leave its live-relay tests to the
# application's e2e suite.
ngit-grasp-pkg = pkgs.rustPlatform.buildRustPackage rec {
pname = "ngit-grasp";
version = "3.0.0";
src = pkgs.fetchCrate {
inherit pname version;
hash = "sha256-t14USfeuoXGKws1ueVXqQk+hjE2mGf1zjXMzHrTax58=";
};
NGIT_BUILD_REVISION = "bce30ef039ecbc8c2371008e1bd00eedd79bbccf";
cargoHash = "sha256-MACPKCWuUuMe37dE84AoWeWH2S4EIp/LFqihvwBzSiY=";
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ];
doCheck = false;
};
# Headless Chromium for browser automation (benchmarks/). The npm
# playwright-core devDependency in package.json must be pinned to the
# exact version of pkgs.playwright-driver so the browser revisions in
# this bundle match what the library looks for.
playwright-browsers = pkgs.playwright-driver.browsers.override {
withFirefox = false;
withWebkit = false;
};
android-sdk = pkgs.androidenv.composeAndroidPackages {
platformVersions = [ "36" ];
# Android Gradle Plugin 8.13 defaults to Build Tools 35.0.0. Include
# that version explicitly because the Nix SDK is immutable and Gradle
# cannot install its default version at build time.
buildToolsVersions = [ "35.0.0" "36.0.0" ];
};
in rec {
devShell = pkgs.mkShell {
buildInputs = [
pkgs.nodejs
pkgs.pnpm
pkgs.jdk21
android-sdk.androidsdk
ngit-grasp-pkg
];
# Point the e2e harness at the pinned ngit-grasp binary. Without this
# the harness falls back to the sibling-clone heuristic
# (../ngit-grasp/target/release/ngit-grasp), which is fine for local
# dev but not reproducible in CI.
shellHook = ''
export NGIT_GRASP_BIN=${ngit-grasp-pkg}/bin/ngit-grasp
export JAVA_HOME=${pkgs.jdk21}
export ANDROID_HOME=${android-sdk.androidsdk}/libexec/android-sdk
export ANDROID_SDK_ROOT="$ANDROID_HOME"
# Capacitor only exposes telemetry as a per-machine CLI preference,
# not a project config option. Enforce the opt-out whenever this
# development shell is entered, once dependencies are installed.
if [ -x node_modules/.bin/cap ]; then
node_modules/.bin/cap telemetry off
fi
# AGP normally downloads aapt2 from Maven, but that binary is not
# runnable on NixOS. Use the aapt2 packaged in the Nix SDK instead.
export GRADLE_OPTS="''${GRADLE_OPTS:+$GRADLE_OPTS }-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_HOME/build-tools/35.0.0/aapt2"
if git rev-parse --git-dir >/dev/null 2>&1; then
hooks_dir="$(git rev-parse --git-dir)/hooks"
mkdir -p "$hooks_dir"
hook="$hooks_dir/pre-push"
if [ -f "$hook" ] && ! grep -q "gitworkshop generated pre-push hook" "$hook"; then
echo "Leaving existing custom pre-push hook in place: $hook"
else
cat > "$hook" <<'EOF'
#!/bin/sh
# gitworkshop generated pre-push hook
set -eu
zero=0000000000000000000000000000000000000000
run_e2e=0
is_relevant_path() {
case "$1" in
e2e/*|vitest.e2e.config.ts|src/lib/git-*|src/lib/git-grasp-pool/*|src/lib/vendored/git-natural-api/*|src/hooks/useGitPool.ts|src/hooks/useGitExplorer.ts|src/pages/repo/RepoCodePage.tsx|src/components/MergePanel.tsx)
return 0
;;
*)
return 1
;;
esac
}
check_range() {
base="$1"
tip="$2"
for path in $(git diff --name-only "$base" "$tip"); do
if is_relevant_path "$path"; then
run_e2e=1
return
fi
done
}
while read -r local_ref local_sha remote_ref remote_sha; do
[ "$local_sha" = "$zero" ] && continue
if [ "$remote_sha" = "$zero" ]; then
upstream="$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null || true)"
if [ -n "$upstream" ]; then
base="$(git merge-base "$local_sha" "$upstream" 2>/dev/null || true)"
if [ -n "$base" ]; then
check_range "$base" "$local_sha"
else
run_e2e=1
fi
else
run_e2e=1
fi
else
check_range "$remote_sha" "$local_sha"
fi
done
if [ "$run_e2e" -eq 0 ]; then
echo "Skipping e2e pre-push: no git/GRASP/e2e paths changed."
exit 0
fi
if command -v pnpm >/dev/null 2>&1 && pnpm --version >/dev/null 2>&1; then
pnpm run pre-push
else
npm run pre-push
fi
EOF
chmod +x "$hook"
fi
fi
'';
};
devShells = {
default = devShell;
# Browser-benchmark shell (`nix develop .#bench`). Kept separate so
# ordinary `nix develop` entries don't realise the ~1 GB Chromium
# bundle that only `pnpm bench` needs.
bench = pkgs.mkShell {
buildInputs = [
pkgs.nodejs
pkgs.pnpm
];
# playwright-core downloads no browsers at install time; point it
# at the Nix-provided bundle. Host-requirement validation checks
# FHS paths that don't exist on NixOS, so skip it.
PLAYWRIGHT_BROWSERS_PATH = playwright-browsers;
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = "true";
};
};
});
}