From 0b0c6d65ca583ee6463679065acf6641a08eab2b Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Fri, 20 Nov 2020 23:17:29 +0800 Subject: [PATCH] Simplify Nix expressions This uses `developPackage` from `nixpkgs` to generate the derivation Also add CI for nix build --- .github/workflows/ci.yaml | 8 ++++++ README.md | 16 +++++++++++- default.nix | 52 ++++++++++++--------------------------- pkgs.nix | 5 ---- release.nix | 5 ---- shell.nix | 13 ---------- 6 files changed, 39 insertions(+), 60 deletions(-) delete mode 100644 pkgs.nix delete mode 100644 release.nix delete mode 100644 shell.nix diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e7c3add..466e206 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -56,3 +56,11 @@ jobs: path: dist-newstyle/sdist/brittany-*.tar.gz name: brittany-${{ github.sha }}.tar.gz - run: cabal check + + + nix: + runs-on: ubuntu-latest + steps: + - uses: cachix/install-nix-action@v12 + - uses: actions/checkout@v2 + - run: nix-build diff --git a/README.md b/README.md index 7828fd2..465e215 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ log the size of the input, but _not_ the full input/output of requests.) - via `nix`: ~~~.sh - nix build -f release.nix # or 'nix-build -f release.nix' + nix build nix-env -i ./result ~~~ @@ -102,6 +102,20 @@ log the size of the input, but _not_ the full input/output of requests.) aura -A brittany ~~~~ +# Development tips + +## Run a hoogle server + +To host a local Hoogle server with all of Brittany's dependencies run: + +```sh +echo brittany.cabal | + $(nix-build '' --no-link -A entr)/bin/entr -r -- \ + sh -c "nix-shell --run 'hoogle server --local'" +``` + +This will watch `brittany.cabal` for changes and restart the server when new dependencies are added there. + # Editor Integration #### Sublime text diff --git a/default.nix b/default.nix index 296987a..ed3dcca 100644 --- a/default.nix +++ b/default.nix @@ -1,38 +1,18 @@ -{ mkDerivation, aeson, base, butcher, bytestring, cmdargs -, containers, czipwith, data-tree-print, deepseq, directory, extra -, filepath, ghc, ghc-boot-th, ghc-exactprint, ghc-paths, hspec -, monad-memo, mtl, multistate, neat-interpolation, parsec, pretty -, random, safe, semigroups, stdenv, strict, syb, text, transformers -, uniplate, unsafe, yaml +{ nixpkgsSrc ? builtins.fetchTarball { + url = + "https://github.com/nixos/nixpkgs/archive/069f183f16c3ea5d4b6e7625433b92eba77534f7.tar.gz"; # nixos-unstable + sha256 = "1by9rqvr2k6iz2yipf89yaj254yicpwq384ijgyy8p71lfxbbww2"; +}, pkgs ? import nixpkgsSrc { }, compiler ? null, forShell ? pkgs.lib.inNixShell }: -mkDerivation { - pname = "brittany"; - version = "0.11.0.0"; - src = ./.; - isLibrary = true; - isExecutable = true; - libraryHaskellDepends = [ - aeson base butcher bytestring cmdargs containers czipwith - data-tree-print deepseq directory extra filepath ghc ghc-boot-th - ghc-exactprint ghc-paths monad-memo mtl multistate - neat-interpolation pretty random safe semigroups strict syb text - transformers uniplate unsafe yaml - ]; - executableHaskellDepends = [ - aeson base butcher bytestring cmdargs containers czipwith - data-tree-print deepseq directory extra filepath ghc ghc-boot-th - ghc-exactprint ghc-paths monad-memo mtl multistate - neat-interpolation pretty safe semigroups strict syb text - transformers uniplate unsafe yaml - ]; - testHaskellDepends = [ - aeson base butcher bytestring cmdargs containers czipwith - data-tree-print deepseq directory extra filepath ghc ghc-boot-th - ghc-exactprint ghc-paths hspec monad-memo mtl multistate - neat-interpolation parsec pretty safe semigroups strict syb text - transformers uniplate unsafe yaml - ]; - homepage = "https://github.com/lspitzner/brittany/"; - description = "Haskell source code formatter"; - license = stdenv.lib.licenses.agpl3; + +let + haskellPackages = if compiler == null then + pkgs.haskellPackages + else + pkgs.haskell.packages.${compiler}; + +in haskellPackages.developPackage { + name = "brittany"; + root = pkgs.nix-gitignore.gitignoreSource [ ] ./.; + returnShellEnv = forShell; } diff --git a/pkgs.nix b/pkgs.nix deleted file mode 100644 index 76cbbb8..0000000 --- a/pkgs.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ - url = "https://github.com/nixos/nixpkgs.git"; - ref = "release-18.09"; - rev = "b9fa31cea0e119ecf1867af4944ddc2f7633aacd"; -} diff --git a/release.nix b/release.nix deleted file mode 100644 index b37b2ce..0000000 --- a/release.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ pkgs ? import (fetchGit (import ./pkgs.nix)) {} -, compiler ? "ghc822" -}: - -pkgs.haskell.packages.${compiler}.callPackage ./shell.nix {} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 5c0ccfe..0000000 --- a/shell.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ pkgs ? import (fetchGit (import ./pkgs.nix)) {} -, compiler ? "ghc822" -}: - -pkgs.haskell.packages.${compiler}.developPackage { - root = ./.; - name = "brittany"; - overrides = with pkgs.haskell.lib; self: super: { - }; - source-overrides = { - ghc-exactprint = "0.5.8.0"; - }; -} -- 2.30.2