Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adds cachix to CI and flake (like hyberbole) #13

Merged
merged 10 commits into from
Jan 30, 2025
33 changes: 16 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@ name: Haskell CI

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

permissions:
contents: read
packages: write # for cachix

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
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
- uses: actions/checkout@v4

- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: cachix/cachix-action@v14
with:
name: hyperbole
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- name: Check packages
run: |
nix flake check
# Build all devShells for the current system
# FIXME figure out how to add this to: nix flake check
# nix develop -c cabal test --dry-run
# nix develop .#ghc982-web-view -c cabal test --dry-run
# cd example
# nix develop ..#ghc966-example -c cabal test --dry-run
# nix develop ..#ghc982-example -c cabal test --dry-run

73 changes: 53 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,10 @@ el (width 100 . media (MinWidth 800) (width 400))

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

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 get a development shell for the example project with:

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

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.
You can import this flake's overlay to add `web-view` to `overriddenHaskellPackages` and which provides a ghc966 and ghc982 package set that satisfy `web-view`'s dependencies.

```nix
{
Expand All @@ -112,7 +96,7 @@ You can import this flake's overlay to add `web-view` to all package sets and ov
inherit system;
overlays = [ web-view.overlays.default ];
};
haskellPackagesOverride = pkgs.haskell.packages.ghc966.override (old: {
haskellPackagesOverride = pkgs.overriddenHaskellPackages.ghc966.override (old: {
overrides = pkgs.lib.composeExtensions (old.overrides or (_: _: { })) (hfinal: hprev: {
# your overrides here
});
Expand All @@ -127,6 +111,55 @@ You can import this flake's overlay to add `web-view` to all package sets and ov
}
```

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

### Recommended ghcid command

If you want to work on both the web-view library and example code, this `ghcid` command will run and reload the examples server as you change any non-testing code.

```
ghcid --command="cabal repl exe:example lib:web-view" --run=Main.main --warnings --reload=./embed/preflight.css
```

If you want to work on the test suite, this will run the tests each time any library code is changed.

```
ghcid --command="cabal repl test lib:web-view" --run=Main.main --warnings --reload=./embed/preflight.css
```

### Nix

- `nix flake check` will build the library, example executable and devShell with ghc-9.8.2 and ghc-9.6.6
- This is what the CI on GitHub runs
- `nix run` or `nix run .#ghc982-example` to start the example project with GHC 9.8.2
- `nix run .#ghc966-example` to start the example project with GHC 9.6.6
- `nix develop` or `nix develop .#ghc982-shell` to get a shell with all dependencies installed for GHC 9.8.2.
- `nix develop .#ghc966-shell` to get a shell with all dependencies installed for GHC 9.6.6.
- `nix build`, `nix build .#ghc982-web-view` and `nix build .#ghc966-web-view` builds the library with the `overriddenHaskellPackages`
- If you want to import this flake, use the overlay
- `nix flake update nixpkgs` will update the Haskell package sets and development tools

### Common Nix Issues

#### Not Allowed to Refer to GHC

If you get an error like:

```
error: output '/nix/store/64k8iw0ryz76qpijsnl9v87fb26v28z8-my-haskell-package-1.0.0.0' is not allowed to refer to the following paths:
/nix/store/5q5s4a07gaz50h04zpfbda8xjs8wrnhg-ghc-9.6.3
```

Follow these [instructions](https://nixos.org/manual/nixpkgs/unstable/#haskell-packaging-helpers)

#### Dependencies Incorrect

You will need to update the overlay, look for where it says `"${packageName}" = hfinal.callCabal2nix packageName src { };` and add a line like `Diff = hfinal.callHackage "Diff" "0.5" { };` with the package and version you need.

#### Missing Files

Check the `include` inside the `nix-filter.lib` to see if all files needed by cabal are there.

Learn More
----------
Expand Down
191 changes: 191 additions & 0 deletions Session.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
cd ~/Projects/Work/GasWork/RelatedWork/web-view
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
set shortmess=aoOA
else
set shortmess=aoO
endif
badd +500 src/Web/View/Types.hs
badd +277 src/Web/View/Style.hs
badd +68 ~/.local/share/nvim/parrot/chats/2025-01-23.22-56-48.041.md
badd +66 web-view.cabal
badd +251 ~/.local/share/nvim/parrot/chats/2025-01-25.06-42-05.937.md
badd +1 src/Web/View/Types
argglobal
%argdel
$argadd src/Web/View/Types
edit src/Web/View/Style.hs
let s:save_splitbelow = &splitbelow
let s:save_splitright = &splitright
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd _ | wincmd |
split
1wincmd k
wincmd w
wincmd w
wincmd _ | wincmd |
split
1wincmd k
wincmd w
let &splitbelow = s:save_splitbelow
let &splitright = s:save_splitright
wincmd t
let s:save_winminheight = &winminheight
let s:save_winminwidth = &winminwidth
set winminheight=0
set winheight=1
set winminwidth=0
set winwidth=1
exe '1resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe '2resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 2resize ' . ((&columns * 91 + 91) / 182)
exe '3resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 3resize ' . ((&columns * 90 + 91) / 182)
exe '4resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 4resize ' . ((&columns * 90 + 91) / 182)
argglobal
balt src/Web/View/Types.hs
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let &fdl = &fdl
let s:l = 277 - ((18 * winheight(0) + 19) / 38)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 277
normal! 0
lcd ~/Projects/Work/GasWork/RelatedWork/web-view
wincmd w
argglobal
if bufexists(fnamemodify("~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Style.hs", ":p")) | buffer ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Style.hs | else | edit ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Style.hs | endif
if &buftype ==# 'terminal'
silent file ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Style.hs
endif
balt ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let &fdl = &fdl
let s:l = 499 - ((30 * winheight(0) + 19) / 38)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 499
normal! 02|
lcd ~/Projects/Work/GasWork/RelatedWork/web-view
wincmd w
argglobal
if bufexists(fnamemodify("~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs", ":p")) | buffer ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs | else | edit ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs | endif
if &buftype ==# 'terminal'
silent file ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs
endif
balt ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Style.hs
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal nofen
silent! normal! zE
31,63fold
87,112fold
150,168fold
276,279fold
392,413fold
442,470fold
510,519fold
let &fdl = &fdl
let s:l = 125 - ((24 * winheight(0) + 19) / 38)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 125
normal! 0
lcd ~/Projects/Work/GasWork/RelatedWork/web-view
wincmd w
argglobal
if bufexists(fnamemodify("~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs", ":p")) | buffer ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs | else | edit ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs | endif
if &buftype ==# 'terminal'
silent file ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Types.hs
endif
balt ~/Projects/Work/GasWork/RelatedWork/web-view/src/Web/View/Style.hs
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal nofen
silent! normal! zE
31,63fold
87,112fold
150,168fold
276,279fold
392,413fold
442,470fold
510,519fold
let &fdl = &fdl
let s:l = 268 - ((19 * winheight(0) + 19) / 38)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 268
normal! 0
lcd ~/Projects/Work/GasWork/RelatedWork/web-view
wincmd w
exe '1resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe '2resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 2resize ' . ((&columns * 91 + 91) / 182)
exe '3resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 3resize ' . ((&columns * 90 + 91) / 182)
exe '4resize ' . ((&lines * 38 + 39) / 79)
exe 'vert 4resize ' . ((&columns * 90 + 91) / 182)
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let &winminheight = s:save_winminheight
let &winminwidth = s:save_winminwidth
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
set hlsearch
let g:this_session = v:this_session
let g:this_obsession = v:this_session
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
3 changes: 1 addition & 2 deletions bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ watchexec -e hs,yaml cabal test &

# Autoreload on save. Show errors and warnings
# run even if warnings
cd example
ghcid --command "cabal repl example" -T Main.main -W
ghcid --command="cabal repl exe:example lib:web-view" --run=Main.main --warnings --reload=./embed/preflight.css
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tests: True
multi-repl: True
packages:
.
example
3 changes: 0 additions & 3 deletions example/cabal.project

This file was deleted.

Loading
Loading