Skip to content

Commit

Permalink
Split flake.nix into various modules
Browse files Browse the repository at this point in the history
This will be useful during `om init` to ignore the template itself for #120
  • Loading branch information
srid committed Jul 23, 2024
1 parent 66c0fc7 commit 60c8b39
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 92 deletions.
99 changes: 7 additions & 92 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,107 +13,22 @@
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.haskell-flake.flakeModule
inputs.treefmt-nix.flakeModule
inputs.fourmolu-nix.flakeModule
];

# TODO: Remove this. Only relevant for github:srid/haskell-template
flake.templates.default = {
description = "A batteries-included Haskell project template for Nix";
path = builtins.path { path = inputs.self; };
};
# See ./nix/modules/*.nix for the modules that are imported here.
imports =
with builtins; map
(fn: ./nix/modules/${fn})
(attrNames (readDir ./nix/modules));

perSystem = { self', lib, config, pkgs, ... }: {
# Our only Haskell project. You can have multiple projects, but this template
# has only one.
# See https://github.com/srid/haskell-flake/blob/master/example/flake.nix
haskellProjects.default = {
# To avoid unnecessary rebuilds, we filter projectRoot:
# https://community.flake.parts/haskell-flake/local#rebuild
projectRoot = builtins.toString (lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./src
./haskell-template.cabal
./LICENSE
./README.md
];
});

# The base package set (this value is the default)
# basePackages = pkgs.haskellPackages;

# Packages to add on top of `basePackages`
packages = {
# Add source or Hackage overrides here
# (Local packages are added automatically)
/*
aeson.source = "1.5.0.0" # Hackage version
shower.source = inputs.shower; # Flake input
*/
};

# Add your package overrides here
settings = {
/*
haskell-template = {
haddock = false;
};
aeson = {
check = false;
};
*/
};

# Development shell configuration
devShell = {
hlsCheck.enable = false;
};

# What should haskell-flake add to flake outputs?
autoWire = [ "packages" "apps" "checks" ]; # Wire all but the devShell
};

# Auto formatters. This also adds a flake check to ensure that the
# source tree was auto formatted.
treefmt.config = {
projectRootFile = "flake.nix";

programs.fourmolu = {
enable = true;
package = config.fourmolu.wrapper;
};
programs.nixpkgs-fmt.enable = true;
programs.cabal-fmt.enable = true;
programs.hlint.enable = true;
};

fourmolu.settings = {
indentation = 2;
comma-style = "leading";
record-brace-space = true;
indent-wheres = true;
import-export-style = "diff-friendly";
respectful = true;
haddock-style = "multi-line";
newlines-between-decls = 1;
extensions = [ "ImportQualifiedPost" ];
};

# Default package & app.
packages.default = self'.packages.haskell-template;
apps.default = self'.apps.haskell-template;

# Default shell.
devShells.default = pkgs.mkShell {
name = "haskell-template";
meta.description = "Haskell development environment";
# See https://community.flake.parts/haskell-flake/devshell#composing-devshells
inputsFrom = [
config.haskellProjects.default.outputs.devShell
config.treefmt.build.devShell
config.haskellProjects.default.outputs.devShell # See ./nix/modules/haskell.nix
config.treefmt.build.devShell # See ./nix/modules/formatter.nix
];
packages = with pkgs; [
just
Expand Down
29 changes: 29 additions & 0 deletions nix/modules/formatter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
perSystem = { config, pkgs, ... }: {
# Auto formatters. This also adds a flake check to ensure that the
# source tree was auto formatted.
treefmt.config = {
projectRootFile = "flake.nix";

programs.fourmolu = {
enable = true;
package = config.fourmolu.wrapper;
};
programs.nixpkgs-fmt.enable = true;
programs.cabal-fmt.enable = true;
programs.hlint.enable = true;
};

fourmolu.settings = {
indentation = 2;
comma-style = "leading";
record-brace-space = true;
indent-wheres = true;
import-export-style = "diff-friendly";
respectful = true;
haddock-style = "multi-line";
newlines-between-decls = 1;
extensions = [ "ImportQualifiedPost" ];
};
};
}
61 changes: 61 additions & 0 deletions nix/modules/haskell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{ inputs, ... }:
{
imports = [
inputs.haskell-flake.flakeModule
];
perSystem = { self', lib, config, pkgs, ... }: {
# Our only Haskell project. You can have multiple projects, but this template
# has only one.
# See https://github.com/srid/haskell-flake/blob/master/example/flake.nix
haskellProjects.default = {
# To avoid unnecessary rebuilds, we filter projectRoot:
# https://community.flake.parts/haskell-flake/local#rebuild
projectRoot = builtins.toString (lib.fileset.toSource {
root = ../..;
fileset = lib.fileset.unions [
../../src
../../haskell-template.cabal
../../LICENSE
../../README.md
];
});

# The base package set (this value is the default)
# basePackages = pkgs.haskellPackages;

# Packages to add on top of `basePackages`
packages = {
# Add source or Hackage overrides here
# (Local packages are added automatically)
/*
aeson.source = "1.5.0.0" # Hackage version
shower.source = inputs.shower; # Flake input
*/
};

# Add your package overrides here
settings = {
/*
haskell-template = {
haddock = false;
};
aeson = {
check = false;
};
*/
};

# Development shell configuration
devShell = {
hlsCheck.enable = false;
};

# What should haskell-flake add to flake outputs?
autoWire = [ "packages" "apps" "checks" ]; # Wire all but the devShell
};

# Default package & app.
packages.default = self'.packages.haskell-template;
apps.default = self'.apps.haskell-template;
};
}
12 changes: 12 additions & 0 deletions nix/modules/template.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ inputs, ... }:

{
imports = [
inputs.treefmt-nix.flakeModule
inputs.fourmolu-nix.flakeModule
];
flake.templates.default = {
description = "A batteries-included Haskell project template for Nix";
path = builtins.path { path = inputs.self; };
};
}

0 comments on commit 60c8b39

Please sign in to comment.