Skip to content

Commit 0df7983

Browse files
authored
Port NeoHaskell to haskell.nix Infrastructure (#203)
* allow multi package builds * fix script * update to support multipackage builds * Refactors binary cache config to use separate file Simplifies Nix binary cache configuration by writing to a dedicated custom config file instead of modifying the main system configuration Reduces complexity by eliminating conditional logic for appending to existing configuration lines and potential conflicts with system-managed settings * Adds automatic Nix daemon restart after configuration Implements cross-platform daemon restart logic to ensure binary cache configuration takes effect immediately without requiring manual restart. Detects macOS, Linux with systemd, and WSL environments to use appropriate restart methods with graceful fallback messaging when restart fails. * bump * refactor(nix): restructure build system to separate shell and package outputs Modifies Haskell project template to return both shell and package targets instead of just packages Updates build and shell commands to use the new structured output format Reorganizes configuration files by extracting common setup and creating dedicated entry points for different use cases Removes obsolete shell configuration file to streamline the development workflow * pin nixpkgs * update ci * chore(ci): improve GitHub Actions setup and caching Adds Dependabot configuration for automatic dependency updates Pins Nix action to specific version for better reproducibility Configures additional substituters and trusted keys for IOG cache to improve build performance * chore(ci): remove Cabal caching and update steps Removes unnecessary caching configuration and Hackage update step from the GitHub Actions workflow to simplify the CI pipeline since Nix already handles dependency management efficiently * fix core tests * Disables doctests due to failing tests Comments out doctest execution in CI workflow to prevent build failures References issue #204 * use magic nix action
1 parent b80204d commit 0df7983

15 files changed

Lines changed: 125 additions & 128 deletions

File tree

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly

.github/workflows/test.yml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,27 @@ jobs:
2828
run: brew install bash
2929

3030
- uses: actions/checkout@v4
31-
- uses: cachix/install-nix-action@v27
3231

33-
- name: Build the project with Nix
34-
run: nix-build
35-
36-
- name: Cache Cabal
37-
id: cache
38-
uses: actions/cache@v4
32+
- uses: DeterminateSystems/determinate-nix-action@v3.8.6
3933
with:
40-
path: |
41-
~/.cabal
42-
dist-newstyle
43-
.devenv/profile
44-
key: ${{ runner.os }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/*.lock') }}-1 # modify the key if the cache is not working as expected
34+
extra-conf: |
35+
extra-substituters = https://cache.iog.io
36+
extra-trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
4537
46-
- name: Update Cabal Hackage list
47-
# if: steps.cache.outputs.cache-hit != 'true'
48-
run: nix-shell --run "cabal update"
38+
- uses: DeterminateSystems/magic-nix-cache-action@v13
39+
40+
- name: Build the project with Nix
41+
run: nix-build
4942

5043
- name: Build the project with cabal
5144
run: nix-shell --run "cabal build all"
5245

5346
- name: Run core tests
5447
run: nix-shell --run "cabal test core"
5548

56-
- name: Run core doctests
57-
run: nix-shell --run "run-doctests-verbose"
49+
# Doctests are failing - See issue #204
50+
# - name: Run core doctests
51+
# run: nix-shell --run "cabal repl --with-compiler=doctest --repl-options=--verbose core"
5852

5953
- name: Run CLI tests
6054
run: nix-shell --run "cabal test cli"

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"Monoid",
2121
"Nanotime",
2222
"NEOHASKELL",
23+
"nhcli",
2324
"nhcore",
2425
"nixfmt",
2526
"nixpkgs",

cli/nhcli.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.4
22
name: nhcli
3-
version: 0.9.0
3+
version: 0.9.1
44
synopsis: Command Line Tool for NeoHaskell
55
description: NeoHaskell is a dialect of Haskell that is focused on newcomer-friendliness and productivity.
66
homepage: https://neohaskell.org
@@ -11,7 +11,7 @@ maintainer: nhlib@nickseagull.dev
1111
copyright:
1212
category: Development
1313
build-type: Simple
14-
extra-source-files: ../nix/haskellnix.nix, ../nix/haskell-project.nix
14+
extra-source-files: ./nix/haskell-project.nix
1515

1616
common common_cfg
1717
ghc-options: -Wall

cli/nix/haskell-project.nix

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
{ pkgs }:
22

3-
# Generic function to create a Haskell project template
4-
{ projectName, src }:
3+
{ packages, mainPackageName, executableName }:
54
let
65
haskellNix = import (pkgs.fetchFromGitHub {
76
owner = "input-output-hk";
87
repo = "haskell.nix";
98
rev = "4d493449406ec91db804511a6d15b6f076ba40e7";
109
sha256 = "sha256-CHNMDgFfpTV5WkVhmMLf5d5qaLUjgeoziVgmgnhPGrI=";
11-
}) { inherit pkgs; };
12-
# Apply haskell.nix overlay
10+
}) { };
1311
pkgsWithOverlay = import haskellNix.sources.nixpkgs-unstable {
1412
overlays = [
1513
haskellNix.overlay
16-
(final: _prev: {
17-
"${projectName}Project" = final.haskell-nix.cabalProject {
18-
inherit src;
19-
compiler-nix-name = "ghc910";
20-
};
21-
})
14+
(final: _prev:
15+
builtins.listToAttrs (builtins.map (packageName: {
16+
name = "${packageName}";
17+
value = final.haskell-nix.cabalProject {
18+
src = packages.${packageName};
19+
compiler-nix-name = "ghc910";
20+
};
21+
}) (builtins.attrNames packages)))
2222
];
2323
inherit (haskellNix) config;
2424
};
2525

26-
flake = pkgsWithOverlay."${projectName}Project".flake { };
26+
pkg = pkgsWithOverlay."${mainPackageName}";
2727

28-
in flake.packages."${projectName}:exe:${projectName}"
28+
in {
29+
shell = pkg.shellFor {
30+
tools = {
31+
cabal = { };
32+
hlint = { };
33+
haskell-language-server = { };
34+
hspec-discover = { };
35+
};
36+
buildInputs = [
37+
pkgs.nil
38+
pkgs.nixfmt-classic
39+
pkgs.nixpkgs-fmt
40+
pkgs.pkg-config
41+
pkgs.zlib
42+
];
43+
};
44+
package = (pkg.flake { }).packages."${executableName}";
45+
}

cli/src/Neo.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ run = do
4949
Command.CommandOptions
5050
{ name = "neo",
5151
description = "NeoHaskell's console helper",
52-
version = Just [Core.version|0.9.0|],
52+
version = Just [Core.version|0.9.1|],
5353
decoder = commandsParser
5454
}
5555
cmd <- Command.parseHandler parser

cli/src/Neo/Build.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ handle config = do
7575
File.writeText targetAppPath appMainFile
7676
|> Task.mapError (\_ -> CustomError "Could not write app main file")
7777

78-
-- FIXME: Create another thread that renders the output of the build via streaming.
79-
-- As right now there's no output at all
78+
let buildExpression :: Text =
79+
[fmt|{ pkgs ? import <nixpkgs> {} }:
80+
( (#{nixFile}) { inherit pkgs; } ).package|]
81+
8082
completion <-
81-
Subprocess.openInherit "nix-build" (Array.fromLinkedList ["-E", nixFile]) rootFolder Subprocess.InheritBOTH
83+
Subprocess.openInherit "nix-build" (Array.fromLinkedList ["-E", buildExpression]) rootFolder Subprocess.InheritBOTH
8284
if completion.exitCode != 0
8385
then errorOut completion.stderr
8486
else print completion.stdout

cli/src/Neo/Build/Templates/Nix.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ let
1818
hp = (#{haskellProject});
1919

2020
in (hp { inherit pkgs; }) {
21-
projectName = "#{name}";
22-
src = ./.;
21+
packages = {
22+
"#{name}" = ./.;
23+
};
24+
mainPackageName = "#{name}";
25+
executableName = "#{name}:exe:#{name}";
2326
}
2427

2528
|]

cli/src/Neo/Shell.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ handle config = do
7575
File.writeText targetAppPath appMainFile
7676
|> Task.mapError (\_ -> CustomError "Could not write app main file")
7777

78-
let shellExpression =
78+
let shellExpression :: Text =
7979
[fmt|{ pkgs ? import <nixpkgs> {} }:
80-
( (#{nixFile}) { inherit pkgs; } ).env|]
80+
( (#{nixFile}) { inherit pkgs; } ).shell|]
81+
8182
completion <-
8283
Subprocess.openInherit "nix-shell" (Array.fromLinkedList ["-E", shellExpression]) rootFolder Subprocess.InheritBOTH
8384
if completion.exitCode != 0

common.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ pkgs ? import ./nix/nixpkgs.nix { } }:
2+
3+
let hp = import ./cli/nix/haskell-project.nix { inherit pkgs; };
4+
in (hp {
5+
packages = {
6+
"nhcore" = ./.;
7+
"nhcli" = ./.;
8+
};
9+
10+
mainPackageName = "nhcli";
11+
executableName = "nhcli:exe:neo";
12+
})

0 commit comments

Comments
 (0)