~kaction/cookiecutter-haskell

56b8d2c5ff4161fb463918c9b1d4949080dd6291 — Dmitry Bogatov 1 year, 5 months ago 2e1f1ac
Configure treefmt(1) to reformat Nix files with alejandra(1)

Not that I like style of alejandra(1) or I like its advertisements,
but it seems to be best-maintained reformatter around.
2 files changed, 22 insertions(+), 17 deletions(-)

M {{cookiecutter.project_name}}/default.nix
M {{cookiecutter.project_name}}/treefmt.toml
M {{cookiecutter.project_name}}/default.nix => {{cookiecutter.project_name}}/default.nix +17 -17
@@ 1,19 1,18 @@
{ compiler ? "ghc921" }:

let
{compiler ? "ghc921"}: let
  sources = import ./nix/sources.nix;
  pkgs = import sources.nixpkgs {};

  gitignore = pkgs.nix-gitignore.gitignoreSourcePure [ ./.gitignore ];
  gitignore = pkgs.nix-gitignore.gitignoreSourcePure [./.gitignore];

  myHaskellPackages = pkgs.haskell.packages.${compiler}.override {
    overrides = hself: hsuper: {
      "{{cookiecutter.project_name}}" =
          let this = hself.callCabal2nix "{{cookiecutter.project_name}}" (gitignore ./.) {};
          in this.overrideAttrs (old: {
            postPatch = "treefmt --fail-on-change";
            nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.treefmt pkgs.haskellPackages.ormolu ];
          });
      "{{cookiecutter.project_name}}" = let
        this = hself.callCabal2nix "{{cookiecutter.project_name}}" (gitignore ./.) {};
      in
        this.overrideAttrs (old: {
          postPatch = "treefmt --fail-on-change";
          nativeBuildInputs = old.nativeBuildInputs ++ [pkgs.treefmt pkgs.alejandra pkgs.haskellPackages.ormolu];
        });
    };
  };



@@ 29,21 28,22 @@ let
      pkgs.haskellPackages.hlint
      pkgs.niv
      pkgs.nixpkgs-fmt
      pkgs.treefmt
      pkgs.alejandra
    ];
    withHoogle = true;
  };
{% if cookiecutter.add_executable_section == "yes" %}
  {%- if cookiecutter.add_executable_section == "yes" %}
  exe = pkgs.haskell.lib.justStaticExecutables (myHaskellPackages."{{cookiecutter.project_name}}");

  docker = pkgs.dockerTools.buildImage {
    name = "{{cookiecutter.project_name}}";
    config.Cmd = [ "${exe}/bin/{{cookiecutter.project_name}}" ];
    config.Cmd = ["${exe}/bin/{{cookiecutter.project_name}}"];
  };
{% endif -%}
in
{
  {%- endif %}
in {
  inherit shell;
  {% if cookiecutter.add_executable_section == "yes" %}inherit exe;
  {% if cookiecutter.add_executable_section == "yes" %}
  inherit exe;
  inherit docker;
  {% endif -%}
  inherit myHaskellPackages;

M {{cookiecutter.project_name}}/treefmt.toml => {{cookiecutter.project_name}}/treefmt.toml +5 -0
@@ 3,3 3,8 @@ command = "ormolu"
options = ["-i"]
includes = [ "*.hs" ]
excludes = []
[formatter.nix]
command = "alejandra"
options = []
includes = [ "*.nix" ]
excludes = [ "nix/sources.nix" ]