From 49cba35d3851cbb146eb6161ad7342754de4208b Mon Sep 17 00:00:00 2001 From: Aleksandr Pakulev Date: Tue, 16 Feb 2021 03:49:12 +0500 Subject: [PATCH] [EDNA-11] Add CI checks for Haskell code --- .buildkite/pipeline.yml | 14 ++- backend/default.nix | 44 ++++++++++ default.nix | 4 + flake.lock | 185 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 51 +++++++++++ pipeline.nix | 1 + shell.nix | 4 + 7 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 backend/default.nix create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pipeline.nix create mode 100644 shell.nix diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 2f6c4218..3817b520 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,4 +1,16 @@ steps: - label: check trailing whitespace commands: - - .buildkite/check-trailing-whitespace.sh + - .buildkite/check-trailing-whitespace.sh + - label: backend build + commands: + - nix-build -A packages.x86_64-linux.backend + - label: backend lib + commands: + - nix-build -A packages.x86_64-linux.backend-lib + - label: backend test + commands: + - nix-build -A checks.x86_64-linux.backend-test + - label: backend hlint + commands: + - nix-build -A checks.x86_64-linux.backend-hlint diff --git a/backend/default.nix b/backend/default.nix new file mode 100644 index 00000000..9beac861 --- /dev/null +++ b/backend/default.nix @@ -0,0 +1,44 @@ +{ haskell-nix, runCommand, lib }: +let + ignoreFilter = path: type: + let + inherit (lib) removePrefix hasPrefix hasSuffix; + relPath = removePrefix (toString ./. + "/") (toString path); + baseName = baseNameOf relPath; + in + !( + baseName == ".gitignore" || + hasPrefix "resources" relPath || + hasSuffix ".md" baseName || + hasSuffix ".nix" baseName + ); + + # Set a constant name for the src closure + source = let + root = ./.; + in builtins.path { + name = "edna-backend-src"; + path = root; + filter = name: type: + (ignoreFilter name type && lib.cleanSourceFilter name type); + }; + + project = haskell-nix.stackProject { + src = haskell-nix.haskellLib.cleanGit { + src = haskell-nix.cleanSourceHaskell { src = ./.; }; + }; + modules = [ + { + doHaddock = true; + packages.edna = { + doHaddock = true; + package.ghcOptions = "-Werror"; + }; + } + ]; + }; + library = project.edna.components.library; + server = project.edna.components.exes.edna-server; + test = project.edna.checks.edna-test; + hlint = runCommand "hlint.html" {} '' ${hlint}/bin/hlint ${source} --no-exit-code --report=$out -j ''; +in { inherit server test library hlint; } diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..1ef8a22a --- /dev/null +++ b/default.nix @@ -0,0 +1,4 @@ +(import (fetchTarball + "https://github.com/edolstra/flake-compat/archive/master.tar.gz") { + src = builtins.fetchGit ./.; + }).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..c3caa683 --- /dev/null +++ b/flake.lock @@ -0,0 +1,185 @@ +{ + "nodes": { + "common-infra": { + "inputs": { + "deploy": "deploy", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1612203367, + "narHash": "sha256-z4knCUz+FJxqEgbT+EEFuzpAFWHmWBfAfTr3HuHMKE0=", + "owner": "serokell", + "repo": "common-infra", + "rev": "c5b609969578f8f5ca56c7d439eb010fcbe17157", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "common-infra", + "type": "github" + } + }, + "deploy": { + "inputs": { + "flake-compat": "flake-compat", + "naersk": "naersk", + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1608488342, + "narHash": "sha256-JhEoKKmETJsdgS+kjT1rACnlM50q/JdVNyAfIbbVQcc=", + "owner": "serokell", + "repo": "deploy-rs", + "rev": "91e934fd9e1e06044f75a3e3ad998813c2a90fb5", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "deploy-rs", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1600853454, + "narHash": "sha256-EgsgbcJNZ9AQLVhjhfiegGjLbO+StBY9hfKsCwc8Hw8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "94cf59784c73ecec461eaa291918eff0bfb538ac", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "hackage": { + "flake": false, + "locked": { + "lastModified": 1613437861, + "narHash": "sha256-fhUWF2dKVoPUyfuj7nj6nOcmu1EIVJ2BEEOyp2YdF3U=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "03b3577a069b61a5fd6f9319e09dd67ad3d94aee", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "hackage.nix", + "type": "github" + } + }, + "haskell-nix": { + "locked": { + "lastModified": 1613524507, + "narHash": "sha256-vIjgOb6PKGtLpSDbKV6J2dI4nR8SOcST1I1B+qOhsR8=", + "owner": "input-output-hk", + "repo": "haskell.nix", + "rev": "ba87ffb84bc4158ada14908bddee9df2c81ac31b", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "haskell.nix", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1602173141, + "narHash": "sha256-m6wU6lP0wf2OMw3KtJqn27ITtg29+ftciGHicLiVSGE=", + "owner": "nmattia", + "repo": "naersk", + "rev": "22b96210b2433228d42bce460f3befbdcfde7520", + "type": "github" + }, + "original": { + "owner": "nmattia", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1608557166, + "narHash": "sha256-N9n82yV/9CCAuJtKPg3EcHR1wZCTGciwrK1TaWYFDME=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2a058487cb7a50e7650f1657ee0151a19c59ec3b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1613226215, + "narHash": "sha256-3rA5cGIrBHD6yeKhNhsF7/t461ww25oJY8KyBb0IhjU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ff96a0fa5635770390b184ae74debea75c3fd534", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "common-infra": "common-infra", + "hackage": "hackage", + "haskell-nix": "haskell-nix", + "nixpkgs": "nixpkgs_2", + "stackage": "stackage" + } + }, + "stackage": { + "flake": false, + "locked": { + "lastModified": 1613437366, + "narHash": "sha256-EIMjXbwx41TNR/dWEWJrKbO61h17tzLDNwTheTXrHJU=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "aba6cc7066d2f5d1179284d708e11751f1c1be78", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "stackage.nix", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1601282935, + "narHash": "sha256-WQAFV6sGGQxrRs3a+/Yj9xUYvhTpukQJIcMbIi7LCJ4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "588973065fce51f4763287f0fda87a174d78bf48", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..9165b597 --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + inputs = { + nixpkgs.url = "github:serokell/nixpkgs"; + haskell-nix.url = "github:input-output-hk/haskell.nix"; + hackage = { + url = "github:input-output-hk/hackage.nix"; + flake = false; + }; + stackage = { + url = "github:input-output-hk/stackage.nix"; + flake = false; + }; + common-infra.url = "github:serokell/common-infra"; + }; + + outputs = { self, nixpkgs, haskell-nix, hackage, stackage, common-infra }: + let + packagesFor = system: rec { + pkgs = nixpkgs.legacyPackages.${system}.extend + (nixpkgs.lib.foldl nixpkgs.lib.composeExtensions (_: _: { }) [ + haskell-nix.overlay + ]); + backend = pkgs.callPackage ./backend { }; + }; + in { + packages = builtins.mapAttrs (system: _: + with packagesFor system; { + backend-lib = backend.library; + backend = backend.server // { + meta.modulePath = [ "services" "edna" "backend" ]; + }; + }) nixpkgs.legacyPackages; + + ciSystems = [ "x86_64-linux" ]; + + checks = builtins.mapAttrs (system: _: + with packagesFor system; { + backend-test = backend.test; + backend-hlint = backend.hlint; + }) nixpkgs.legacyPackages; + + pipelineFile = common-infra.mkPipelineFile self; + + devShell = builtins.mapAttrs (system: packages: + let pkgs = nixpkgs.legacyPackages.${system}; + in pkgs.mkShell { + inputsFrom = [ packages.backend-lib ]; + buildInputs = with pkgs.haskellPackages; [ cabal-install hpack ]; + }) self.packages; + }; +} diff --git a/pipeline.nix b/pipeline.nix new file mode 100644 index 00000000..f8a31536 --- /dev/null +++ b/pipeline.nix @@ -0,0 +1 @@ +(import ./.).pipelineFile diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..9a25fabd --- /dev/null +++ b/shell.nix @@ -0,0 +1,4 @@ +(import (fetchTarball + "https://github.com/edolstra/flake-compat/archive/master.tar.gz") { + src = builtins.fetchGit ./.; + }).shellNix