-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegate most Nix to
srid/haskell-flake
(a flake-parts
module for…
… Haskell dev) (#22) * Move Haskell stuff into separate module cf. https://github.com/hercules-ci/flake-parts/blob/main/modules/apps.nix * Parametrize the haskell part * Allow user to override default attrs * Add baseBuildTools (so they can be overriden) * Don't hardcode non-essential build tools * Avoid types.anything * Merge into one buildTools, using sets * getExe and type are redundant Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> * Use docstring wherever possible * Use ${self} as default for root * Allow defining multiple Haskell packages The downside: the user is forced to define 'default' flake outputs. * Automatically create 'default' attr if a singleton projects set * Make haskell.nix its own repo Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
33 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,33 @@ | ||
{ | ||
description = "haskell-template's description"; | ||
description = "srid/haskell-template: Nix template for Haskell projects"; | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
flake-parts.inputs.nixpkgs.follows = "nixpkgs"; | ||
flake-compat.url = "github:edolstra/flake-compat"; | ||
flake-compat.flake = false; | ||
flake-compat.inputs.nixpkgs.follows = "nixpkgs"; | ||
haskell-flake.url = "github:srid/haskell-flake"; | ||
}; | ||
|
||
# We use flake-parts as a way to make flakes 'system-aware' | ||
# cf. https://github.com/NixOS/nix/issues/3843#issuecomment-661720562 | ||
outputs = { self, nixpkgs, flake-parts, ... }: | ||
outputs = { self, nixpkgs, flake-parts, haskell-flake, ... }: | ||
flake-parts.lib.mkFlake { inherit self; } { | ||
systems = nixpkgs.lib.systems.flakeExposed; | ||
# The primed versions (self', inputs') are same as the non-primed | ||
# versions, but with 'system' already applied. | ||
perSystem = { self', inputs', pkgs, system, ... }: | ||
let | ||
inherit (pkgs.lib.lists) optionals; | ||
|
||
# Specify GHC version here. To get the appropriate value, run: | ||
# nix-env -f "<nixpkgs>" -qaP -A haskell.compiler | ||
hp = pkgs.haskellPackages; # Eg: pkgs.haskell.packages.ghc921; | ||
|
||
# Specify your build/dev dependencies here. | ||
shellDeps = with hp; [ | ||
cabal-fmt | ||
cabal-install | ||
ghcid | ||
haskell-language-server | ||
fourmolu | ||
hlint | ||
pkgs.nixpkgs-fmt | ||
pkgs.treefmt | ||
]; | ||
|
||
project = | ||
{ returnShellEnv ? false | ||
, withHoogle ? false | ||
}: | ||
hp.developPackage { | ||
inherit returnShellEnv withHoogle; | ||
name = "haskell-template"; | ||
root = ./.; | ||
overrides = self: super: with pkgs.haskell.lib; { | ||
# Use callCabal2nix to override Haskell dependencies here | ||
# cf. https://tek.brick.do/K3VXJd8mEKO7 | ||
# Example: | ||
# > NanoID = self.callCabal2nix "NanoID" inputs'.NanoID { }; | ||
# Assumes that you have the 'NanoID' flake input defined. | ||
}; | ||
modifier = drv: | ||
pkgs.haskell.lib.overrideCabal drv (oa: { | ||
# All the Cabal-specific overrides go here. | ||
# For examples on what is possible, see: | ||
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/lib/compose.nix | ||
buildTools = (oa.buildTools or [ ]) ++ optionals returnShellEnv shellDeps; | ||
}); | ||
}; | ||
in | ||
{ | ||
# Used by `nix build ...` | ||
packages = { | ||
default = project { }; | ||
}; | ||
# Used by `nix run ...` | ||
apps = { | ||
default = { | ||
type = "app"; | ||
program = pkgs.lib.getExe self'.packages.default; | ||
}; | ||
}; | ||
# Used by `nix develop ...` | ||
devShells = { | ||
default = project { returnShellEnv = true; withHoogle = true; }; | ||
imports = [ | ||
haskell-flake.flakeModule | ||
]; | ||
perSystem = { self', pkgs, ... }: { | ||
haskellProjects.haskell-template = { | ||
buildTools = hp: { | ||
# TODO: Use https://github.com/numtide/treefmt/pull/169 | ||
inherit (pkgs) | ||
treefmt | ||
nixpkgs-fmt; | ||
inherit (hp) | ||
cabal-fmt | ||
fourmolu; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |