-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathflake.nix
More file actions
148 lines (141 loc) · 5.2 KB
/
Copy pathflake.nix
File metadata and controls
148 lines (141 loc) · 5.2 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
{
description = "Development environment for PebbleOS";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
};
outputs =
{ self, nixpkgs }:
let
sdkVersion = "0.1.10";
sdkBundles = {
aarch64-darwin = {
osArch = "darwin-aarch64";
sha256 = "f2c8c60a19fdc90c5c588fd9c8a15bbd9f405e7fa949e83a77122aff69f0c057";
};
aarch64-linux = {
osArch = "linux-aarch64";
sha256 = "7b61cb3a5ba8c350f059a38c2742f4dc5120e3452a5fd8943e2606b8564f121b";
};
x86_64-linux = {
osArch = "linux-x86_64";
sha256 = "14260c23b6ba5443dabf4c31ec2a2a88822fa222b85b3ad7413bab990b0ffc4f";
};
};
forSupportedSystems = nixpkgs.lib.genAttrs (builtins.attrNames sdkBundles);
requirementsHash = builtins.hashString "sha256" (
builtins.concatStringsSep "\n" (map builtins.readFile [
./requirements.txt
./tools/libs/pbl-cli/pyproject.toml
./tools/libs/pebble-commander/pyproject.toml
./tools/libs/pulse2/pyproject.toml
./tools/libs/pebble-loghash/pyproject.toml
])
);
in
{
devShells = forSupportedSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
bundle = sdkBundles.${system};
pebbleos-sdk = pkgs.stdenv.mkDerivation {
pname = "pebbleos-sdk";
version = sdkVersion;
src = pkgs.fetchurl {
url = "https://github.com/coredevices/PebbleOS-SDK/releases/download/v${sdkVersion}/pebbleos-sdk-${sdkVersion}-${bundle.osArch}.tar.gz";
sha256 = bundle.sha256;
};
nativeBuildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux [
pkgs.autoPatchelfHook
];
buildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs; [
# arm-none-eabi host binaries (matches nixpkgs gcc-arm-embedded)
ncurses6
ncurses5 # aarch64-linux toolchain gdb links ABI-5 ncurses/tinfo
libxcrypt-legacy
xz
zstd
# qemu-pebble host binaries
glib
pixman
zlib
stdenv.cc.cc.lib
SDL2
libpng
alsa-lib
libpulseaudio
# sftool host binary
systemdLibs
]);
dontConfigure = true;
dontBuild = true;
dontStrip = true;
installPhase = ''
runHook preInstall
bash install.sh --prefix "$out" --defaults --force
# gdb-py variants need a Python 3.8 not packaged in nixpkgs.
rm -f "$out"/arm-none-eabi/bin/arm-none-eabi-gdb-py \
"$out"/arm-none-eabi/bin/arm-none-eabi-gdb-add-index-py
# Surface every SDK binary under $out/bin so PATH inclusion picks them up.
mkdir -p "$out/bin"
for d in arm-none-eabi/bin qemu/bin sftool; do
[ -d "$out/$d" ] || continue
for f in "$out/$d"/*; do
[ -f "$f" ] && [ -x "$f" ] && ln -sf "$f" "$out/bin/$(basename "$f")"
done
done
runHook postInstall
'';
};
in
{
default = pkgs.mkShellNoCC {
PEBBLEOS_SDK_ROOT = "${pebbleos-sdk}";
hardeningDisable = [ "fortify" ]; # the firmware is built unoptimized
packages = with pkgs; [
pebbleos-sdk
cmake
dash
gettext
git
librsvg
nodejs
openocd
protobuf
python313
meson
ninja
pkg-config
uv
# Host compiler for Moddable and tests; x86 Linux tests need multilib.
(if stdenv.isLinux && stdenv.hostPlatform.isx86_64 then clang_multi else clang)
] ++ lib.optionals stdenv.isLinux [
gcc
];
buildInputs = with pkgs; lib.optionals stdenv.isDarwin [
apple-sdk
] ++ lib.optionals stdenv.isLinux [
# Required for Moddable build
glib
gtk3
];
shellHook = ''
# Moddable's launcher recipes need echo to expand backslash escapes.
export MAKEFLAGS="''${MAKEFLAGS:+$MAKEFLAGS }SHELL=${pkgs.dash}/bin/dash"
export VENV_DIR=".venv"
if [ ! -f "$VENV_DIR/pyvenv.cfg" ]; then
uv venv --python ${pkgs.python313.interpreter} "$VENV_DIR" || exit 1
fi
source "$VENV_DIR/bin/activate" || exit 1
# Refresh only when requirements or editable package metadata change.
requirements_stamp="$VENV_DIR/.requirements.sha256"
if [ "${requirementsHash}" != "$(cat "$requirements_stamp" 2>/dev/null)" ]; then
uv pip install --python "$VENV_DIR/bin/python" -r requirements.txt || exit 1
printf '%s\n' "${requirementsHash}" > "$requirements_stamp"
fi
'';
};
}
);
};
}