]> Git — Sourcephile - haskell/mpms.git/blob - flake.nix
init
[haskell/mpms.git] / flake.nix
1 # SPDX-FileCopyrightText: 2022 Julien Mouyinho <julm+most-perfect-magic-squares@sourcephile.fr>
2 # SPDX-License-Identifier: CC0-1.0
3 {
4 description = "Most-Perfect Magic Square";
5 inputs = {
6 nixpkgs.url = "flake:nixpkgs";
7 };
8 outputs =
9 inputs:
10 let
11 lib = inputs.nixpkgs.lib;
12 # Helper to build for each system in `lib.systems.flakeExposed`.
13 perSystem =
14 f:
15 lib.genAttrs lib.systems.flakeExposed (
16 system:
17 f rec {
18 inherit system;
19 pkgs = import inputs.nixpkgs { inherit system; };
20 haskellPackages = pkgs.haskellPackages;
21 }
22 );
23 in
24 {
25 # `nix -L build`
26 packages = perSystem (
27 { pkgs, system, haskellPackages, ... }:
28 {
29 # The Glasgow Haskell Compiler (GHC)
30 # Here made available as `.#ghc` for Main.hs's shebang
31 ghc = haskellPackages.ghcWithPackages (
32 haskellPackages: [
33 # Extra Haskell packages available
34 haskellPackages.blaze-builder
35 haskellPackages.blaze-html
36 haskellPackages.blaze-markup
37 haskellPackages.relude
38 haskellPackages.text
39 haskellPackages.transformers
40 ]
41 );
42 ghcid = pkgs.ghcid;
43 # A compiled version of `Main.hs`
44 # (instead of an interpreted one when run as `./Main.hs`)
45 # To avoid writing a `.cabal` file, `ghc --make` is called directly here,
46 # but should the script become a full fledge executable,
47 # a `.cabal` file should be written instead.
48 default = pkgs.stdenv.mkDerivation {
49 name = "Main";
50 src = ./.;
51 buildInputs = [
52 inputs.self.packages.${system}.ghc
53 ];
54 buildPhase = ''
55 mkdir -p $out/bin
56 ghc -o "$out/bin/Main" -O2 --make ./Main.hs
57 '';
58 };
59 }
60 );
61 # `nix develop` or `direnv allow`
62 devShells = perSystem (
63 { pkgs, system, ... }:
64 {
65 default = pkgs.mkShell {
66 nativeBuildInputs = [
67 inputs.self.packages.${system}.ghc
68 pkgs.haskellPackages.haskell-language-server
69 pkgs.haskellPackages.hlint
70 pkgs.reuse
71 ];
72 };
73 }
74 );
75 # `nix flake check`
76 checks = perSystem (args: with args; {
77 git-hooks-check = inputs.git-hooks.lib.${system}.run {
78 src = ./.;
79 hooks = {
80 ormolu.settings.cabalDefaultExtensions = true;
81 cabal-fmt.enable = true;
82 fourmolu.enable = true;
83 hlint.enable = true;
84 nixfmt-rfc-style.enable = true;
85 reuse = {
86 enable = true;
87 entry = "${pkgs.reuse}/bin/reuse lint";
88 pass_filenames = false;
89 };
90 };
91 };
92 });
93 };
94 }
95