# SPDX-FileCopyrightText: 2025 Julien Moutinho # SPDX-License-Identifier: CC0-1.0 { description = "Literate Invoice"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/9cb344e96d5b6918e94e1bca2d9f3ea1e9615545"; git-hooks.url = "github:cachix/git-hooks.nix"; git-hooks.inputs.nixpkgs.follows = "nixpkgs"; really-safe-money = { url = "github:NorfairKing/really-safe-money"; flake = false; }; }; outputs = inputs: let pkg = "literate-invoice"; lib = inputs.nixpkgs.lib; fileInputs = with lib.fileset; toSource { root = ./.; fileset = unions [ ./literate-invoice.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; config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "really-safe-money" ]; overlays = [ (finalPkgs: previousPkgs: { haskellPackages = previousPkgs.haskellPackages.extend ( with finalPkgs.haskell.lib; finalHaskellPkgs: previousHaskellPkgs: { ${pkg} = buildFromSdist (finalHaskellPkgs.callCabal2nix pkg fileInputs { }); really-safe-money = finalHaskellPkgs.callCabal2nix "really-safe-money" "${inputs.really-safe-money}/really-safe-money" { }; } ); }) ]; }; } ); 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.git-chglog 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 ); }; }