Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol.
wisp.place
1{
2 description = "wisp-cli - Static site hosting CLI for AT Protocol";
3
4 # === INPUTS ===
5 # These are the dependencies of your flake (like package.json dependencies)
6 inputs = {
7 # nixpkgs is the main Nix package repository
8 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
9
10 # rust-overlay gives us easy access to Rust toolchains with cross-compilation targets
11 rust-overlay = {
12 url = "github:oxalica/rust-overlay";
13 inputs.nixpkgs.follows = "nixpkgs";
14 };
15
16 # flake-utils provides helpers for multi-system flakes
17 flake-utils.url = "github:numtide/flake-utils";
18 };
19
20 # === OUTPUTS ===
21 outputs = { self, nixpkgs, rust-overlay, flake-utils }:
22 flake-utils.lib.eachDefaultSystem (system:
23 let
24 overlays = [ (import rust-overlay) ];
25 pkgs = import nixpkgs { inherit system overlays; };
26
27 # Rust toolchain with cross-compilation targets
28 rustToolchain = pkgs.rust-bin.stable.latest.default.override {
29 targets = [
30 "x86_64-unknown-linux-musl"
31 "aarch64-unknown-linux-musl"
32 "x86_64-apple-darwin"
33 "aarch64-apple-darwin"
34 ];
35 };
36
37 version = "0.5.0";
38 pname = "wisp-cli";
39
40
41 # Linux cross-compilation (uses zig as linker for musl)
42 mkLinuxPackage = { target, suffix }: pkgs.stdenv.mkDerivation {
43 pname = "${pname}-${suffix}";
44 inherit version;
45 src = ./cli;
46
47 nativeBuildInputs = [
48 rustToolchain
49 pkgs.cargo-zigbuild
50 pkgs.zig
51 pkgs.cacert
52 ];
53
54 __noChroot = true;
55
56 buildPhase = ''
57 export HOME=$(mktemp -d)
58 export CARGO_HOME=$(mktemp -d)
59 export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
60 export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-C target-feature=+crt-static"
61 export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-C target-feature=+crt-static"
62 cargo zigbuild --release --target ${target}
63 '';
64
65 installPhase = ''
66 mkdir -p $out/bin
67 cp target/${target}/release/${pname} $out/bin/${pname}
68 '';
69
70 dontConfigure = true;
71 dontFixup = true;
72 };
73
74 # macOS builds (native cargo)
75 mkDarwinPackage = { target, suffix }: pkgs.stdenv.mkDerivation {
76 pname = "${pname}-${suffix}";
77 inherit version;
78 src = ./cli;
79
80 nativeBuildInputs = [ rustToolchain pkgs.cacert ];
81
82 __noChroot = true;
83
84 buildPhase = ''
85 export HOME=$(mktemp -d)
86 export CARGO_HOME=$(mktemp -d)
87 export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
88 cargo build --release --target ${target}
89 '';
90
91 installPhase = ''
92 mkdir -p $out/bin
93 cp target/${target}/release/${pname} $out/bin/${pname}
94 '';
95
96 dontConfigure = true;
97 dontFixup = true;
98 };
99
100 # Cross-compiled packages
101 linux-x86_64 = mkLinuxPackage {
102 target = "x86_64-unknown-linux-musl";
103 suffix = "linux-x86_64";
104 };
105
106 linux-aarch64 = mkLinuxPackage {
107 target = "aarch64-unknown-linux-musl";
108 suffix = "linux-aarch64";
109 };
110
111 macos-x86_64 = mkDarwinPackage {
112 target = "x86_64-apple-darwin";
113 suffix = "macos-x86_64";
114 };
115
116 macos-aarch64 = mkDarwinPackage {
117 target = "aarch64-apple-darwin";
118 suffix = "macos-aarch64";
119 };
120
121 # Build all targets and collect binaries
122 all = pkgs.stdenv.mkDerivation {
123 pname = "${pname}-all";
124 inherit version;
125 dontUnpack = true;
126
127 installPhase = ''
128 mkdir -p $out
129 cp ${linux-x86_64}/bin/${pname} $out/${pname}-linux-x86_64
130 cp ${linux-aarch64}/bin/${pname} $out/${pname}-linux-aarch64
131 cp ${macos-x86_64}/bin/${pname} $out/${pname}-macos-x86_64
132 cp ${macos-aarch64}/bin/${pname} $out/${pname}-macos-aarch64
133 '';
134 };
135
136 # Pick the right default based on current system
137 default = {
138 "x86_64-linux" = linux-x86_64;
139 "aarch64-linux" = linux-aarch64;
140 "x86_64-darwin" = macos-x86_64;
141 "aarch64-darwin" = macos-aarch64;
142 }.${system};
143
144 in {
145 packages = {
146 inherit default linux-x86_64 linux-aarch64 macos-x86_64 macos-aarch64 all;
147 };
148
149 devShells.default = pkgs.mkShell {
150 buildInputs = [
151 rustToolchain
152 pkgs.cargo-zigbuild
153 pkgs.zig
154 pkgs.rust-analyzer
155 ];
156 # Darwin stdenv includes SDK with frameworks and libiconv automatically
157 };
158 }
159 );
160}