Skip to content

Commit

Permalink
Add contributing.md chapter on Nix
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchmindtree committed Jan 21, 2024
1 parent a5845dd commit c51c497
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions guide/src/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ you in the right direction.
- [**PR Checklist**](./contributing/pr-checklist.md)
- [**PR Reviews**](./contributing/pr-reviews.md)
- [**Publishing New Versions**](./contributing/publishing-new-versions.md)
- [**Nix Shell**](./contributing/nix-shell.md)

## Still have questions?

Expand Down
54 changes: 54 additions & 0 deletions guide/src/contributing/nix-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Nix Shell

The nannou repo offers a Nix shell as a way of providing a reproducible
environment across both macOS and Linux. This simplifies the nannou repo CI a
little while making it easier to experiment with nannou using a known working
environment.

### Installing Nix

The [Determinate Systems installer](https://github.com/DeterminateSystems/nix-installer)
is one of the easiest ways to get started with Nix.

### Nannou's Nix Files

- **default.nix** - A derivation that describes how to build the nannou Rust
package, including all of its examples and with all of the necessary environment
variables. This is what is built by default when running `nix build`. When
- **shell.nix** - A derivation that describes a development shell providing all
of the necessary system dependencies and environment variables for working on
nannou and its examples.
- **flake.nix** - A Nix manifest standard declaring the `nannou` package and
devShell.

### Adding a `nannou` Dependency

When adding a new package (e.g. system dependency):

1. Find the package in nixpkgs (`nix search nixpkgs <name>` is handy)
2. Add the package to the `default.nix` input attribute set.
3. Add the package to `buildInputs` if its a runtime dependency, or
`nativeBuildInputs` if its a build-time dependency.

### Adding a Development Shell Dependency

To add handy development dependencies (e.g. rustfmt, rust-analyser), do the same
but add them to `shell.nix` instead.

### Adding Environment Variables

Add these to the `env` attributes within either `default.nix` or `shell.nix`.

### Build Everything

Build all binaries, examples and dylibs within the `nannou` workspace with
`nix build`. When finished, look in the `result` symlink directory to find all
of the built binaries.

### Enter a nannou `devShell`

To enter a development shell with all of the tools and env vars necessary for
nannou dev, use `nix develop`.

To quickly enter a nannou dev shell to build a downstream nannou project, you
can use: `nix develop github:nannou-org/nannou`.

0 comments on commit c51c497

Please sign in to comment.