Skip to content

Commit e803e4b

Browse files
sestrelladavidnbrfm7-1
authored
chore: Replace haskell.nix with stacklock2nix (#251)
Co-authored-by: David Becerra <dbecerra@stackbuilders.com> Co-authored-by: Fabricio Mera <55803899+fm7-1@users.noreply.github.com>
1 parent 745b439 commit e803e4b

15 files changed

Lines changed: 245 additions & 849 deletions

File tree

.envrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
use flake
1+
export DIRENV_WARN_TIMEOUT=20s
2+
3+
eval "$(devenv direnvrc)"
4+
5+
use devenv

.github/workflows/build.yml

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,76 @@ on:
99
types:
1010
- opened
1111
- synchronize
12+
1213
concurrency:
1314
group: build-${{ github.ref }}
1415
cancel-in-progress: true
1516

1617
jobs:
17-
haskell:
18+
build:
19+
strategy:
20+
matrix:
21+
runner:
22+
- macos-latest
23+
- ubuntu-latest
24+
runs-on: ${{ matrix.runner }}
25+
env:
26+
LANG: en_US.UTF-8
27+
LC_ALL: en_US.UTF-8
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
- name: Install Nix
32+
uses: cachix/install-nix-action@v31
33+
- name: Setup Cachix
34+
uses: cachix/cachix-action@v16
35+
with:
36+
name: devenv
37+
- name: Install devenv
38+
run: nix profile install nixpkgs#devenv
39+
- name: Setup cache for `~/.stack`
40+
uses: actions/cache@v4
41+
with:
42+
path: ~/.stack
43+
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('hapistrano.cabal') }}
44+
restore-keys: |
45+
${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-
46+
${{ runner.os }}-stack-global-
47+
- name: Install dependencies
48+
run: devenv shell -- stack build --only-dependencies --test
49+
- name: Setup cache for `.stack-work`
50+
uses: actions/cache@v4
51+
with:
52+
path: .stack-work
53+
key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('hapistrano.cabal') }}-${{ hashFiles('**/*.hs') }}
54+
restore-keys: |
55+
${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('hapistrano.cabal') }}-
56+
${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-
57+
${{ runner.os }}-stack-work-
58+
- name: Compile code
59+
run: devenv shell -- stack build --test --no-run-tests
60+
- name: Run tests
61+
run: devenv shell -- stack test
62+
63+
nix-build:
1864
strategy:
1965
matrix:
20-
os:
21-
- macos-13 # x86_64-darwin
22-
- macos-latest # aarch64-darwin
23-
- ubuntu-latest # x86_64-linux
24-
fail-fast: true
25-
runs-on: ${{ matrix.os }}
26-
timeout-minutes: 30
66+
runner:
67+
- macos-latest
68+
- ubuntu-latest
69+
runs-on: ${{ matrix.runner }}
2770
steps:
28-
- uses: actions/checkout@v4
29-
- uses: DeterminateSystems/nix-installer-action@v12
71+
- name: Checkout code
72+
uses: actions/checkout@v4
73+
- name: Install Nix
74+
uses: cachix/install-nix-action@v31
75+
- name: Setup Cachix
76+
uses: cachix/cachix-action@v16
3077
with:
31-
extra-conf: accept-flake-config = true
32-
- uses: DeterminateSystems/magic-nix-cache-action@v7
33-
- name: Compile code ${{ matrix.ghc }}
34-
run: nix build .#test
35-
- name: Run tests ${{ matrix.ghc }}
36-
run: nix run .#test
78+
name: stackbuilders
79+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
80+
- name: Build `default` package
81+
run: nix build
3782

3883
docker:
3984
uses: ./.github/workflows/reusable-docker.yml

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ cabal.sandbox.config
2020
.stack-work/
2121
dist-newstyle
2222
result
23-
nix/
2423
.ghc.environment.*
2524
.tmuxinator.yml
2625
# Devenv

bin/ghc810

Lines changed: 0 additions & 2 deletions
This file was deleted.

bin/ghc90

Lines changed: 0 additions & 2 deletions
This file was deleted.

devenv.lock

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
"flake-compat": {
2121
"flake": false,
2222
"locked": {
23-
"lastModified": 1696426674,
23+
"lastModified": 1733328505,
2424
"owner": "edolstra",
2525
"repo": "flake-compat",
26-
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
27-
"treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb",
26+
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
2827
"type": "github"
2928
},
3029
"original": {
@@ -33,10 +32,31 @@
3332
"type": "github"
3433
}
3534
},
35+
"git-hooks": {
36+
"inputs": {
37+
"flake-compat": "flake-compat",
38+
"gitignore": "gitignore",
39+
"nixpkgs": [
40+
"nixpkgs"
41+
]
42+
},
43+
"locked": {
44+
"lastModified": 1742649964,
45+
"owner": "cachix",
46+
"repo": "git-hooks.nix",
47+
"rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82",
48+
"type": "github"
49+
},
50+
"original": {
51+
"owner": "cachix",
52+
"repo": "git-hooks.nix",
53+
"type": "github"
54+
}
55+
},
3656
"gitignore": {
3757
"inputs": {
3858
"nixpkgs": [
39-
"pre-commit-hooks",
59+
"git-hooks",
4060
"nixpkgs"
4161
]
4262
},
@@ -45,7 +65,6 @@
4565
"owner": "hercules-ci",
4666
"repo": "gitignore.nix",
4767
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
48-
"treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9",
4968
"type": "github"
5069
},
5170
"original": {
@@ -70,50 +89,14 @@
7089
"type": "github"
7190
}
7291
},
73-
"nixpkgs-stable": {
74-
"locked": {
75-
"lastModified": 1718811006,
76-
"owner": "NixOS",
77-
"repo": "nixpkgs",
78-
"rev": "03d771e513ce90147b65fe922d87d3a0356fc125",
79-
"treeHash": "ab837eb82b2b0afbb6568f2b27f214324699af3d",
80-
"type": "github"
81-
},
82-
"original": {
83-
"owner": "NixOS",
84-
"ref": "nixos-23.11",
85-
"repo": "nixpkgs",
86-
"type": "github"
87-
}
88-
},
89-
"pre-commit-hooks": {
90-
"inputs": {
91-
"flake-compat": "flake-compat",
92-
"gitignore": "gitignore",
93-
"nixpkgs": [
94-
"nixpkgs"
95-
],
96-
"nixpkgs-stable": "nixpkgs-stable"
97-
},
98-
"locked": {
99-
"lastModified": 1718879355,
100-
"owner": "cachix",
101-
"repo": "pre-commit-hooks.nix",
102-
"rev": "8cd35b9496d21a6c55164d8547d9d5280162b07a",
103-
"treeHash": "246f2197feb48979ccc58af4cab0cfd0f5738645",
104-
"type": "github"
105-
},
106-
"original": {
107-
"owner": "cachix",
108-
"repo": "pre-commit-hooks.nix",
109-
"type": "github"
110-
}
111-
},
11292
"root": {
11393
"inputs": {
11494
"devenv": "devenv",
95+
"git-hooks": "git-hooks",
11596
"nixpkgs": "nixpkgs",
116-
"pre-commit-hooks": "pre-commit-hooks"
97+
"pre-commit-hooks": [
98+
"git-hooks"
99+
]
117100
}
118101
}
119102
},

devenv.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ pkgs, lib, ... }:
2+
3+
{
4+
packages =
5+
[
6+
pkgs.git
7+
pkgs.stack
8+
pkgs.zsh
9+
]
10+
++ lib.optionals pkgs.stdenv.isLinux [
11+
pkgs.gmp
12+
];
13+
}

devenv.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
2+
inputs:
3+
nixpkgs:
4+
url: github:cachix/devenv-nixpkgs/rolling

docs/NIX.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,50 @@
33
## Requirements
44

55
- Install [Nix](https://nixos.org/download.html)
6-
- Enable Flakes [permanently](https://nixos.wiki/wiki/Flakes#Permanent)
6+
- Enable [Flakes](https://nixos.wiki/wiki/Flakes#Permanent) permanently
7+
- Install [devenv](https://devenv.sh/getting-started/):
78

8-
**For macOS users**
9+
## Project Structure
910

10-
Add the following lines to configuration file located at `/etc/nix/nix.conf`:
11+
The project uses:
12+
- Nix Flakes for reproducible builds and development environments
13+
- `stacklock2nix` for deriving Nix packages from stack.yaml.lock
14+
- `devenv` for creating consistent development environments
1115

12-
```
13-
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
14-
substituters = https://cache.iog.io https://cache.nixos.org
15-
```
16+
### Flake.nix
1617

17-
Restart the `nix-daemon` service:
18+
The flake.nix file has the following inputs:
19+
- `nixpkgs`: Standard Nix packages repository
20+
- `stacklock2nix`: A tool for generating Nix packages from stack.yaml.lock files
1821

19-
```
20-
sudo launchctl stop org.nixos.nix-daemon
21-
sudo launchctl start org.nixos.nix-daemon
22-
```
22+
The flake outputs:
23+
- `packages.default`: The Hapistrano package for each supported system
24+
- `overlays.default`: An overlay for integrating Hapistrano into other Nix
25+
systems
2326

24-
If the following messages appear running the scripts detailed in the section
25-
below, it means that Nix is not picking up the substituters we described
26-
earlier and is unable to use them as a derivation cache:
27+
## Development Environments
2728

28-
```
29-
warning: ignoring untrusted substituter 'https://cache.iog.io'
30-
```
31-
in which case
32-
it is recommended to go over the steps detailed in this section again, or look for alternative ways to add extra substituters in [nix.conf](https://nix.dev/manual/nix/2.18/command-ref/conf-file).
33-
34-
## Enabling the development environment
29+
The project includes a `devenv.nix` configuration that provides a consistent
30+
development environment with all necessary dependencies.
3531

36-
To enable the development environment exposed by the project's [Nix flake](../flake.nix), you can start a development shell by running the following command from within the project's root:
32+
To use devenv:
3733

3834
```
39-
nix develop
35+
devenv shell
4036
```
4137

42-
Alternatively, if you are using [nix-direnv](https://github.com/nix-community/nix-direnv) (recommended), you can run:
38+
The devenv configuration includes:
39+
- Essential tools like git, stack, and zsh
40+
- System-specific dependencies (e.g., gmp for Linux systems)
41+
42+
### Using nix-direnv
43+
44+
If you are using [nix-direnv](https://github.com/nix-community/nix-direnv), run:
4345

4446
```
4547
direnv allow
4648
```
4749

48-
that will enable the development shell according to the contents of [.envrc](../.envrc). It is advisable not to run `direnv allow` blindly and always check the contents of [.envrc](../.envrc) files first to ensure nothing malicious is executed.
50+
This will enable the development shell according to the contents of
51+
[.envrc](../.envrc). Always check the contents of [.envrc](../.envrc) files
52+
before running `direnv allow` to ensure nothing malicious is executed.

0 commit comments

Comments
 (0)