|
| 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 = |
| 76 | + commonOverrides (hself.callCabal2nix "sel" (gitignoreSource ./sel) { |
| 77 | + base16 = hsuper.base16_1_0; |
| 78 | + hedgehog = hsuper.hedgehog_1_4; |
| 79 | + tasty = hsuper.tasty_1_5; |
| 80 | + }); |
| 81 | + # text-display = markUnbroken hsuper.text-display; |
| 82 | + }; |
| 83 | + }); |
| 84 | + |
| 85 | + hsShell = hsPkgs.shellFor { |
| 86 | + shellHook = '' |
| 87 | + ${pre-commit-check.shellHook} |
| 88 | + set -x |
| 89 | + export LD_LIBRARY_PATH="${pkgs.libsodium}/lib" |
| 90 | + set +x |
| 91 | + ''; |
| 92 | + |
| 93 | + packages = ps: with ps; [ |
| 94 | + libsodium-bindings |
| 95 | + sel |
| 96 | + ]; |
| 97 | + |
| 98 | + buildInputs = with hsPkgs; [ |
| 99 | + pkgs.pkg-config |
| 100 | + pkgs.libsodium.dev |
| 101 | + cabal-install |
| 102 | + haskell-language-server |
| 103 | + hlint |
| 104 | + cabal-fmt |
| 105 | + fourmolu |
| 106 | + ]; |
| 107 | + }; |
| 108 | + |
| 109 | + in |
| 110 | + { |
| 111 | + checks = { |
| 112 | + inherit (hsPkgs) libsodium-bindings sel; |
| 113 | + shell = hsShell; |
| 114 | + formatting = pre-commit-check; |
| 115 | + }; |
| 116 | + |
| 117 | + packages = { |
| 118 | + inherit (hsPkgs) libsodium-bindings sel; |
| 119 | + }; |
| 120 | + |
| 121 | + devShells.default = hsShell; |
| 122 | + } |
| 123 | + ); |
| 124 | +} |
0 commit comments