From 52ff4d773a016545776423613e43582066a274cf Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 29 Oct 2025 12:17:17 -0400 Subject: [PATCH 1/5] wip --- .copier-answers.yml | 2 ++ .github/workflows/ci.yaml | 31 ++++++++++++---- .gitignore | 3 ++ LICENSE | 2 +- README.md | 3 +- copier.yml | 42 ++++++++++++++++++++++ haskell-template.cabal | 10 +++--- nix/modules/flake/template.nix | 66 ---------------------------------- src/Main.hs | 2 +- 9 files changed, 79 insertions(+), 82 deletions(-) create mode 100644 .copier-answers.yml create mode 100644 copier.yml delete mode 100644 nix/modules/flake/template.nix diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 0000000..69141bb --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,2 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +{{ _copier_answers|to_nice_yaml -}} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c1ba870..7e31cea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,7 +6,7 @@ on: - master pull_request: jobs: - build: + template-test: runs-on: ${{ matrix.os }} strategy: matrix: @@ -14,11 +14,28 @@ jobs: steps: - uses: actions/checkout@v4 - uses: nixbuild/nix-quick-install-action@v33 - - name: Install omnix - run: | - nix --accept-flake-config profile install "github:juspay/omnix" - nix --version - - name: Build all flake outputs - run: om ci + + - name: Test template initialization with copier + run: | + # Initialize template with sample variables + nix run nixpkgs#copier -- copy --defaults \ + --data author="Test Author" \ + --data package_name="test-project" \ + --data vscode=false \ + --data github_ci=false \ + . ../test-project + + cd ../test-project + + # Verify templating worked + grep "Test Author" LICENSE + grep "test-project" test-project.cabal + + # Build the project + nix build + + # Run the executable + ./result/bin/test-project + - name: What GHC version? run: nix develop -c ghc --version diff --git a/.gitignore b/.gitignore index 76646ea..623119e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ result-* .direnv /.pre-commit-config.yaml + +# LLM +/.claude/settings.local.json diff --git a/LICENSE b/LICENSE index 852e58e..53e2b09 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Sridhar Ratnakumar +Copyright (c) {{ now().year }} {{ author }} Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bccc1eb..6bf007b 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,7 @@ If you have an *existing* Haskell project, you should probably use https://githu Initialize this template using: ```sh -nix run nixpkgs#omnix -- \ - init github:srid/haskell-template -o ./yourproject +nix run nixpkgs#copier -- copy gh:srid/haskell-template ./yourproject ``` *tldr: [Install Nix](https://nixos.asia/en/install), [setup direnv](https://nixos.asia/en/direnv), open in VSCode, install recommended extensions and run `just run`.* diff --git a/copier.yml b/copier.yml new file mode 100644 index 0000000..5a7f035 --- /dev/null +++ b/copier.yml @@ -0,0 +1,42 @@ +# Copier template configuration for haskell-template +# https://copier.readthedocs.io/ + +_min_copier_version: "9.0.0" + +# Answers file location +_answers_file: .copier-answers.yml + +# Template questions +author: + type: str + help: Author name + default: Sridhar Ratnakumar + placeholder: "{{ author }}" + +package_name: + type: str + help: Name of the Haskell package + default: haskell-template + placeholder: "{{ package_name }}" + +vscode: + type: bool + help: Include the VSCode settings folder (./.vscode)? + default: true + +github_ci: + type: bool + help: Include GitHub Actions workflow configuration (./.github)? + default: true + +# Exclude patterns based on user choices +_exclude: + - "{% if not vscode %}.vscode{% endif %}" + - "{% if not github_ci %}.github{% endif %}" + - .git + - .copier-answers.yml + - "*.pyc" + - __pycache__ + +# Template without suffix - all files with Jinja syntax will be templated +_templates_suffix: "" diff --git a/haskell-template.cabal b/haskell-template.cabal index 01363dd..61df256 100644 --- a/haskell-template.cabal +++ b/haskell-template.cabal @@ -1,12 +1,12 @@ cabal-version: 2.4 -name: haskell-template +name: {{ package_name }} version: 0.1.0.0 license: MIT -copyright: 2022 Sridhar Ratnakumar +copyright: {{ now().year }} {{ author }} maintainer: srid@srid.ca -author: Sridhar Ratnakumar +author: {{ author }} category: Web -homepage: https://srid.ca/haskell-template +homepage: https://github.com/srid/haskell-template -- TODO: Before hackage release. -- A short (one-line) description of the package. @@ -63,6 +63,6 @@ common shared hs-source-dirs: src default-language: GHC2021 -executable haskell-template +executable {{ package_name }} import: shared main-is: Main.hs diff --git a/nix/modules/flake/template.nix b/nix/modules/flake/template.nix deleted file mode 100644 index 2e7d1e3..0000000 --- a/nix/modules/flake/template.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ inputs, ... }: - -{ - flake = rec { - templates.default = { - description = "A batteries-included Haskell project template for Nix"; - path = builtins.path { path = inputs.self; }; - welcomeText = '' - Please see https://srid.ca/haskell-template/start - ''; - }; - - # https://omnix.page/om/init.html#spec - om.templates.haskell-template = { - template = templates.default; - params = [ - { - name = "author"; - description = "Author name"; - placeholder = "Sridhar Ratnakumar"; - } - { - name = "package-name"; - description = "Name of the Haskell package"; - placeholder = "haskell-template"; - } - { - name = "vscode"; - description = "Include the VSCode settings folder (./.vscode)"; - paths = [ ".vscode" ]; - value = true; - } - { - name = "github-ci"; - description = "Include GitHub Actions workflow configuration"; - paths = [ ".github" ]; - value = true; - } - { - name = "nix-template"; - description = "Keep the flake template in the project"; - paths = [ "**/template.nix" ]; - value = false; - } - ]; - tests = { - default = { - params = { - package-name = "foo"; - author = "John"; - vscode = false; - }; - asserts = { - source = { - ".github/workflows/ci.yaml" = true; - ".vscode" = false; - }; - packages.default = { - "bin/foo" = true; - }; - }; - }; - }; - }; - }; -} diff --git a/src/Main.hs b/src/Main.hs index d8b3d4f..0b38397 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -17,4 +17,4 @@ main :: IO () main = do -- For withUtf8, see https://serokell.io/blog/haskell-with-utf8 Utf8.withUtf8 $ do - putTextLn "Hello 🌎 (from haskell-template)" + putTextLn "Hello 🌎 (from {{ package_name }})" From 0cb2fb7fade6a0c42247b5d8e59d15b774de6d31 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 29 Oct 2025 12:18:42 -0400 Subject: [PATCH 2/5] install copier --- .github/workflows/ci.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7e31cea..22a38e3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,10 +15,13 @@ jobs: - uses: actions/checkout@v4 - uses: nixbuild/nix-quick-install-action@v33 + - name: Install copier + run: nix profile install nixpkgs#copier + - name: Test template initialization with copier run: | # Initialize template with sample variables - nix run nixpkgs#copier -- copy --defaults \ + copier copy --defaults \ --data author="Test Author" \ --data package_name="test-project" \ --data vscode=false \ From 077185c2b3314e175b71500e7b893a14a82e5bf4 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 29 Oct 2025 12:21:17 -0400 Subject: [PATCH 3/5] fix? --- .github/workflows/ci.yaml | 1 + LICENSE | 2 +- haskell-template.cabal => {{ package_name }}.cabal | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename haskell-template.cabal => {{ package_name }}.cabal (96%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 22a38e3..0b4646c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,6 +33,7 @@ jobs: # Verify templating worked grep "Test Author" LICENSE grep "test-project" test-project.cabal + test -f test-project.cabal # Verify cabal file has correct name # Build the project nix build diff --git a/LICENSE b/LICENSE index 53e2b09..96e06b3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) {{ now().year }} {{ author }} +Copyright (c) {{ '%Y' | strftime }} {{ author }} Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/haskell-template.cabal b/{{ package_name }}.cabal similarity index 96% rename from haskell-template.cabal rename to {{ package_name }}.cabal index 61df256..502fe3f 100644 --- a/haskell-template.cabal +++ b/{{ package_name }}.cabal @@ -2,7 +2,7 @@ cabal-version: 2.4 name: {{ package_name }} version: 0.1.0.0 license: MIT -copyright: {{ now().year }} {{ author }} +copyright: {{ '%Y' | strftime }} {{ author }} maintainer: srid@srid.ca author: {{ author }} category: Web From fd77093220dd31c75c708c4148508ca490d67f25 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 29 Oct 2025 12:30:46 -0400 Subject: [PATCH 4/5] jj --- .copier-answers.yml => .copier-answers.yml.jinja | 0 .github/workflows/ci.yaml | 2 +- .gitignore | 5 +++++ LICENSE => LICENSE.jinja | 0 copier.yml | 4 ++-- src/{Main.hs => Main.hs.jinja} | 0 {{ package_name }}.cabal => {{ package_name }}.cabal.jinja | 0 7 files changed, 8 insertions(+), 3 deletions(-) rename .copier-answers.yml => .copier-answers.yml.jinja (100%) rename LICENSE => LICENSE.jinja (100%) rename src/{Main.hs => Main.hs.jinja} (100%) rename {{ package_name }}.cabal => {{ package_name }}.cabal.jinja (100%) diff --git a/.copier-answers.yml b/.copier-answers.yml.jinja similarity index 100% rename from .copier-answers.yml rename to .copier-answers.yml.jinja diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0b4646c..8f84320 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,7 +33,7 @@ jobs: # Verify templating worked grep "Test Author" LICENSE grep "test-project" test-project.cabal - test -f test-project.cabal # Verify cabal file has correct name + test -f test-project.cabal # Verify cabal file has templated name # Build the project nix build diff --git a/.gitignore b/.gitignore index 623119e..e77f395 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,8 @@ result-* # LLM /.claude/settings.local.json + +# Template working files (originals are in .jinja files) +LICENSE +haskell-template.cabal +src/Main.hs diff --git a/LICENSE b/LICENSE.jinja similarity index 100% rename from LICENSE rename to LICENSE.jinja diff --git a/copier.yml b/copier.yml index 5a7f035..6315e47 100644 --- a/copier.yml +++ b/copier.yml @@ -38,5 +38,5 @@ _exclude: - "*.pyc" - __pycache__ -# Template without suffix - all files with Jinja syntax will be templated -_templates_suffix: "" +# Use .jinja suffix for templates +_templates_suffix: .jinja diff --git a/src/Main.hs b/src/Main.hs.jinja similarity index 100% rename from src/Main.hs rename to src/Main.hs.jinja diff --git a/{{ package_name }}.cabal b/{{ package_name }}.cabal.jinja similarity index 100% rename from {{ package_name }}.cabal rename to {{ package_name }}.cabal.jinja From c44f6db837d849b6457c39ec35abf13164b3f036 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 29 Oct 2025 12:36:03 -0400 Subject: [PATCH 5/5] Template haskell.nix to fix package name references --- .gitignore | 1 + nix/modules/flake/{haskell.nix => haskell.nix.jinja} | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) rename nix/modules/flake/{haskell.nix => haskell.nix.jinja} (89%) diff --git a/.gitignore b/.gitignore index e77f395..07fe784 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ result-* LICENSE haskell-template.cabal src/Main.hs +nix/modules/flake/haskell.nix diff --git a/nix/modules/flake/haskell.nix b/nix/modules/flake/haskell.nix.jinja similarity index 89% rename from nix/modules/flake/haskell.nix rename to nix/modules/flake/haskell.nix.jinja index aa0cd57..9efa8d1 100644 --- a/nix/modules/flake/haskell.nix +++ b/nix/modules/flake/haskell.nix.jinja @@ -16,7 +16,7 @@ inherit root; fileset = lib.fileset.unions [ (root + /src) - (root + /haskell-template.cabal) + (root + /{{ package_name }}.cabal) (root + /LICENSE) (root + /README.md) ]; @@ -37,7 +37,7 @@ # Add your package overrides here settings = { - haskell-template = { + {{ package_name }} = { stan = true; # haddock = false; }; @@ -53,7 +53,7 @@ }; # Default package & app. - packages.default = self'.packages.haskell-template; - apps.default = self'.apps.haskell-template; + packages.default = self'.packages.{{ package_name }}; + apps.default = self'.apps.{{ package_name }}; }; }