diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5e9a7ac988..bb715c0b05 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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 ` diff --git a/flake.lock b/flake.lock index 64a1db1331..dcfc2d0966 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1684879512, - "narHash": "sha256-BoAOf19Dshtfu6BDPznrKO97oeCkXlYfa1Hyt0Qv8VU=", + "lastModified": 1709780214, + "narHash": "sha256-p4iDKdveHMhfGAlpxmkCtfQO3WRzmlD11aIcThwPqhk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e6e049b7a24decd1f0caee8b035913795697c699", + "rev": "f945939fd679284d736112d3d5410eb867f3b31c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 8d087aaf21..7354fae431 100644 --- a/flake.nix +++ b/flake.nix @@ -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 @@ -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 .#` # Reference documentation: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-build.html @@ -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