Skip to content

Commit a7ca63a

Browse files
committed
refactoring: reintroduce nix
1 parent 72f3817 commit a7ca63a

File tree

5 files changed

+321
-2
lines changed

5 files changed

+321
-2
lines changed

.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
use flake -Lv --fallback
1+
use flake

.github/workflows/nix-check.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "libsodium hs nix check"
2+
on:
3+
pull_request:
4+
push:
5+
branches: ["main"]
6+
jobs:
7+
tests:
8+
runs-on: ubuntu-latest
9+
continue-on-error: true
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: cachix/install-nix-action@v25
13+
with:
14+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
15+
- uses: cachix/cachix-action@v14
16+
with:
17+
name: libsodium-hs
18+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
19+
- run: nix flake check -Lv --allow-import-from-derivation --fallback

flake.lock

Lines changed: 179 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11-small";
4+
flake-utils.url = "github:numtide/flake-utils";
5+
flake-compat = {
6+
url = "github:edolstra/flake-compat";
7+
flake = false;
8+
};
9+
pre-commit-hooks = {
10+
url = "github:cachix/pre-commit-hooks.nix";
11+
inputs.nixpkgs.follows = "nixpkgs";
12+
inputs.flake-utils.follows = "flake-utils";
13+
};
14+
gitignore = {
15+
url = "github:hercules-ci/gitignore.nix";
16+
inputs.nixpkgs.follows = "nixpkgs";
17+
};
18+
};
19+
20+
nixConfig = {
21+
extra-substituters = [
22+
"https://libsodium-hs.cachix.org"
23+
];
24+
extra-trusted-public-keys = [
25+
"libsodium-hs.cachix.org-1:u/v4XdWrbl+G/fDUoEwB1yvMdlxdKM4al2odCNsrqkg="
26+
];
27+
allow-import-from-derivation = true;
28+
};
29+
30+
outputs = inputs@{ nixpkgs, ... }:
31+
let
32+
# this is to allow running `nix flake check` by using `--impure`
33+
systems =
34+
if builtins.hasAttr "currentSystem" builtins
35+
then [ builtins.currentSystem ]
36+
else nixpkgs.lib.systems.flakeExposed;
37+
in
38+
inputs.flake-utils.lib.eachSystem systems (system:
39+
let
40+
inherit (inputs.gitignore.lib) gitignoreSource;
41+
42+
pkgs = import nixpkgs {
43+
inherit system;
44+
config.allowBroken = true;
45+
};
46+
47+
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
48+
src = ./.;
49+
hooks = {
50+
# nix checks
51+
nixpkgs-fmt.enable = true;
52+
deadnix.enable = true;
53+
statix.enable = true;
54+
55+
# Haskell checks
56+
fourmolu.enable = true;
57+
cabal-fmt.enable = true;
58+
hlint.enable = true;
59+
};
60+
};
61+
62+
hsPkgs = pkgs.haskellPackages.override (_old: {
63+
overrides = with pkgs.haskell.lib.compose; hself: hsuper:
64+
let
65+
commonOverrides = overrideCabal (_drv: {
66+
doInstallIntermediates = true;
67+
enableSeparateIntermediatesOutput = true;
68+
pkg-configDepends = [
69+
pkgs.libsodium
70+
];
71+
});
72+
in
73+
{
74+
libsodium-bindings = commonOverrides (hself.callCabal2nix "libsodium-bindings" (gitignoreSource ./libsodium-bindings) { });
75+
sel = commonOverrides (hself.callCabal2nix "sel" (gitignoreSource ./sel) {
76+
base16 = hsuper.base16_1_0;
77+
hedgehog = hsuper.hedgehog_1_4;
78+
});
79+
};
80+
});
81+
82+
hsShell = hsPkgs.shellFor {
83+
shellHook = ''
84+
${pre-commit-check.shellHook}
85+
set -x
86+
export LD_LIBRARY_PATH="${pkgs.libsodium}/lib"
87+
set +x
88+
'';
89+
90+
packages = ps: with ps; [
91+
libsodium-bindings
92+
sel
93+
];
94+
95+
buildInputs = with hsPkgs; [
96+
pkgs.pkg-config
97+
pkgs.libsodium.dev
98+
cabal-install
99+
haskell-language-server
100+
hlint
101+
cabal-fmt
102+
fourmolu
103+
];
104+
};
105+
106+
in
107+
{
108+
checks = {
109+
inherit (hsPkgs) libsodium-bindings sel;
110+
shell = hsShell;
111+
formatting = pre-commit-check;
112+
};
113+
114+
packages = {
115+
inherit (hsPkgs) libsodium-bindings sel;
116+
};
117+
118+
devShells.default = hsShell;
119+
}
120+
);
121+
}

sel/sel.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test-suite sel-tests
9999
, hedgehog ^>=1.4
100100
, libsodium-bindings
101101
, sel
102-
, tasty ^>=1.5
102+
, tasty >=1.4 && <1.6
103103
, tasty-hunit ^>=0.10
104104
, text
105105
, text-display

0 commit comments

Comments
 (0)