From ad6ecb0b6911aae6e463f7d4e12e160c85d43bb1 Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Sun, 15 Dec 2024 16:34:16 +0000 Subject: [PATCH] Nix to the CI rescue --- .github/workflows/haskell-ci.yaml | 74 +++++++++++++++---------------- flake.lock | 61 +++++++++++++++++++++++++ flake.nix | 40 +++++++++++++++++ 3 files changed, 137 insertions(+), 38 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/haskell-ci.yaml b/.github/workflows/haskell-ci.yaml index 1a4f108..296df71 100644 --- a/.github/workflows/haskell-ci.yaml +++ b/.github/workflows/haskell-ci.yaml @@ -87,61 +87,59 @@ jobs: cabal test --project-file "$project_file" --constraint "atomic-counter +no-cmm" --test-show-details=direct all cabal bench --project-file "$project_file" --constraint "atomic-counter +no-cmm" --benchmark-options='--stdev 100 --timeout 100' all - i386: - runs-on: ubuntu-latest - container: - image: i386/ubuntu:bionic + nix-build: + name: Nix build ${{ matrix.arch }} + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - os: [ubuntu-latest] - ghc: - - "8.6" - - "8.8" - - "8.10" - - "9.0" - - "9.2" - - "9.4" - - "9.6" - + arch: + - "x86_64-linux" + - "i686-linux" steps: - - name: Install - run: | - apt-get update -y - apt-get install -y autoconf build-essential zlib1g-dev libgmp-dev curl libncurses5 libtinfo5 libncurses5-dev libtinfo-dev + - uses: actions/checkout@v4 - curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 BOOTSTRAP_HASKELL_INSTALL_NO_STACK=1 sh + - uses: cachix/install-nix-action@v16 - source ~/.ghcup/env - ghcup install ghc --set ${{ matrix.ghc }} - ghcup install cabal latest + - name: GHC version + run: nix develop '.#devShells.${{ matrix.arch }}.ci-shell' --command ghc --version - # This version must stay old enough to remain compatible with the container image. - - uses: actions/checkout@v1 + - name: Build atomic-counter with nix + run: nix build -L + + - name: Build atomic-counter nix shell + run: nix build -L '.#devShells.${{ matrix.arch }}.ci-shell' - - name: Cabal version - run: | - source ~/.ghcup/env - cabal --version - name: Unpack run: | - source ~/.ghcup/env - cabal update + proj_dir="$(pwd)" + + nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \ + cabal update + + nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \ + cabal sdist --ignore-project --output-directory .. - cabal sdist --ignore-project --output-directory .. cd .. - cabal get atomic-counter-*.tar.gz -d default + + nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \ + cabal get atomic-counter-*.tar.gz -d default - name: Build & Test default run: | - source ~/.ghcup/env - cabal update - project_file="$(pwd)/cabal.project.ci" + proj_dir="$(pwd)" + + project_file="${proj_dir}/cabal.project.ci" cd ../default/atomic-counter-*/ - cabal build --project-file "$project_file" all - cabal test --project-file "$project_file" --test-show-details=direct all - cabal bench --project-file "$project_file" --benchmark-options='--stdev 100 --timeout 100' all + nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \ + cabal build --project-file "$project_file" all + + nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \ + cabal test --project-file "$project_file" --test-show-details=direct all + + nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \ + cabal bench --project-file "$project_file" --benchmark-options='--stdev 100 --timeout 100' all diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a4c1513 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1734278093, + "narHash": "sha256-yDhdv9ajfxS4RkXjaU8iX4wrEBuUxEdJZxun/xAX1aI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "08a9d8d6ed7ac1a3258798525e5c750dc6433d4f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..cbe7bd1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "atomic-counter"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-24.11"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + let + overlay = final: prev: { + haskell = prev.haskell // { + packageOverrides = hfinal: hprev: + prev.haskell.packageOverrides hfinal hprev // { + atomic-counter = hfinal.callCabal2nix "atomic-counter" ./. { }; + }; + }; + atomic-counter = final.haskell.lib.compose.justStaticExecutables final.haskellPackages.atomic-counter; + }; + perSystem = system: + let + pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; }; + hspkgs = pkgs.haskellPackages; + in + { + devShells = rec { + ci-shell = hspkgs.shellFor { + withHoogle = false; + packages = p: [ p.atomic-counter ]; + buildInputs = [ + hspkgs.cabal-install + ]; + }; + }; + packages = rec { + default = atomic-counter; + atomic-counter = pkgs.atomic-counter; + }; + }; + in + { inherit overlay; } // flake-utils.lib.eachSystem ["x86_64-linux" "i686-linux"] perSystem; +}