# SPDX-FileCopyrightText: 2022 Julien Mouyinho # SPDX-License-Identifier: CC0-1.0 { description = "Most-Perfect Magic Square"; inputs = { nixpkgs.url = "flake:nixpkgs"; }; outputs = inputs: let lib = inputs.nixpkgs.lib; # Helper to build for each system in `lib.systems.flakeExposed`. perSystem = f: lib.genAttrs lib.systems.flakeExposed ( system: f rec { inherit system; pkgs = import inputs.nixpkgs { inherit system; }; haskellPackages = pkgs.haskellPackages; } ); in { # `nix -L build` packages = perSystem ( { pkgs, system, haskellPackages, ... }: { # The Glasgow Haskell Compiler (GHC) # Here made available as `.#ghc` for Main.hs's shebang ghc = haskellPackages.ghcWithPackages ( haskellPackages: [ # Extra Haskell packages available haskellPackages.blaze-builder haskellPackages.blaze-html haskellPackages.blaze-markup haskellPackages.relude haskellPackages.text haskellPackages.transformers ] ); ghcid = pkgs.ghcid; # A compiled version of `Main.hs` # (instead of an interpreted one when run as `./Main.hs`) # To avoid writing a `.cabal` file, `ghc --make` is called directly here, # but should the script become a full fledge executable, # a `.cabal` file should be written instead. default = pkgs.stdenv.mkDerivation { name = "Main"; src = ./.; buildInputs = [ inputs.self.packages.${system}.ghc ]; buildPhase = '' mkdir -p $out/bin ghc -o "$out/bin/Main" -O2 --make ./Main.hs ''; }; } ); # `nix develop` or `direnv allow` devShells = perSystem ( { pkgs, system, ... }: { default = pkgs.mkShell { nativeBuildInputs = [ inputs.self.packages.${system}.ghc pkgs.haskellPackages.haskell-language-server pkgs.haskellPackages.hlint pkgs.reuse ]; }; } ); # `nix flake check` checks = perSystem (args: with args; { git-hooks-check = inputs.git-hooks.lib.${system}.run { src = ./.; hooks = { ormolu.settings.cabalDefaultExtensions = true; cabal-fmt.enable = true; fourmolu.enable = true; hlint.enable = true; nixfmt-rfc-style.enable = true; reuse = { enable = true; entry = "${pkgs.reuse}/bin/reuse lint"; pass_filenames = false; }; }; }; }); }; }