Skip to content

Commit 4a7b0ee

Browse files
jamesbrinkclaude
andcommitted
Add Nix flake with CUDA devshell for hal9000 builds
Provides a devShell with rust-overlay toolchain, CUDA packages (nvcc, cudart, cublas, nvtx) on Linux, and proper LD_LIBRARY_PATH/CUDA_PATH env vars for RTX 4090 (sm_89). macOS shell includes libiconv for Metal builds. deploy.sh now always uses `nix develop` instead of falling back to system cargo. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4af79fb commit 4a7b0ee

6 files changed

Lines changed: 164 additions & 7 deletions

File tree

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
env:
1010
CARGO_TERM_COLOR: always
1111

12+
# Note: CUDA builds are not run in CI — they happen on hal9000 (NixOS + RTX 4090)
13+
# via scripts/deploy.sh. CI only checks non-CUDA compilation, lints, and tests.
14+
1215
jobs:
1316
check:
1417
name: Check

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ Cargo.lock
1010
*.jpeg
1111
*.jpg
1212
!docs/**/*.png
13+
14+
# Nix / direnv
15+
.direnv/
16+
result

flake.lock

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
description = "mold - like ollama, but for diffusion models";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
rust-overlay = {
8+
url = "github:oxalica/rust-overlay";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
};
12+
13+
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
14+
flake-utils.lib.eachDefaultSystem (system:
15+
let
16+
isLinux = builtins.elem system [ "x86_64-linux" "aarch64-linux" ];
17+
isDarwin = builtins.elem system [ "x86_64-darwin" "aarch64-darwin" ];
18+
overlays = [ rust-overlay.overlays.default ];
19+
pkgs = import nixpkgs {
20+
inherit system overlays;
21+
config.allowUnfree = true;
22+
config.cudaSupport = isLinux;
23+
};
24+
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
25+
extensions = [ "rust-src" "rustfmt" "clippy" ];
26+
};
27+
28+
commonInputs = [
29+
rustToolchain
30+
pkgs.pkg-config
31+
pkgs.openssl
32+
pkgs.git
33+
];
34+
35+
linuxInputs = pkgs.lib.optionals isLinux [
36+
pkgs.cudaPackages.cuda_nvcc
37+
pkgs.cudaPackages.cuda_cudart
38+
pkgs.cudaPackages.libcublas
39+
pkgs.cudaPackages.cuda_nvtx
40+
];
41+
42+
darwinInputs = pkgs.lib.optionals isDarwin [
43+
pkgs.libiconv
44+
];
45+
in
46+
{
47+
devShells.default = pkgs.mkShell {
48+
buildInputs = commonInputs ++ linuxInputs ++ darwinInputs;
49+
50+
env = pkgs.lib.optionalAttrs isLinux {
51+
CUDA_PATH = "${pkgs.cudaPackages.cuda_cudart}";
52+
CUDA_COMPUTE_CAP = "89"; # RTX 4090 = sm_89
53+
};
54+
55+
LD_LIBRARY_PATH = pkgs.lib.optionalString isLinux (
56+
(pkgs.lib.makeLibraryPath [
57+
pkgs.cudaPackages.cuda_cudart
58+
pkgs.cudaPackages.libcublas
59+
]) + ":/run/opengl-driver/lib"
60+
);
61+
62+
shellHook = ''
63+
echo "mold dev shell (${system})"
64+
'' + pkgs.lib.optionalString isLinux ''
65+
echo " CUDA enabled - build with: cargo build --release -p mold-server --features cuda"
66+
'' + pkgs.lib.optionalString isDarwin ''
67+
echo " macOS - build with: cargo build --release -p mold-server --features metal"
68+
'';
69+
};
70+
}
71+
);
72+
}

scripts/deploy.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ echo "🔨 Syncing source to hal9000..."
1010
rsync -av --exclude target --exclude .git --exclude "*.png" \
1111
./ "$REMOTE_USER@$HAL9000:$REMOTE_DIR/"
1212

13-
echo "🦀 Building on hal9000 (CUDA)..."
13+
echo "🦀 Building on hal9000 (CUDA via nix develop)..."
1414
ssh "$REMOTE_USER@$HAL9000" "
1515
cd $REMOTE_DIR
16-
# Try to use cargo directly, fallback to nix develop
17-
if command -v cargo &>/dev/null; then
18-
cargo build --release -p mold-server --features cuda 2>&1
19-
else
20-
nix develop --command cargo build --release -p mold-server --features cuda 2>&1
21-
fi
16+
nix develop --command cargo build --release -p mold-server --features cuda 2>&1
2217
"
2318

2419
echo "🛑 Stopping existing mold-server (if running)..."

0 commit comments

Comments
 (0)