Skip to content
zz0-0Public

About

Nix devshell configuration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

98 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

DevShell Flake: Multi-Language Development Environments

A modular Nix flake providing development environments for multiple programming languages, built around the NixOS + direnv workflow: each project folder gets its own isolated toolchain (language servers, formatters, linters, dependency management) with no containers or VMs โ€” the Nix store deduplicates everything.

โœจ Features

  • Per-Folder Isolation: use flake in a project's .envrc activates exactly the toolchain that project needs
  • Editor Integration: Automatic .vscode/settings.json and .zed/settings.json generation; LSP servers resolve through the project's direnv environment, so they work regardless of how the editor was launched.
  • Automatic Dependency Management: Detects dependency files and installs/syncs them (poetry/pip, cargo, pub, maven)
  • Sane TERM fallback: Restores xterm-256color when the parent environment reports TERM=dumb, so Starship and other prompt tools keep working
  • Language-Aware Tools: Includes language servers, formatters, and linters
  • Project Scaffolding: nix flake init -t devshell#<lang> creates a ready-to-use project
  • Cross-Platform: Supports x86_64-linux and aarch64-linux

๐Ÿš€ Quick Start

# Scaffold + direnv allow in one step, then prints the next steps
nix run github:zz0-0/devshell#new -- python myproj

Or by hand:

# 1. Scaffold a project (creates flake.nix + .envrc + .gitignore)
nix flake init -t github:zz0-0/devshell#python

# 2. Enable direnv
direnv allow

That's it. Entering the directory now gives you a Python environment with pyright/ruff, auto-venv, and automatic dependency installation โ€” isolated to that folder.

Without Templates

# flake.nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    devshell.url = "github:zz0-0/devshell";
  };

  outputs = { self, nixpkgs, devshell }: {
    # Supported systems: x86_64-linux, aarch64-linux
    devShells.x86_64-linux.default = devshell.lib.x86_64-linux.python { };
  };
}
echo "use flake" > .envrc && direnv allow

Or without direnv: nix develop to enter the shell interactively.

The flake also exposes devShells.default with the Nix tooling (nixd, nil, nixfmt, statix, deadnix) for editing this repository itself. Run direnv allow here once if you want it loaded automatically.

๐Ÿ“ฆ Supported Languages

Language Function Tools Included
Python devshell.lib.<system>.python python3, pip, poetry, ruff, basedpyright
Rust devshell.lib.<system>.rust cargo, rustc, rust-analyzer, rustfmt, clippy, lldb
Bevy devshell.lib.<system>.bevy Rust toolchain + ALSA, udev, Vulkan, X11/Wayland, Mesa, mold, cargo-nextest
Flutter devshell.lib.<system>.flutter flutter, android-sdk, jdk17, gradle, cmake, chromium
LaTeX devshell.lib.<system>.latex texlive (scheme-medium + latexextra), texlab, pandoc, ghostscript
Nix devshell.lib.<system>.nix nil, nixd, statix, nixfmt, deadnix
Markdown devshell.lib.<system>.markdown markdown-oxide
PostgreSQL devshell.lib.<system>.postgresql postgresql + start_pg/stop_pg/reset_pg helpers
Java devshell.lib.<system>.java jdk25, jdt-language-server, maven, gradle
Video devshell.lib.<system>.video ffmpeg, Chromium, Node, Python, uv, media CLI, Whisper, Assimp
Web devshell.lib.<system>.web node, Chromium, web-check๏ผˆๆ‰‹ๅ†™ HTML/CSS ็š„ๆœบๆขฐ้”™๏ผ‰

ๅ…ฌๅ…ฑๆŽฅๅฃ

  • lib.<system>.<lang> โ€”โ€” ็จณๅฎšใ€‚ๅ‚ๆ•ฐ่งๅ„่ฏญ่จ€ๆ–‡ไปถๅคด้ƒจใ€‚
  • packages.<system>.web-check โ€”โ€” ๅ•ไธชๆฃ€ๆŸฅ๏ผŒๅฏไปฅๆŒ‚ๅˆฐไปปไฝ•่ฏญ่จ€ไธŠ๏ผˆextraPackages๏ผ‰๏ผŒไธๅฟ…ๆ‹–ๆ•ดๅฅ— web ๅทฅๅ…ท้“พใ€‚
  • templates/<lang> โ€”โ€” ็จณๅฎšใ€‚ๆจกๆฟ็”Ÿๆˆ็š„ๆ–‡ไปถไนŸ็ฎ—ๆŽฅๅฃใ€‚
  • languages/ใ€scripts/ โ€”โ€” ๅ†…้ƒจๅฎž็Žฐ๏ผŒๅฏ่ƒฝๅ˜ใ€‚

ๅ„่ฏญ่จ€ๅ…ทไฝ“่ฃ…ไบ†ไป€ไนˆใ€ไพ่ต–ๆ€ŽไนˆๅŒๆญฅ๏ผŒ่ง docs/languages.mdใ€‚

๐Ÿ”ง Customizing Environments

# Add extra packages to any environment
devShells.x86_64-linux.default = devshell.lib.x86_64-linux.python {
  extraPackages = [ pkgs.redis ];
};

# Flutter with emulator support
devShells.x86_64-linux.default = devshell.lib.x86_64-linux.flutter {
  withEmulator = true;
};

# Choose a different Python or JDK
devShells.x86_64-linux.default = devshell.lib.x86_64-linux.python {
  python = pkgs.python312;
};
devShells.x86_64-linux.default = devshell.lib.x86_64-linux.java {
  jdk = pkgs.jdk21;
};

๐Ÿ—๏ธ Project Structure

.devshell/
โ”œโ”€โ”€ flake.nix                # Main flake configuration (lib, formatter, checks, templates)
โ”œโ”€โ”€ languages/
โ”‚   โ”œโ”€โ”€ common.nix           # Shared helpers (LSP wrappers, settings writers)
โ”‚   โ”œโ”€โ”€ python.nix           # Python development environment
โ”‚   โ”œโ”€โ”€ rust.nix             # Rust development environment
โ”‚   โ”œโ”€โ”€ bevy.nix             # Bevy game development environment
โ”‚   โ”œโ”€โ”€ flutter.nix          # Flutter development environment
โ”‚   โ”œโ”€โ”€ latex.nix            # LaTeX development environment
โ”‚   โ”œโ”€โ”€ nix.nix              # Nix development tools
โ”‚   โ”œโ”€โ”€ markdown.nix         # Markdown tooling
โ”‚   โ”œโ”€โ”€ postgresql.nix       # PostgreSQL development environment
โ”‚   โ”œโ”€โ”€ java.nix             # Java development environment
โ”‚   โ”œโ”€โ”€ video.nix            # Video production environment
  โ””โ”€โ”€ web.nix              # Static web project
โ””โ”€โ”€ templates/               # `nix flake init -t` scaffolds (one dir per language)

๐Ÿ”„ Auto-Generated Files

When you enter a devshell, it automatically creates (project-local, gitignored):

  • .vscode/settings.json โ€“ VS Code configuration (language server paths, formatters)
  • .zed/settings.json โ€“ Zed configuration
  • .zed/lsp/ โ€“ LSP wrapper scripts resolving through direnv exec
  • .venv/ โ€“ Python virtual environment (Python shells)
  • .dart_tool/ โ€“ Flutter cache and stamp files
  • .postgres/ โ€“ PostgreSQL data directory (PostgreSQL shells)
  • .bin/ โ€“ Symlinks to Nix tools (Nix shell)
  • target/ โ€“ Rust build directory

All files are regenerated idempotently: nothing is wiped on updates, and files are only rewritten when their content actually changed.

๐Ÿง  How It Works

  • direnv + use flake is the core mechanism: entering a project directory loads its devShells.default, so PATH and environment variables come from the Nix store and are scoped to that folder.
  • LSP wrappers (languages/common.nix) resolve the project root from their own location and run the language server via direnv exec, so Zed/VS Code always use the exact toolchain of the project โ€” even when launched from outside the shell.
  • Hash stamps skip expensive operations (venv install, cargo fetch, flutter pub get, maven fetch) until the dependency files actually change.

Combining Languages

Shells can be combined for multi-language projects; each shell writes a Zed settings fragment (.zed/lsp-config/<lang>.json) and they are deep-merged into .zed/settings.json:

devShells.${system}.default = pkgs.mkShellNoCC {
  buildInputs = nixShell.buildInputs ++ markdownShell.buildInputs;
  shellHook = ''
    ${nixShell.shellHook}
    ${markdownShell.shellHook}
  '';
};

Video can be combined the same way:

let
  pythonShell = devshell.lib.${system}.python { };
  rustShell = devshell.lib.${system}.rust { };
  videoShell = devshell.lib.${system}.video { };
in
devShells.${system}.default = pkgs.mkShellNoCC {
  buildInputs = pythonShell.buildInputs ++ rustShell.buildInputs ++ videoShell.buildInputs;
  shellHook = ''
    ${pythonShell.shellHook}
    ${rustShell.shellHook}
    ${videoShell.shellHook}
  '';
};

Note: .vscode/settings.json can only hold one language's configuration โ€” the last shell in the hook wins there. Zed settings merge correctly for all shells.

โœ… Validation

nix flake check evaluates every language shell and builds the lightweight nix and markdown shells. The heavy language shells (Flutter, LaTeX, video, PostgreSQL, Java) are eval-only so the check stays practical. There is no cloud CI; pre-push runs the checks locally. A fresh clone needs ./scripts/setup.sh once to point git at .githooks/.

ๆจกๆฟไนŸๆ˜ฏๅ…ฌๅ…ฑๆŽฅๅฃ๏ผŒๅ•็‹ฌๅ†’็ƒŸ๏ผˆๅคๅˆถๅˆฐไธดๆ—ถ็›ฎๅฝ•๏ผŒ็œŸ็š„่ฟ›ไธ€ๆฌก shell๏ผ‰๏ผš

./scripts/check-templates.sh              # ๅ…จ้ƒจ๏ผŒ้ฆ–ๆฌก็บฆ 1-2 ๅˆ†้’Ÿ
./scripts/check-templates.sh x86_64-linux rust   # ๆŒ‡ๅฎšๆจกๆฟ
EVAL_ONLY=1 ./scripts/check-templates.sh  # ๅชๅฎžไพ‹ๅŒ–๏ผŒไธๆž„ๅปบ

ๅ…ฌๅ…ฑๆŽฅๅฃ็š„ๅ‚ๆ•ฐๅไนŸไธ่ƒฝๅ˜๏ผš

./scripts/check-interface.sh              # ๅฏนๆฏ” interface.json
./scripts/check-interface.sh --update     # ็กฎ่ฎคๆ˜ฏๆœ‰ๆ„็š„็ ดๅๆ€งๅ˜ๆ›ดๅŽ๏ผŒ้‡ๅ†™ๅŸบ็บฟ

ๆ–‡ๆกฃ้‡Œ็š„่ทฏๅพ„ๅผ•็”จ๏ผš

./scripts/check-doc-pointers.sh

Lint ๅ‘ฝไปค๏ผš

nix flake check
statix check .
deadnix --fail .
nixfmt --check $(git ls-files "*.nix")

๐Ÿ”’ Security Notes

  • Android Licenses: The Flutter environment attempts to accept Android SDK licenses automatically. If this fails, run flutter doctor --android-licenses manually.
  • Nix Config: This flake sets allowUnfree = true and android_sdk.accept_license = true for its own nixpkgs instance; no global config changes required.

๐Ÿค Contributing

To add a new language:

  1. Create a new file in languages/ following the existing pattern (uses helpers from common.nix)
  2. Add it to the lib outputs in flake.nix
  3. Add a template directory under templates/
  4. Run ./scripts/check-templates.sh x86_64-linux <lang> and nix flake check

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

About

Nix devshell configuration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages