Skip to content

Commit

Permalink
add nix flake, GitHub Actions workflow, fix tests
Browse files Browse the repository at this point in the history
* Add Nix flake configuration for building and development
  - Configure build inputs and overlays
  - Set up development shells for main package and example

* Add GitHub Actions workflow for CI
  - Build packages and devShells on Ubuntu and macOS
  - Use DeterminateSystems' Nix installer and cache actions
  - Adds cabal.project file for `cabal test`

* Update documentation
  - Add Local Development section with Nix instructions
  - Document dev shell and example project setup
  - Include example usage of flake overlay

* cabal changes file
  - Add missing test resource files to extra-source-files
  - removed build-tool-depend since cabal does not see skeletest-preprocessor
  provided by nix

* Fix CSS rendering for golden tests
  - There were two extra spaces before each CSS Node and an extra newline
  before and after the CSS attributes.

notes:
  - the hlint and fourmolu pre-commit checks are dissabled, since
  they need to be applied across the codebase
  - the hpack pre-commit check is dissabled because the version
  is 0.36.1 instead of 0.37.0
  • Loading branch information
Skyfold committed Dec 13, 2024
1 parent d3f3e81 commit d947994
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 5 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Haskell CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check packages
run: |
nix flake check
- name: Build packages
run: |
# Build all packages for the current system
nix build .#
nix build .#web-view
- name: Build devShells
run: |
# Build all devShells for the current system
nix develop .#web-view -c cabal test
cd example
nix develop ..#example -c cabal build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist
tags
docs/old.md
build

.direnv
result
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,48 @@ el (width 100 . media (MinWidth 800) (width 400))
"Big if window > 800"
```

Local Development
-----------------

### Nix

With nix installed, you can use `nix develop` to get a shell with all dependencies installed.

You can also try out the example project with:

```
cd example
nix develop ../#example
cabal run
```

You can import this flake's overlay to add `web-view` to all package sets.

```nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
web-view.url = "github:seanhess/web-view"; # or "path:/path/to/cloned/web-view";
};
outputs = { self, nixpkgs, web-view }: {
# Apply the overlay to your packages
packages.x86_64-linux = import nixpkgs {
system = "x86_64-linux";
overlays = [ web-view.overlays.default ];
};
haskellPackagesOverride = pkgs.haskellPackages.override (old: {
overrides = pkgs.lib.composeExtensions (old.overrides or (_: _: {})) (hfinal: hprev: {
...
});
});
haskellPackagesExtend = pkgs.haskellPackages.extend (hfinal: hprev: {
...
});
};
}
```


Learn More
----------
Expand Down
3 changes: 3 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests: True
packages:
.
155 changes: 155 additions & 0 deletions flake.lock

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

129 changes: 129 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
description = "web-view";

inputs = {
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nix-filter.url = "github:numtide/nix-filter/main";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
inputs@{ self
, flake-utils
, nix-filter
, git-hooks
, ...
}:
let
web-view-src = nix-filter.lib {
root = ./.;
include = [
(nix-filter.lib.inDirectory "src")
(nix-filter.lib.inDirectory "embed")
(nix-filter.lib.inDirectory "test")
./README.md
./CHANGELOG.md
./LICENSE
./web-view.cabal
./cabal.project
./package.yaml
./fourmolu.yaml
];
};

overlay = final: prev: {
haskell = prev.haskell // {
packageOverrides = prev.lib.composeExtensions prev.haskell.packageOverrides (hfinal: hprev: {
web-view = hfinal.callCabal2nix "web-view" web-view-src { };
});
};
};
in
{
overlays.default = overlay;
}
// flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ overlay ];
};

example-src = nix-filter.lib {
root = ./example;
include = [
(nix-filter.lib.inDirectory "app")
./example/example.cabal
./example/cabal.project
];
};

myHaskellPackages = pkgs.haskellPackages.extend (
hfinal: hprev: {
attoparsec-aeson = hfinal.callHackage "attoparsec-aeson" "2.2.0.0" { };
skeletest = hprev.skeletest.overrideAttrs (old: {
meta = old.meta // { broken = false; };
});
Diff = hfinal.callHackage "Diff" "0.5" { };
aeson = hfinal.callHackage "aeson" "2.2.2.0" { };
}
);

shellCommon = {
inherit (self.checks.${system}.pre-commit-check) shellHook;
# don't use the modified package set to build dev tools
buildInputs = with pkgs.haskellPackages; [
cabal-install
haskell-language-server
fast-tags
ghcid
fourmolu
pkgs.hpack
];
withHoogle = true;
doBenchmark = true;
CABAL_CONFIG = "/dev/null";
};
in
{
checks = {
hyperbole-check = self.packages.${system}.web-view;
pre-commit-check = git-hooks.lib.${system}.run {
src = web-view-src;
hooks = {
# hlint.enable = true;
# hpack.enable = true;
# fourmolu.enable = true;
nixpkgs-fmt.enable = true;
};
};
};

packages = {
default = self.packages.${system}.web-view;
web-view = myHaskellPackages.web-view;
};
inherit pkgs;

devShells = {
default = self.devShells.${system}.web-view;
web-view = myHaskellPackages.shellFor (
shellCommon // { packages = p: [ p.web-view ]; }
);
example = myHaskellPackages.shellFor (
shellCommon
// {
packages = _: [
(myHaskellPackages.callCabal2nix "example" example-src { })
];
}
);
};
}
);
}
Loading

0 comments on commit d947994

Please sign in to comment.