-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
189 lines (160 loc) · 5.36 KB
/
flake.nix
File metadata and controls
189 lines (160 loc) · 5.36 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{
description = "UbiCity - Learning Capture System (RSR-Compliant)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
# Rust with WASM target
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [ "wasm32-unknown-unknown" ];
};
# ReScript from npm (using nodePackages)
rescript = pkgs.nodePackages.rescript or (pkgs.buildNpmPackage rec {
pname = "rescript";
version = "11.0.0";
src = pkgs.fetchurl {
url = "https://registry.npmjs.org/rescript/-/rescript-${version}.tgz";
hash = "sha256-placeholder"; # Replace with actual hash
};
npmDepsHash = "sha256-placeholder"; # Replace with actual hash
});
in
{
# Development shell
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
# Deno
deno
# Rust + WASM
rustToolchain
wasm-pack
wasm-bindgen-cli
binaryen # wasm-opt
# ReScript
nodejs
nodePackages.npm
rescript
# Build tools
just
git
# Optional tools
nixpkgs-fmt
cargo-watch
];
shellHook = ''
echo "🏙️ UbiCity Development Environment"
echo ""
echo "Available commands:"
echo " just setup - Setup development environment"
echo " just build - Build ReScript + WASM"
echo " just test - Run tests"
echo " just --list - Show all commands"
echo ""
echo "Versions:"
echo " Deno: $(deno --version | head -1)"
echo " Rust: $(rustc --version)"
echo " ReScript: $(rescript -version 2>/dev/null || echo 'Not found')"
echo " Node: $(node --version)"
echo ""
# Set WASM target
export CARGO_BUILD_TARGET="wasm32-unknown-unknown"
# Add local bin to PATH
export PATH="$PWD/bin:$PATH"
'';
# Environment variables
DENO_DIR = "./.deno";
CARGO_HOME = "./.cargo";
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
# Package derivation
packages.default = pkgs.stdenv.mkDerivation {
pname = "ubicity";
version = "0.3.0";
src = ./.;
buildInputs = with pkgs; [
deno
rustToolchain
nodejs
rescript
];
buildPhase = ''
# Build ReScript
rescript build
# Build WASM
cd wasm
cargo build --release --target wasm32-unknown-unknown
cd ..
# Optimize WASM
wasm-opt -Oz -o wasm/pkg/ubicity_bg.wasm \
wasm/target/wasm32-unknown-unknown/release/ubicity_wasm.wasm
# Cache Deno dependencies
deno cache --reload src/index.ts
'';
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/share/ubicity
# Copy source
cp -r src src-rescript wasm $out/share/ubicity/
cp deno.json justfile $out/share/ubicity/
# Create wrapper scripts
cat > $out/bin/ubicity <<EOF
#!/bin/sh
exec ${pkgs.deno}/bin/deno run \\
--allow-read --allow-write \\
$out/share/ubicity/src/cli.ts "\$@"
EOF
chmod +x $out/bin/ubicity
cat > $out/bin/ubicity-capture <<EOF
#!/bin/sh
exec ${pkgs.deno}/bin/deno run \\
--allow-read --allow-write \\
$out/share/ubicity/src/capture.ts "\$@"
EOF
chmod +x $out/bin/ubicity-capture
'';
meta = with pkgs.lib; {
description = "Learning capture system for informal urban education";
homepage = "https://github.com/Hyperpolymath/ubicity";
license = with licenses; [ mit ]; # Dual MIT / Palimpsest
maintainers = []; # Add maintainers here
platforms = platforms.unix;
};
};
# Formatter
formatter = pkgs.nixpkgs-fmt;
# Apps
apps = {
ubicity = {
type = "app";
program = "${self.packages.${system}.default}/bin/ubicity";
};
capture = {
type = "app";
program = "${self.packages.${system}.default}/bin/ubicity-capture";
};
};
# Checks (tests)
checks = {
build = self.packages.${system}.default;
test = pkgs.runCommand "ubicity-tests" {
buildInputs = [ pkgs.deno ];
} ''
cd ${./.}
${pkgs.deno}/bin/deno test --allow-read --allow-write tests/
touch $out
'';
};
}
);
}