Skip to content

Commit

Permalink
Merge pull request #2855 from informalsystems/update-flake
Browse files Browse the repository at this point in the history
Update flake and improve nix setup for development
  • Loading branch information
bugarela authored Mar 8, 2024
2 parents c518278 + 70d6603 commit 811b480
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 36 deletions.
16 changes: 15 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ it here!
We provide a nix shell in case you want to use nix to manage your development
environment and dependencies. The primary benefits of using the nix shell is
that it allows us to keep environments consistent, and distribute updates to
environment dependencies.
environment dependencies. Alternatively, you can also use `direnv` to load
dependencies from nix.

#### Getting Nix

Expand All @@ -202,6 +203,19 @@ Once you have `nix` installed, build and enter the clean development shell with:
$ nix develop
```

#### Loading nix dependencies with direnv

If you want to use direnv to setup your environment with nix (instead of using a
shell), you will need to add `use flake;` to your `.local-envrc`, and then
running `direnv allow`:

```sh
echo "use flake;" >> .local-envrc && direnv allow
```

You can also add a `direnv` extension/package to your IDE of choice to have
those dependencies set up for the IDE to use.

#### Updating nix dependencies

To update one of the flake inputs you can run: `nix flake lock --update-input <input-name>`
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 49 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# dependencies.
inputs = {
# Nix Inputs
nixpkgs.url = github:nixos/nixpkgs/nixpkgs-unstable;
flake-utils.url = github:numtide/flake-utils;
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

# Outputs define the result of a flake. I use the term result to be intentionally vague since flakes
Expand All @@ -30,11 +30,11 @@
# FIXME(#2565): pin old nixpkgs, to pull in mdx 2.1.0, need to workaround this regression:
# https://github.com/realworldocaml/mdx/issues/428
pkgsOldMdx = import (builtins.fetchTarball {
url = https://github.com/NixOS/nixpkgs/archive/76be8d2d04a00e5e2df6fa147dfc4797874edc97.tar.gz;
url =
"https://github.com/NixOS/nixpkgs/archive/76be8d2d04a00e5e2df6fa147dfc4797874edc97.tar.gz";
sha256 = "Nw1lgrAQG++uzYQc1SilzGdeoy9RZ/HwcKlbaAp1rTE=";
}) { inherit system; };
in
{
in {
# Nix Build
# Command: `nix build .#<attr-name>`
# Reference documentation: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-build.html
Expand All @@ -45,37 +45,57 @@
# The reason we use packages, instead of the devShell attribute directly, is so that we can potentially
# provide multiple shells in the future.
packages = {
dev-shell =
pkgs.mkShell {
dev-shell = pkgs.mkShell {

# Commands that run when the shell starts
shellHook = ''
# Add common project environment variables
source ./.envrc
# Commands that run when the shell starts
shellHook = ''
# This is a copy from the .envrc file contents. We do this instead of sourcing the .envrc
# to avoid circular dependencies when using direnv with nix ("use flake").
# Required to avoid polluting the dev-shell's ocaml environment with
# dynamically liked libs from the host environment
unset CAML_LD_LIBRARY_PATH
'';
# This function is to protect local variables from polluting downstream scripts
# that source this one.
exports () {
# The directory of this file
local DIR="$( cd "$( dirname "$\{
BASH_SOURCE [ 0 ]
}" )" >/dev/null 2>&1 && pwd )"
# Provide reference to the target directory
export TARGET_DIR=$DIR/target
# Built inputs are the packages that we provide in the PATH in the nix shell
buildInputs = with pkgs; [
# Java / Scala
jdk17_headless
scala_2_12
# Add executables to path
export PATH=$DIR/bin:$PATH
# Build
sbt
# Base path for looking up the Apalache standard library, see
# https://github.com/informalsystems/apalache/pull/1553
export APALACHE_HOME=$DIR
}
# Development
metals
exports
# .envrc contents end here
# Testing
pkgsOldMdx.ocamlPackages.mdx
python39Full
];
};
# Required to avoid polluting the dev-shell's ocaml environment with
# dynamically liked libs from the host environment
unset CAML_LD_LIBRARY_PATH
'';

# Built inputs are the packages that we provide in the PATH in the nix shell
buildInputs = with pkgs; [
# Java / Scala
jdk17_headless
scala_2_13

# Build
sbt

# Development
metals

# Testing
pkgsOldMdx.ocamlPackages.mdx
python39Full
];
};
};

# Nix Develop
Expand Down

0 comments on commit 811b480

Please sign in to comment.