# SPDX-FileCopyrightText: 2025 Julien Moutinho # SPDX-License-Identifier: CC0-1.0 { description = "Worksheet"; inputs = { nixpkgs.url = "flake:nixpkgs"; git-hooks.url = "github:cachix/git-hooks.nix"; git-hooks.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = inputs: let pkg = "worksheets"; lib = inputs.nixpkgs.lib; fileInputs = with lib.fileset; toSource { root = ./.; fileset = unions [ ./worksheets.cabal #./ChangeLog.md #./Readme.md ./LICENSES (fileFilter (file: lib.any file.hasExt [ "hs" ]) ./src) (fileFilter (file: lib.any file.hasExt [ "css" ]) ./style) (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`. perSystem = f: lib.genAttrs lib.systems.flakeExposed ( system: f rec { inherit system; #pkgs = import inputs.nixpkgs { inherit system; }; pkgs = inputs.nixpkgs.legacyPackages.${system}; haskellPackages = pkgs.haskellPackages.extend (with pkgs.haskell.lib; finalHaskellPkgs: previousHaskellPkgs: { ${pkg} = buildFromSdist (finalHaskellPkgs.callCabal2nix pkg fileInputs { }); }); } ); in { # `nix -L build` packages = perSystem ({ haskellPackages, ... }: { default = haskellPackages.${pkg}; }); # `nix -L develop` or `direnv allow` devShells = perSystem ({ pkgs, haskellPackages, system, ... }: { default = haskellPackages.shellFor { packages = ps: [ ps.${pkg} ]; nativeBuildInputs = [ haskellPackages.cabal-fmt haskellPackages.cabal-install haskellPackages.ghcid haskellPackages.haskell-language-server haskellPackages.hlint #pkgs.git-chglog pkgs.reuse ]; withHoogle = false; inherit (inputs.self.checks.${system}.git-hooks-check) shellHook; }; }); # `nix flake check` checks = perSystem (args: with args; { git-hooks-check = inputs.git-hooks.lib.${system}.run { src = ./.; hooks = { cabal-fmt.enable = true; fourmolu.enable = true; hlint.enable = true; nixpkgs-fmt.enable = true; ormolu.settings.cabalDefaultExtensions = true; ormolu.settings.defaultExtensions = [ "ImportQualifiedPost" "TypeApplications" ]; reuse = { enable = true; entry = "${pkgs.reuse}/bin/reuse lint"; pass_filenames = false; }; }; }; }); }; }