crabidy/devenv.nix

103 lines
2.8 KiB
Nix

{
pkgs,
lib,
config,
inputs,
...
}:
let
pkgs-unstable = import inputs.nixpkgs-unstable { system = pkgs.stdenv.system; };
commonLibs = with pkgs; [ alsa-lib ];
extraPackages = with pkgs; [
d2
pkg-config
protobuf
cargo-cross
# Stream-URL sidecar for the ytdy provider: YouTube caps tokenless
# stream URLs at ~1 MiB and yt-dlp is the only maintained cipher
# solver (architecture/youtube-rustypipe.md, D2-revised).
yt-dlp
# Web client toolchain (architecture/web-client.md): trunk builds
# cbd-web to wasm, wasm-bindgen-cli must match the crate version,
# binaryen provides wasm-opt for release builds.
trunk
wasm-bindgen-cli
binaryen
];
in
{
imports = [ ./devenv-rust.nix ];
# The wasm target for cbd-web; merges with the languages.rust
# settings in devenv-rust.nix.
languages.rust.targets = [ "wasm32-unknown-unknown" ];
env = {
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath commonLibs;
};
# https://devenv.sh/packages/
packages = commonLibs ++ extraPackages;
# https://devenv.sh/processes/
# processes.cargo-watch.exec = "cargo-watch";
# https://devenv.sh/services/
# services.postgres.enable = true;
# https://devenv.sh/scripts/
scripts.hello.exec = ''
echo Welcome to rust devenv
'';
# Builds the web client bundle (cbd-web/dist), which crabidy-server
# embeds on its next build (architecture/web-client.md). RUSTFLAGS is
# cleared because the mold linker flag from the native toolchain
# (RUSTFLAGS wins over target-specific config) breaks rust-lld.
scripts.build-web.exec = ''
cd "$DEVENV_ROOT/cbd-web" && RUSTFLAGS="" trunk build --release "$@"
'';
# Dev loop: live-reloading trunk server proxying gRPC-web to a
# locally running crabidy-server.
scripts.serve-web.exec = ''
cd "$DEVENV_ROOT/cbd-web" && RUSTFLAGS="" trunk serve "$@"
'';
enterShell = "";
# https://devenv.sh/tasks/
# tasks = {
# "myproj:setup".exec = "mytool build";
# "devenv:enterShell".after = [ "myproj:setup" ];
# };
# https://devenv.sh/tests/
enterTest = ''
echo "Running tests"
'';
# https://devenv.sh/git-hooks/
git-hooks.hooks = {
nixfmt.enable = true;
taplo.enable = true;
markdownlint.enable = true;
shellcheck.enable = true;
};
# https://devenv.sh/integrations/claude-code/
# Claude Code integration: writes .claude/{settings,commands,agents}. We keep
# ownership of .mcp.json (skills wiring), so stop devenv from writing it.
claude.code.enable = true;
claude.code.mcpServers = lib.mkForce { };
claude.code.hooks.git-hooks-run.command = ''
f=$(${pkgs.jq}/bin/jq -r '.tool_input.file_path // empty')
if [ -n "$f" ]; then
cd "''${CLAUDE_PROJECT_DIR:-.}"
${lib.getExe config.git-hooks.package} run --files "$f"
fi
'';
# See full reference at https://devenv.sh/reference/options/
}