forked from coredevices/PebbleOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
154 lines (146 loc) · 5.51 KB
/
Copy pathflake.nix
File metadata and controls
154 lines (146 loc) · 5.51 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
{
description = "Development environment for PebbleOS";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
};
outputs =
{ self, nixpkgs }:
let
sdkVersion = "0.1.6";
sdkBundles = {
aarch64-darwin = {
osArch = "darwin-aarch64";
sha256 = "d389ecf084c168f6b18edfec972be8790521e81750d6fbfc352275206839bec2";
};
aarch64-linux = {
osArch = "linux-aarch64";
sha256 = "3c5f87380d7498ccaaa4ade45c105e97fa39aa71dec6b615d924e490978acb60";
};
x86_64-linux = {
osArch = "linux-x86_64";
sha256 = "a93d33f479154f96351590709af57ef79465ebee07c06f5e264a086eb1ca55b6";
};
};
forSupportedSystems = nixpkgs.lib.genAttrs (builtins.attrNames sdkBundles);
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 {
hardeningDisable = [ "fortify" ]; # waf expects unoptimized builds
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
pebbleos-sdk
gettext
git
librsvg
nodejs
openocd
protobuf
python313
] ++ lib.optionals stdenv.isLinux [
# multilib clang (i686 sysroot for -m32 test builds) is x86-only
(if stdenv.hostPlatform.isx86_64 then clang_multi else clang)
gcc
# Required for Moddable build
dash
glib
gtk3
];
shellHook = ''
# Ensure that apple command line tools are installed on macOS
${pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
# Verify Apple Command Line Tools are installed
if ! /usr/bin/xcrun --find clang &> /dev/null; then
echo "❌ Error: Apple Command Line Tools not found!"
echo " Please install with: xcode-select --install"
exit 1
fi
echo "✓ Apple CLT found: $(/usr/bin/clang --version | head -1)"
# Moddable's mac/tools.mk generates launcher scripts via
# `echo '...\n...'` and depends on `\n` being expanded. macOS
# /bin/sh (bash 3.2, XSI-compliant in POSIX mode) does this,
# but Nix's bash 5.x — picked up as `sh` via PATH — does not,
# producing scripts with a malformed shebang. Pin make's SHELL
# to /bin/sh so the recipe runs under the expected shell.
export MAKEFLAGS="SHELL=/bin/sh"
''}
# Disable pyenv to avoid conflicts
export PYENV_VERSION=system
unset PYENV_ROOT
# Prepare the python venv
export VENV_DIR=".venv"
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment..."
python -m venv "$VENV_DIR"
source "$VENV_DIR/bin/activate"
if [ -f "requirements.txt" ]; then
echo "Installing Python dependencies..."
pip install -r requirements.txt
fi
else
source "$VENV_DIR/bin/activate"
fi
echo "Python virtual environment activated."
'';
};
}
);
};
}