diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..2da5bd8473 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +env=$(nix-build --no-out-link "$PWD/direnv.nix") +PATH_add "${env}" + +# allow local .envrc overrides +[[ -f .envrc.local ]] && source_env .envrc.local diff --git a/Makefile b/Makefile index 465c03ca2d..980fffa320 100644 --- a/Makefile +++ b/Makefile @@ -234,7 +234,7 @@ libzauth: .PHONY: hie.yaml hie.yaml: stack-dev.yaml stack build implicit-hie - stack exec gen-hie | nix-shell --command 'yq "{cradle: {stack: {stackYaml: \"./stack-dev.yaml\", components: .cradle.stack}}}" > hie.yaml' + stack exec gen-hie | yq "{cradle: {stack: {stackYaml: \"./stack-dev.yaml\", components: .cradle.stack}}}" > hie.yaml .PHONY: stack-dev.yaml stack-dev.yaml: diff --git a/changelog.d/5-internal/direnv_buildEnv b/changelog.d/5-internal/direnv_buildEnv new file mode 100644 index 0000000000..8ee4394ab6 --- /dev/null +++ b/changelog.d/5-internal/direnv_buildEnv @@ -0,0 +1 @@ +Replace shell.nix with direnv + nixpkgs.buildEnv based setup \ No newline at end of file diff --git a/shell.nix b/direnv.nix similarity index 86% rename from shell.nix rename to direnv.nix index 334f8007c3..c29ac40da5 100644 --- a/shell.nix +++ b/direnv.nix @@ -90,11 +90,21 @@ let binPath = "client/bin/kubectl"; }; + + kind = staticBinary { + pname = "kind"; + version = "0.11.0"; + + darwinAmd64Url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-darwin-amd64"; + darwinAmd64Sha256 = "432bef555a70e9360b44661c759658265b9eaaf7f75f1beec4c4d1e6bbf97ce3"; + + linuxAmd64Url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-linux-amd64"; + linuxAmd64Sha256 = "949f81b3c30ca03a3d4effdecda04f100fa3edc07a28b19400f72ede7c5f0491"; + }; }; -in pkgs.mkShell { - name = "shell"; - LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; # works around https://github.com/tweag/ormolu/issues/38 - buildInputs = [ +in pkgs.buildEnv { + name = "wire-server-direnv"; + paths = [ pkgs.docker-compose pkgs.gnumake pkgs.haskell-language-server @@ -107,11 +117,12 @@ in pkgs.mkShell { # To actually run buildah on nixos, I had to follow this: https://gist.github.com/alexhrescale/474d55635154e6b2cd6362c3bb403faf pkgs.buildah - pkgs.kind pinned.stack pinned.helm pinned.helmfile pinned.kubectl + pinned.kind ]; } + diff --git a/docs/developer/dependencies.md b/docs/developer/dependencies.md index 25a15e4205..3cd670834e 100644 --- a/docs/developer/dependencies.md +++ b/docs/developer/dependencies.md @@ -174,11 +174,12 @@ docker login --username= * [Install docker](https://docker.com) * [Install docker-compose](https://docs.docker.com/compose/install/) -## Nix +## Nix + Direnv Using Stack's [Nix integration](https://docs.haskellstack.org/en/stable/nix_integration/), Stack will take care of installing any system dependencies automatically - including `cryptobox-c`. If new system dependencies are needed, add them to the `stack-deps.nix` file in the project root. -Just type `$ nix-shell` and you will automatically have `make`, `docker-compose` and `stack` in `PATH`. + +If you have `direnv` and `nix`, you will automatically have `make`, `docker-compose` and `stack` in `PATH` once you `cd` into the project root and `direnv allow`. You can then run all the builds, and the native dependencies will be automatically present. ## Telepresence diff --git a/docs/developer/editor-setup.md b/docs/developer/editor-setup.md index 99509513fe..e21d59025b 100644 --- a/docs/developer/editor-setup.md +++ b/docs/developer/editor-setup.md @@ -57,6 +57,16 @@ Install the [projectile][] package for Emacs and do `M-x projectile-add-known-pr ad-do-it))) ``` +### Haskell Language Server + +To use HLS bundled in direnv setup, here is a sample `.dir-locals.el` that can +be put in the root directory of the project: +```el +((haskell-mode . ((haskell-completion-backend . lsp) + (lsp-haskell-server-path . "/home/haskeller/code/wire-server/hack/bin/nix-hls.sh") + ))) +``` + ### Ormolu integration There are make targets `format`, `formatf`, `formatc` to re-format diff --git a/hack/bin/nix-hls.sh b/hack/bin/nix-hls.sh new file mode 100755 index 0000000000..488cc122e6 --- /dev/null +++ b/hack/bin/nix-hls.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +TOP_LEVEL="$(cd "$DIR/../.." && pwd)" + +env=$(nix-build --no-out-link "$PWD/direnv.nix") +export PATH="$env/bin:$PATH" +haskell-language-server-wrapper "$@"