• Stars
    star
    1,140
  • Rank 39,848 (Top 0.9 %)
  • Language
    Nix
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 13 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Per project developer environments

devshell - like virtualenv, but for all the languages

STATUS: unstable

Devshell Dev Environment Support room on Matrix

The goal of this project is to simplify per-project developer environments.

Imagine, a new employee joins the company, or somebody transfers teams, or somebody wants to contribute to one of your Open Source projects. It should take them 10 minutes to clone the repo and get all of the development dependencies.

Documentation

See docs (docs source)

Features

Compatible

Keep it compatible with:

  • nix-shell
  • direnv
  • nix flakes

Clean environment

pkgs.stdenv.mkDerivation and pkgs.mkShell build on top of the pkgs.stdenv which introduces all sort of dependencies. Each added package, like the pkgs.go in the "Story time!" section has the potential of adding new environment variables, which then need to be unset. The stdenv itself contains either GCC or Clang which makes it hard to select a specific C compiler.

This is why mkShell builds its environment from a builtins.derivation.

direnv loads will change from:

direnv: export +AR +AS +CC +CONFIG_SHELL +CXX +HOST_PATH +IN_NIX_SHELL +LD +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_BUILD_TOP +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_INDENT_MAKE +NIX_LDFLAGS +NIX_STORE +NM +OBJCOPY +OBJDUMP +RANLIB +READELF +RUSTC +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +TEMP +TEMPDIR +TMP +TMPDIR +buildInputs +buildPhase +builder +builtDependencies +cargo_bins_jq_filter +cargo_build_options +cargo_options +cargo_release +cargo_test_options +cargoconfig +checkPhase +configureFlags +configurePhase +cratePaths +crate_sources +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +docPhase +dontAddDisableDepTrack +dontUseCmakeConfigure +installPhase +name +nativeBuildInputs +out +outputs +patches +preInstallPhases +propagatedBuildInputs +propagatedNativeBuildInputs +remapPathPrefix +shell +src +stdenv +strictDeps +system +version ~PATH

to:

direnv: export +DEVSHELL_DIR +PRJ_DATA_DIR +PRJ_ROOT +IN_NIX_SHELL +NIXPKGS_PATH ~PATH

There are new environment variables useful to support the day-to-day activities:

  • DEVSHELL_DIR: contains all the programs.
  • PRJ_ROOT: points to the project root.
  • PRJ_DATA_DIR: points to $PRJ_ROOT/.data by default. Is used to store runtime data.
  • NIXPKGS_PATH: path to nixpkgs source.

Common utilities

The shell comes pre-loaded with some utility functions. I'm not 100% sure if those are useful yet:

  • menu - list all the programs available

MOTD

When entering a random project, it's useful to get a quick view of what commands are available.

When running nix-shell or nix develop, mkShell prints a welcome message:

πŸ”¨ Welcome to devshell

[[general commands]]

  hello         - prints hello
  menu          - prints this menu

[formatters]

  nixpkgs-fmt   - Nix code formatter for nixpkgs

[linters]

  golangci-lint - golang linter

[utilites]

  hub           - github utility

[devshell]$ 

Configurable with a TOML file

You might be passionate about Nix, but people on the team might be afraid of that non-mainstream technology. So let them write TOML instead. It should handle 80% of the use-cases and falling back on Nix is always possible.

Bash completion by default

Life is not complete otherwise. Huhu.

Packages that contain bash completions will automatically be loaded by mkShell in nix-shell or nix develop modes.

Capture development dependencies in CI

With a CI + Binary cache setup, one often wants to be able to capture all the build inputs of a shell.nix. With mkShell capturing all of the development dependencies is as easy as:

nix-build shell.nix | cachix push <mycache>

Runnable as a Nix application

Devshells are runnable (via nix run). This makes it possible to run commands defined in your devshell without entering a nix-shell or nix develop session:

nix run '.#<myapp>' -- <devshell-command> <and-args>

This project itself exposes a Nix application; you can try it out with:

nix run 'github:numtide/devshell' -- hello

See here for more details.

TODO

A lot of things!

  • Documentation
    • Explain how all of this works and all the use-cases.
  • Testing
    • Write integration tests for all of the use-cases.
  • Lazy dependencies
    • This requires some coordination with the repository structure. To keep the dev closure small, it would be nice to be able to load some of the dependencies on demand.
  • Doctor / nix version check
    • Not everything can be nicely sandboxed. Is it possible to get a fast doctor script that checks that everything is in good shape?
  • Support other shells
    • What? Not everyone is using bash? Right now, support is already available in direnv mode.

Contributing

Docs

  1. Change files in docs/
  2. Run nix run .#docs
  3. Open docs

Benchmark

  1. See benchmark/README.md
  2. Run nix run .#bench

Commercial support

Looking for help or customization?

Get in touch with Numtide to get a quote. We make it easy for companies to work with Open Source projects: https://numtide.com/contact

More Repositories

1

flake-utils

Pure Nix flake utility functions [maintainer=@zimbatm]
Nix
1,043
star
2

system-manager

Manage system config using nix on any distro
Rust
574
star
3

treefmt

one CLI to format your repo
Go
500
star
4

treefmt-nix

treefmt nix configuration
Nix
185
star
5

nix-filter

a small self-contained source filtering lib
Nix
182
star
6

nixpkgs-unfree

nixpkgs with the unfree bits enabled
Nix
84
star
7

nits

Nix & NATS
Go
76
star
8

nix-gl-host

Run OpenGL/Cuda programs built with Nix, on all Linux distributions.
Python
64
star
9

systemd-vaultd

Provide access to vault secrets to systemd services
Nix
61
star
10

nar-serve

Unpack and serve NAR file content on the fly
Go
30
star
11

prj-spec

Project Base Directory Specification
Shell
28
star
12

nix-vm-test

Re-use the NixOS VM test infrastructure to test Ubuntu, Debian, and Fedora machines.
Nix
28
star
13

terraform-provider-linuxbox

Configure Linux machines with Terraform
Go
27
star
14

bld

Build nix targets based on git repository directories
Go
27
star
15

deploykit

Execute commands remote via ssh and locally in parallel with python
Python
25
star
16

nix-stdlib

experimental nix prelude
Nix
24
star
17

action-cli

GitHub Actions without JavaScript
Rust
18
star
18

nix-eval-cache

Skips build/evaluation based on modification date of nix files.
Rust
17
star
19

software-consulting-documents

Software Consulting Legal Documents
16
star
20

blueprint

Nix without the glue code
Nix
15
star
21

github-deploy

Track deployments on GitHub PRs
Go
12
star
22

clean-git-action

Leave no build artifacts behind
Shell
10
star
23

serve-go

Like vercel/serve but for production. Serve SPA apps quickly.
Go
9
star
24

build-go-cache

buildGoCache speeds up nix's buildGoModule by pre-compiling imported go modules
Nix
8
star
25

nix-gitignore

filterSource using .gitignore (experiment)
Go
7
star
26

numtide-github-runner

the best self-hosted github runners on the market
Nix
7
star
27

terraform-deploy-nixos-flakes

Shell
5
star
28

nixos-rke2

NixOS modules for RKE2
Nix
5
star
29

terraform-upload-ami

Upload and import the AMI from a VHD
HCL
5
star
30

harvest-invoice-calculator

A little tool that helps generating invoices from Harvest data
Python
4
star
31

terraform-nixos-install

HCL
3
star
32

generate-terraform-provider-shim

Handle third-party Terraform providers
Go
3
star
33

nixpkgs-terraform

terraform-related packages with Nix
Nix
3
star
34

terraform-nix-build

Build Nix with the external provider
Python
2
star
35

nix-vm-test-demo

Dump of the code used in the nix-vm-test demo
Nix
2
star
36

yarnlock2json

Convert `yarn.lock` files to JSON
JavaScript
1
star
37

kartusche

Go
1
star
38

terraform-linuxbox-traefik

HCL
1
star
39

terraform-linuxbox-monitorpack

Seed DevOps monitoring module
HCL
1
star
40

activate

A small resource converger tool
Nix
1
star
41

gh-v6.com

GitHub downloads, with IPv6
HTML
1
star
42

configure-nix-action

Configures Nix on GitHub Actions
Shell
1
star
43

mkdocs-numtide

Our own mkdocs template, based on the material design
Nix
1
star
44

docker-host-forwarder

Docker image that will forward udp/tcp to docker host
Shell
1
star
45

terraform-nixos-amis

Fork of https://github.com/tweag/terraform-nixos/tree/master/aws_image_nixos
HCL
1
star
46

nixionary.org

HTML
1
star