From 43dcffa97fa875130b5517933c40e63ffdc950a6 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 4 Nov 2021 11:47:50 +0100 Subject: [PATCH 1/7] nix: add ormolu to wire-server-direnv --- direnv.nix | 7 ++++--- tools/ormolu.sh | 7 ------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/direnv.nix b/direnv.nix index c29ac40da57..2c2547e9a7b 100644 --- a/direnv.nix +++ b/direnv.nix @@ -105,14 +105,15 @@ let in pkgs.buildEnv { name = "wire-server-direnv"; paths = [ + pkgs.cfssl pkgs.docker-compose pkgs.gnumake + pkgs.grpcurl pkgs.haskell-language-server - pkgs.telepresence pkgs.jq - pkgs.grpcurl + pkgs.ormolu + pkgs.telepresence pkgs.wget - pkgs.cfssl pkgs.yq # To actually run buildah on nixos, I had to follow this: https://gist.github.com/alexhrescale/474d55635154e6b2cd6362c3bb403faf diff --git a/tools/ormolu.sh b/tools/ormolu.sh index 99734e27569..924cd93a4b9 100755 --- a/tools/ormolu.sh +++ b/tools/ormolu.sh @@ -4,13 +4,6 @@ set -e cd "$( dirname "${BASH_SOURCE[0]}" )/.." -command -v grep >/dev/null 2>&1 || { echo >&2 "grep is not installed, aborting."; exit 1; } -command -v sed >/dev/null 2>&1 || { echo >&2 "sed is not installed, aborting."; exit 1; } - -ORMOLU_VERSION=$(sed -n '/^extra-deps:/,$ { s/^- ormolu-//p }' < stack.yaml) -( ormolu -v 2>/dev/null | grep -q $ORMOLU_VERSION ) || ( echo "please install ormolu $ORMOLU_VERSION (eg., run 'stack install ormolu' and ensure ormolu is on your PATH.)"; exit 1 ) -echo "ormolu version: $ORMOLU_VERSION" - ARG_ALLOW_DIRTY_WC="0" ARG_ORMOLU_MODE="inplace" From 88aab94ad107db4fd33afd99b3ec32b4afa37d63 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 4 Nov 2021 11:48:39 +0100 Subject: [PATCH 2/7] direnv.nix: nixpkgs-fmt --- direnv.nix | 62 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/direnv.nix b/direnv.nix index 2c2547e9a7b..07281107a66 100644 --- a/direnv.nix +++ b/direnv.nix @@ -6,14 +6,17 @@ let src = if pkgs.stdenv.isDarwin - then pkgs.fetchurl { - url = darwinAmd64Url; - sha256 = darwinAmd64Sha256; - } - else pkgs.fetchurl { - url = linuxAmd64Url; - sha256 = linuxAmd64Sha256; - }; + then + pkgs.fetchurl + { + url = darwinAmd64Url; + sha256 = darwinAmd64Sha256; + } + else + pkgs.fetchurl { + url = linuxAmd64Url; + sha256 = linuxAmd64Sha256; + }; installPhase = '' mkdir -p $out/bin @@ -21,28 +24,31 @@ let ''; }; - staticBinary = { pname, version, linuxAmd64Url, linuxAmd64Sha256, darwinAmd64Url, darwinAmd64Sha256, binPath ? pname }: - pkgs.stdenv.mkDerivation { - inherit pname version; - - src = - if pkgs.stdenv.isDarwin - then pkgs.fetchurl { - url = darwinAmd64Url; - sha256 = darwinAmd64Sha256; - } - else pkgs.fetchurl { + staticBinary = { pname, version, linuxAmd64Url, linuxAmd64Sha256, darwinAmd64Url, darwinAmd64Sha256, binPath ? pname }: + pkgs.stdenv.mkDerivation { + inherit pname version; + + src = + if pkgs.stdenv.isDarwin + then + pkgs.fetchurl + { + url = darwinAmd64Url; + sha256 = darwinAmd64Sha256; + } + else + pkgs.fetchurl { url = linuxAmd64Url; sha256 = linuxAmd64Sha256; }; - phases = ["installPhase" "patchPhase"]; + phases = [ "installPhase" "patchPhase" ]; - installPhase = '' - mkdir -p $out/bin - cp $src $out/bin/${binPath} - chmod +x $out/bin/${binPath} - ''; - }; + installPhase = '' + mkdir -p $out/bin + cp $src $out/bin/${binPath} + chmod +x $out/bin/${binPath} + ''; + }; pinned = { stack = staticBinaryInTarball { @@ -102,7 +108,8 @@ let linuxAmd64Sha256 = "949f81b3c30ca03a3d4effdecda04f100fa3edc07a28b19400f72ede7c5f0491"; }; }; -in pkgs.buildEnv { +in +pkgs.buildEnv { name = "wire-server-direnv"; paths = [ pkgs.cfssl @@ -126,4 +133,3 @@ in pkgs.buildEnv { pinned.kind ]; } - From efa73cc7e697a74160d3035b144aff01cdbfe0e0 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 4 Nov 2021 11:51:18 +0100 Subject: [PATCH 3/7] .github/workflows: add ci.yml This builds the direnv, so it's available in the cachix binary cache. --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..cc979c6221e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +on: + pull_request: + push: + branches: [master] + +jobs: + build-dev-env: + name: Build dev env + strategy: + matrix: + os: + - ubuntu-latest + # This is too expensive + # - macos-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: cachix/install-nix-action@v14.1 + - uses: cachix/cachix-action@v10 + with: + name: wire-server + signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - name: Build the wire-server-direnv + run: nix-build --no-out-link direnv.nix From bb7b7db00ede8836bca2c34d58351ae534bb0d33 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 4 Nov 2021 11:53:03 +0100 Subject: [PATCH 4/7] .github/workflows/ci.yml: run make formatc This ensures the codebase is properly formatted. --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc979c6221e..ac692eec191 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,3 +25,7 @@ jobs: authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - name: Build the wire-server-direnv run: nix-build --no-out-link direnv.nix + - name: Install the wire-server-direnv + run: nix-env -f direnv.nix -i + - name: Ensure everything is formatted + run: make formatc From 56e6e614e75a497a2d8adc160b32b21456eef351 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 4 Nov 2021 12:05:55 +0100 Subject: [PATCH 5/7] tools/ormolu.sh: use utf-8 for IO Otherwise, ormolu fails with some locales on non-ASCII characters: ``` ormolu: libs/dns-util/src/Wire/Network/DNS/SRV.hs: hGetContents: invalid argument (invalid byte sequence) ``` See https://github.com/tweag/ormolu/issues/38 and https://gitlab.haskell.org/ghc/ghc/-/issues/17755 for details. --- tools/ormolu.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/ormolu.sh b/tools/ormolu.sh index 924cd93a4b9..e34fddf3015 100755 --- a/tools/ormolu.sh +++ b/tools/ormolu.sh @@ -67,6 +67,11 @@ if [ -t 1 ]; then : ${ORMOLU_CONDENSE_OUTPUT:=1} fi +# https://github.com/tweag/ormolu/issues/38 +# https://gitlab.haskell.org/ghc/ghc/-/issues/17755 +export LANG=C.UTF-8 +export LC_ALL=C.UTF-8 + for hsfile in $(git ls-files | grep '\.hsc\?$'); do FAILED=0 From e42d91a5d0a200a1cde8dd0a6f7b94f95969feed Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 4 Nov 2021 15:38:08 +0100 Subject: [PATCH 6/7] changelog: add changelog --- changelog.d/5-internal/ormolu-direnv | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5-internal/ormolu-direnv diff --git a/changelog.d/5-internal/ormolu-direnv b/changelog.d/5-internal/ormolu-direnv new file mode 100644 index 00000000000..ae0dddfd756 --- /dev/null +++ b/changelog.d/5-internal/ormolu-direnv @@ -0,0 +1 @@ +Add ormolu to the direnv, add a GH Action to ensure formatting From 682a1302422ad4fe52e7fee50f480bef19cd3869 Mon Sep 17 00:00:00 2001 From: jschaul Date: Thu, 4 Nov 2021 17:36:23 +0100 Subject: [PATCH 7/7] Hi CI