# SPDX-FileCopyrightText: 2025 Julien Moutinho # SPDX-License-Identifier: CC0-1.0 { description = "Literate Business"; nixConfig = { allow-import-from-derivation = true; }; inputs = { nixpkgs.url = "flake:nixpkgs"; git-hooks.url = "github:cachix/git-hooks.nix"; git-hooks.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = inputs: let pkg = "literate-business"; inherit (inputs.nixpkgs) lib; fileInputs = with lib.fileset; toSource { root = ./.; fileset = unions [ ./literate-business.cabal #./ChangeLog.md #./Readme.md ./LICENSES (fileFilter (file: lib.any file.hasExt [ "hs" ]) ./src) (fileFilter (file: lib.any file.hasExt [ "css" ]) ./data/styles) (fileFilter ( file: lib.any file.hasExt [ "hs" "html" "txt" ] ) ./tests) #(fileFilter (file: lib.any file.hasExt [ "hs" ]) ./app) ]; }; # Helper to build for each system in `lib.systems.flakeExposed`. forallSystems = f: lib.genAttrs lib.systems.flakeExposed ( system: f rec { inherit system; #pkgs = inputs.nixpkgs.legacyPackages.${system}; pkgs = import inputs.nixpkgs { inherit system; overlays = [ (finalPkgs: previousPkgs: { haskellPackages = previousPkgs.haskellPackages.extend ( with finalPkgs.haskell.lib; finalHaskellPkgs: previousHaskellPkgs: { ${pkg} = buildFromSdist (finalHaskellPkgs.callCabal2nix pkg fileInputs { }); } ); }) ]; }; } ); in { # `nix -L build` packages = forallSystems ( { pkgs, ... }: pkgs // { default = pkgs.haskellPackages.${pkg}; } ); # `nix -L develop` or `direnv allow` devShells = forallSystems ( { pkgs, system, ... }: { default = pkgs.haskellPackages.shellFor { packages = ps: [ ps.${pkg} ]; nativeBuildInputs = [ pkgs.haskellPackages.cabal-fmt pkgs.haskellPackages.cabal-install pkgs.haskellPackages.eventlog2html pkgs.haskellPackages.ghc-gc-tune pkgs.haskellPackages.ghcid pkgs.haskellPackages.haskell-language-server pkgs.haskellPackages.hlint #pkgs.haskellPackages.hs-speedscope pkgs.reuse pkgs.xdot pkgs.gnuplot pkgs.fswatch ] ++ inputs.self.checks.${system}.git-hooks-check.enabledPackages; withHoogle = false; shellHook = '' ${inputs.self.checks.${system}.git-hooks-check.shellHook} ''; }; } ); # `nix flake check` checks = forallSystems ( args: with args; { git-hooks-check = inputs.git-hooks.lib.${system}.run { src = ./.; hooks = { cabal-fmt.enable = true; fourmolu.enable = true; hlint.enable = true; nixfmt-rfc-style.enable = true; ormolu.settings.cabalDefaultExtensions = true; ormolu.settings.defaultExtensions = [ "ImportQualifiedPost" "TypeApplications" ]; reuse = { enable = true; entry = "${pkgs.reuse}/bin/reuse lint"; pass_filenames = false; }; }; }; } ); # `nix fmt` formatter = forallSystems ( args: with args; let config = inputs.self.checks.${system}.git-hooks-check.config; inherit (config) package configFile; script = '' ${lib.getExe package} run --all-files --config ${configFile} ''; in pkgs.writeShellScriptBin "pre-commit-run" script ); }; }