Skip to content

Commit

Permalink
Adds support for ghc982 and updates documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyfold committed Dec 17, 2024
1 parent 0d18ee2 commit dff72e2
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 56 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ jobs:
- 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
# FIXME figure out how to add this to: nix flake check
nix develop -c cabal test
nix develop .#ghc982-web-view -c cabal test
cd example
nix develop ..#example -c cabal build
nix develop ..#ghc966-example -c cabal build
nix develop ..#ghc982-example -c cabal build
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,30 @@ el (width 100 . media (MinWidth 800) (width 400))
"Big if window > 800"
```

### Try Example Project with Nix

If you want to get a feel for web-view without cloning the project run `nix run github:seanhess/web-view` to run the example webserver locally

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

### Nix

With nix installed, you can use `nix develop` to get a shell with all dependencies installed.
Prepend targets with ghc982 or ghc966 to use GHC 9.8.2 or GHC 9.6.6

- `nix run` starts the example project with GHC 9.8.2
- `nix develop` to get a shell with all dependencies installed for GHC 9.8.2.
- `nix develop .#ghc966-web-view` for GHC 9.6.6

You can also try out the example project with:
You can also get a development shell for the example project with:

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

You can import this flake's overlay to add `web-view` to all package sets and override ghc966 with the packages to satisfy `web-view`'s dependencies.
You can import this flake's overlay to add `web-view` to all package sets and override ghc966 and ghc982 with the packages to satisfy `web-view`'s dependencies.

```nix
{
Expand Down
140 changes: 100 additions & 40 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
web-view = hfinal.callCabal2nix "web-view" web-view-src { };
});
packages = prev.haskell.packages // {
ghc982 = prev.haskell.packages.ghc982.override (old: {
overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) (
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" { };
}
);
});
ghc966 = prev.haskell.packages.ghc966.override (old: {
overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) (
hfinal: hprev: {
Expand All @@ -67,38 +79,37 @@
let
pkgs = import inputs.nixpkgs {
inherit system;
# overlays = [ self.overlays.default ];
};

pkgsOverlayed = import inputs.nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};

# Define GHC versions list
ghcVersions = [ "966" "982" ];

# Create an attrset of GHC packages
ghcPkgs = builtins.listToAttrs (map
(version: {
name = "ghc${version}";
value = pkgsOverlayed.haskell.packages."ghc${version}";
})
ghcVersions);

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

myHaskellPackages = (import inputs.nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
}).haskell.packages.ghc966.override (old: {
overrides = pkgs.lib.composeExtensions (old.overrides or (_: _: { })) (
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 = {
shellCommon = version: {
inherit (self.checks.${system}.pre-commit-check) shellHook;
# don't use the modified package set to build dev tools
buildInputs = with pkgs.haskellPackages; [
buildInputs = with pkgs.haskell.packages."ghc${version}"; [
cabal-install
haskell-language-server
fast-tags
Expand All @@ -111,15 +122,21 @@
CABAL_CONFIG = "/dev/null";
};

# Create examples for each GHC version
examples = builtins.listToAttrs (map
(version: {
name = "ghc${version}-example";
value = ghcPkgs."ghc${version}".callCabal2nix "example" example-src { };
})
ghcVersions);

in
{
checks = {
pre-commit-check = git-hooks.lib.${system}.run {
src = web-view-src;
hooks = {
# hlint.enable = true;
# hpack.enable = true;
# fourmolu.enable = true;
hpack.enable = true;
nixpkgs-fmt.enable = true;
flake-checker = {
enable = true;
Expand All @@ -128,27 +145,70 @@
check-merge-conflicts.enable = true;
};
};
};
} // builtins.listToAttrs (
# Generate checks
builtins.concatMap
(version: [
{
name = "ghc${version}-check";
value = self.packages.${system}."ghc${version}-web-view";
}
{
name = "ghc${version}-check-example";
value = examples."ghc${version}-example";
}
])
ghcVersions
);

apps = {
default = self.apps.${system}.ghc966-example;
} // builtins.listToAttrs (
# Generate apps
map
(version: {
name = "ghc${version}-example";
value = {
type = "app";
program = "${pkgs.haskell.lib.justStaticExecutables examples."ghc${version}-example"}/bin/example";
};
})
ghcVersions
);

packages = {
default = self.packages.${system}.web-view;
web-view = myHaskellPackages.web-view;
};
default = self.packages.${system}.ghc982-web-view;
} // builtins.listToAttrs (
# Generate packages
map
(version: {
name = "ghc${version}-web-view";
value = ghcPkgs."ghc${version}".web-view;
})
ghcVersions
);

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 { })
];
}
);
};
default = self.devShells.${system}.ghc982-web-view;
} // builtins.listToAttrs (
# Generate devShells
builtins.concatMap
(version: [
{
name = "ghc${version}-web-view";
value = ghcPkgs."ghc${version}".shellFor (
shellCommon version // { packages = p: [ p.web-view ]; }
);
}
{
name = "ghc${version}-example";
value = ghcPkgs."ghc${version}".shellFor (
shellCommon version // { packages = _: [ examples."ghc${version}-example" ]; }
);
}
])
ghcVersions
);
}
);
}
4 changes: 4 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ ghc-options:
- -Wall
- -fdefer-typed-holes

tested-with:
- GHC == 9.8.2
- GHC == 9.6.6

default-extensions:
- OverloadedStrings
- OverloadedRecordDot
Expand Down
7 changes: 6 additions & 1 deletion web-view.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2

-- This file has been generated from package.yaml by hpack version 0.37.0.
-- This file has been generated from package.yaml by hpack version 0.36.1.
--
-- see: https://github.com/sol/hpack

Expand All @@ -16,6 +16,9 @@ maintainer: [email protected]
license: BSD-3-Clause
license-file: LICENSE
build-type: Simple
tested-with:
GHC == 9.8.2
, GHC == 9.6.6
extra-source-files:
embed/preflight.css
test/resources/basic.txt
Expand Down Expand Up @@ -86,6 +89,8 @@ test-suite test
DuplicateRecordFields
NoFieldSelectors
ghc-options: -Wall -fdefer-typed-holes -threaded -rtsopts -with-rtsopts=-N -F -pgmF=skeletest-preprocessor
build-tool-depends:
skeletest:skeletest-preprocessor
build-depends:
Diff >=0.5 && <1.0
, base >=4.16 && <5
Expand Down

0 comments on commit dff72e2

Please sign in to comment.