diff --git a/cabal.nix b/cabal.nix new file mode 100644 index 0000000..d17d05a --- /dev/null +++ b/cabal.nix @@ -0,0 +1,19 @@ +{ mkDerivation, aeson, async, base, data-default, directory +, filepath, lib, mtl, optics-core, profunctors, relude, shower +, time, with-utf8 +}: +mkDerivation { + pname = "haskell-template"; + version = "0.1.0.0"; + src = ./.; + isLibrary = false; + isExecutable = true; + executableHaskellDepends = [ + aeson async base data-default directory filepath mtl optics-core + profunctors relude shower time with-utf8 + ]; + homepage = "https://srid.ca/haskell-template"; + description = "A template for Haskell projects using Nix"; + license = lib.licenses.mit; + mainProgram = "haskell-template"; +} diff --git a/flake.lock b/flake.lock index dc816a1..02d6180 100644 --- a/flake.lock +++ b/flake.lock @@ -38,11 +38,11 @@ "git-hooks": { "flake": false, "locked": { - "lastModified": 1733318908, - "narHash": "sha256-SVQVsbafSM1dJ4fpgyBqLZ+Lft+jcQuMtEL3lQWx2Sk=", + "lastModified": 1734797603, + "narHash": "sha256-ulZN7ps8nBV31SE+dwkDvKIzvN6hroRY8sYOT0w+E28=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "6f4e2a2112050951a314d2733a994fbab94864c6", + "rev": "f0f0dc4920a903c3e08f5bdb9246bb572fcae498", "type": "github" }, "original": { @@ -53,11 +53,11 @@ }, "haskell-flake": { "locked": { - "lastModified": 1734464164, - "narHash": "sha256-5JCCyrgy7IMnipyYMQzIAXncGt2XVlW1aK71A+FTXDs=", + "lastModified": 1734920822, + "narHash": "sha256-YQo6LBiVVT05AcznDtlMuJkigM04FKW+lXQ5uRuT1yQ=", "owner": "srid", "repo": "haskell-flake", - "rev": "e280b39efdd72b6a5bdaa982b67f150c819be642", + "rev": "d8a21e6d8c6c01416e20bc944d7157eaf39ae93c", "type": "github" }, "original": { diff --git a/nix/modules/flake-parts/haskell.nix b/nix/modules/flake-parts/haskell.nix index 28a2979..272417c 100644 --- a/nix/modules/flake-parts/haskell.nix +++ b/nix/modules/flake-parts/haskell.nix @@ -17,6 +17,7 @@ (root + /haskell-template.cabal) (root + /LICENSE) (root + /README.md) + (root + /cabal.nix) ]; }); @@ -25,6 +26,11 @@ # Packages to add on top of `basePackages` packages = { + # For IFD-less evaluation, you can point to pre-generated `cabal2nix` expression + # here for each package, + # haskell-flake will use this file to build the package. + # By default haskell-flake refers to `cabal.nix` + haskell-template.cabal2NixFile = config.pre-commit.settings.hooks.cabal2nix.settings.outputFilename; # Add source or Hackage overrides here # (Local packages are added automatically) /* diff --git a/nix/modules/flake-parts/pre-commit.nix b/nix/modules/flake-parts/pre-commit.nix index 340ca8f..183c5f0 100644 --- a/nix/modules/flake-parts/pre-commit.nix +++ b/nix/modules/flake-parts/pre-commit.nix @@ -7,13 +7,21 @@ perSystem = { config, ... }: { pre-commit.settings = { hooks = { - nixpkgs-fmt.enable = true; + nixpkgs-fmt = { + enable = true; + # cabal2nix, nixpkgs-fmt both modifies default.nix, hence exlude fmt. + excludes = [ config.pre-commit.settings.hooks.cabal2nix.settings.outputFilename ]; + }; cabal-fmt.enable = true; fourmolu = { enable = true; package = config.fourmolu.wrapper; }; hlint.enable = true; + cabal2nix = { + enable = true; + settings.outputFilename = "cabal.nix"; + }; }; };