Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Nix flake #620

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 64 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,52 @@ There is also legacy Travis-CI configuration generator, which is unmaintained.
or [`ghcup`](https://www.haskell.org/ghcup/) to install GHC
and `cabal-install`.

GHC-7.0.1 — GHC-9.2.1 are supported.
GHC-7.0.1 — GHC-9.4.2 are supported.

### Quick-start instructions

* Step 1: Clone and install this project in/from any directory
haskell-ci can be installed either with Cabal or with Nix, depending on your
preference:

```bash
$ git clone https://github.com/haskell-CI/haskell-ci.git
$ cd haskell-ci
$ cabal new-install haskell-ci:exe:haskell-ci
```
#### Installation: Cabal

or
Either install from a Git clone:

```bash
cabal new-install haskell-ci
```
```bash
$ git clone https://github.com/haskell-CI/haskell-ci.git
$ cd haskell-ci
$ cabal new-install haskell-ci:exe:haskell-ci
```

or from Hackage:

```bash
cabal new-install haskell-ci
```

#### Installation: Nix

Either get haskell-ci from nixpkgs (may be older):

```
$ nix run nixpkgs#haskell-ci -- --help
```

or use the flake to build it from source:

```
$ nix run github:haskell-ci/haskell-ci -- --help
```

* Step 2: Change directories to your project:
#### Setup on your project

* Step 1: Change directories to your project:

```bash
$ cd path/to/your-project
```

* Step 3: Edit your project's `*.cabal` file to add a `Tested-With` line, such as this one:
* Step 2: Edit your project's `*.cabal` file to add a `Tested-With` line, such as this one:

```bash
$ cat your-project.cabal
Expand All @@ -43,7 +64,7 @@ GHC-7.0.1 — GHC-9.2.1 are supported.

Add as many or as few GHC versions to test as you want.

* Step 4: Generate a workflow file for your project:
* Step 3: Generate a workflow file for your project:

```bash
$ # You run the following command from your project's directory, even
Expand All @@ -61,7 +82,7 @@ GHC-7.0.1 — GHC-9.2.1 are supported.
`*.cabal` files and generates a configuration that tests each compiler
version you listed in parallel.

* Step 5: Create a branch with your new CI configuration file and push your branch:
* Step 4: Create a branch with your new CI configuration file and push your branch:

```bash
$ git checkout master # Check out `master`
Expand All @@ -72,7 +93,7 @@ GHC-7.0.1 — GHC-9.2.1 are supported.
$ git push -u origin new-ci # Push your branch upstream
```

* Step 6: Fix the build
* Step 5: Fix the build

If you're lucky, your repository will build for every compiler version
you listed. If that's the case, then just merge your changes into `master`:
Expand Down Expand Up @@ -105,3 +126,30 @@ Real-world Examples
- [aeson](https://github.com/haskell/aeson)
- [lens](https://github.com/ekmett/lens)
- [unordered-containers](https://github.com/haskell-unordered-containers/unordered-containers)

## Contributing

There is a Nix flake to easily get the exact environment required, which you
can use like so, once you've [installed the Nix package manager][nix-install]:

```
$ nix develop
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how I develop haskell-ci and I won't be able to help people.

```

This will give you an environment with an appropriate compiler and cabal to
work on haskell-ci.

### Care and feeding of the Nix flake

There's a lockfile at `flake.lock` containing all the inputs including the
nixpkgs set.

You can update the nixpkgs version like so:

```
$ nix flake lock --update-input nixpkgs
```

Then test building the flake to see if anything went awry.

[nix-install]: https://nixos.org/download.html#download-nix
43 changes: 43 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
description = "Scripts for setting up CI for Haskell";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

nixConfig.allow-import-from-derivation = true; # cabal2nix uses IFD

outputs = { self, nixpkgs, flake-utils }:
let
ghcVer = "ghc902";
makeHaskellOverlay = overlay: final: prev: {
haskell = prev.haskell // {
packages = prev.haskell.packages // {
${ghcVer} = prev.haskell.packages."${ghcVer}".override (oldArgs: {
overrides =
prev.lib.composeExtensions (oldArgs.overrides or (_: _: { }))
(overlay prev);
});
};
};
};

out = system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};

in
{
packages = rec {
default = haskell-ci;
haskell-ci = pkgs.haskell.lib.justStaticExecutables pkgs.haskell.packages.${ghcVer}.haskell-ci;
};

checks = {
inherit (self.packages.${system}) haskell-ci;
};

# for debugging
inherit pkgs;

devShells.default =
let haskellPackages = pkgs.haskell.packages.${ghcVer};
in
haskellPackages.shellFor {
packages = p: [ self.packages.${system}.haskell-ci ];
withHoogle = true;
buildInputs = with haskellPackages; [
# just commented out because they take extra time to build
# given the overrides below:
#
# haskell-language-server
# fourmolu

# broken on this nixpkgs version
# ghcid
cabal-install
] ++ (with pkgs; [
sqlite
]);
# Change the prompt to show that you are in a devShell
# shellHook = "export PS1='\\e[1;34mdev > \\e[0m'";
};
};
in
flake-utils.lib.eachDefaultSystem out // {
# this stuff is *not* per-system
overlays = {
default = makeHaskellOverlay (prev: hfinal: hprev:
let
hlib = prev.haskell.lib;
# filter paths so that readme changes don't force rebuilds
filteredSource = prev.lib.sourceByRegex ./. [
"^.*\\.hs$"
"^.*\\.cabal$"

"LICENSE"
"CHANGELOG\\.md"

"^src.*$"
"^cli.*$"
"^test.*$"
"^fixtures.*$"
];
in
{
haskell-ci = hprev.callCabal2nix "haskell-ci" filteredSource {
# this has to be overridden like this because it is looking
# villainy directly in the face to override Cabal
Cabal-syntax = hfinal.Cabal-syntax_3_8_1_0;
};

# these are just old in the default nixpkgs configuration
base-compat = hfinal.base-compat_0_12_2;
base-compat-batteries = hfinal.base-compat-batteries_0_12_2;
optparse-applicative = hfinal.optparse-applicative_0_17_0_0;
});
};
};
}