M .github/workflows/build.yaml => .github/workflows/build.yaml +5 -1
@@ 4,6 4,10 @@ on:
push:
jobs:
build:
+ strategy:
+ matrix:
+ use_hpack: ["no", "yes"]
+ add_executable_section: ["no", "yes"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@@ 12,4 16,4 @@ jobs:
with:
name: hs-nix-template
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- - run: nix-build ci.nix
+ - run: nix-build ci.nix --argstr use_hpack "${{ matrix.use_hpack }}" --argstr add_executable_section "${{ matrix.add_executable_section }}"
M ci.nix => ci.nix +9 -14
@@ 1,30 1,25 @@
+{
+ use_hpack ? "no",
+ add_executable_section ? "no"
+}:
+
let
sources = import (./. + "/{{cookiecutter.project_name}}/nix/sources.nix");
pkgs = import sources.nixpkgs {};
in
rec {
-
generated = pkgs.runCommand "hs-nix-template" {
buildInputs = [ pkgs.cookiecutter ];
preferLocalBuild = true;
} ''
HOME="$(mktemp -d)"
mkdir "$out"
- cookiecutter --no-input --output-dir "$out" ${./.}
+ cookiecutter \
+ --no-input --output-dir "$out" ${./.} \
+ use_hpack="${use_hpack}" \
+ add_executable_section="${add_executable_section}"
'';
build = pkgs.recurseIntoAttrs
(import "${generated}/your-project-name" {});
-
- generatedWithHpack = pkgs.runCommand "hs-nix-template" {
- buildInputs = [ pkgs.cookiecutter ];
- preferLocalBuild = true;
- } ''
- HOME="$(mktemp -d)"
- mkdir "$out"
- cookiecutter --no-input --output-dir "$out" ${./.} project_configuration_tool="package.yaml (hpack)"
- '';
-
- buildWithHpack = pkgs.recurseIntoAttrs
- (import "${generatedWithHpack}/your-project-name" {});
}
M cookiecutter.json => cookiecutter.json +2 -1
@@ 5,5 5,6 @@
"module": "{{cookiecutter.project_name|title|replace('-', '')}}",
"author_name": "Your Name",
"gh_user": "your_github_username",
- "project_configuration_tool": ["{{cookiecutter.project_name|replace('-', '')}}.cabal (cabal's default)", "package.yaml (hpack)"]
+ "use_hpack": ["no", "yes"],
+ "add_executable_section": ["no", "yes"]
}
M hooks/post_gen_project.py => hooks/post_gen_project.py +4 -2
@@ 2,8 2,10 @@ import os
import sys
REMOVE_PATHS = [
- '{% if cookiecutter.project_configuration_tool.startswith("package.yaml") %} {{ cookiecutter.project_name }}.cabal {% endif %}',
- '{% if not cookiecutter.project_configuration_tool.startswith("package.yaml") %} package.yaml {% endif %}',
+ '{% if cookiecutter.use_hpack == "yes" %} {{ cookiecutter.project_name }}.cabal {% endif %}',
+ '{% if cookiecutter.use_hpack == "no" %} package.yaml {% endif %}',
+ '{% if cookiecutter.add_executable_section == "no" %} app/Main.hs {% endif %}',
+ '{% if cookiecutter.add_executable_section == "no" %} app {% endif %}',
]
for path in REMOVE_PATHS:
M {{cookiecutter.project_name}}/default.nix => {{cookiecutter.project_name}}/default.nix +5 -3
@@ 26,25 26,27 @@ let
pkgs.haskellPackages.ghcid
pkgs.haskellPackages.ormolu
pkgs.haskellPackages.hlint
- {% if cookiecutter.project_configuration_tool.startswith("package.yaml") %}pkgs.haskellPackages.hpack
+ {% if cookiecutter.use_hpack == "yes" %}pkgs.haskellPackages.hpack
{% endif -%}
pkgs.niv
pkgs.nixpkgs-fmt
];
withHoogle = true;
};
-
+{% 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}}" ];
};
+{% endif -%}
in
{
inherit shell;
- inherit exe;
+ {% if cookiecutter.add_executable_section == "yes" %}inherit exe;
inherit docker;
+ {% endif -%}
inherit myHaskellPackages;
"{{cookiecutter.project_name}}" = myHaskellPackages."{{cookiecutter.project_name}}";
}
M {{cookiecutter.project_name}}/package.yaml => {{cookiecutter.project_name}}/package.yaml +2 -1
@@ 13,13 13,14 @@ dependencies:
library:
source-dirs: src
-executables:
+{% if cookiecutter.add_executable_section == "yes" %}executables:
{{cookiecutter.project_name}}-exe:
source-dirs: app
main: Main.hs
dependencies:
- {{cookiecutter.project_name}}
+{% endif -%}
tests:
{{cookiecutter.project_name}}-test:
source-dirs: test
M {{cookiecutter.project_name}}/{{cookiecutter.project_name}}.cabal => {{cookiecutter.project_name}}/{{cookiecutter.project_name}}.cabal +2 -1
@@ 18,7 18,7 @@ library
ghc-options: -Wall -fno-warn-name-shadowing
build-depends: base >= 4.11 && < 5
-executable {{cookiecutter.project_name}}
+{% if cookiecutter.add_executable_section == "yes" %}executable {{cookiecutter.project_name}}
main-is: Main.hs
hs-source-dirs: app
default-language: Haskell2010
@@ 26,6 26,7 @@ executable {{cookiecutter.project_name}}
build-depends: base
, {{cookiecutter.project_name}}
+{% endif -%}
test-suite {{cookiecutter.project_name}}-tests
type: exitcode-stdio-1.0
hs-source-dirs: test