diff --git a/.copier-answers.yml.jinja b/.copier-answers.yml.jinja new file mode 100644 index 0000000..69141bb --- /dev/null +++ b/.copier-answers.yml.jinja @@ -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..8f84320 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,32 @@ 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: Install copier + run: nix profile install nixpkgs#copier + + - name: Test template initialization with copier + run: | + # Initialize template with sample variables + 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 + test -f test-project.cabal # Verify cabal file has templated name + + # 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..07fe784 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,12 @@ result-* .direnv /.pre-commit-config.yaml + +# LLM +/.claude/settings.local.json + +# Template working files (originals are in .jinja files) +LICENSE +haskell-template.cabal +src/Main.hs +nix/modules/flake/haskell.nix diff --git a/LICENSE b/LICENSE.jinja similarity index 95% rename from LICENSE rename to LICENSE.jinja index 852e58e..96e06b3 100644 --- a/LICENSE +++ b/LICENSE.jinja @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Sridhar Ratnakumar +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/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..6315e47 --- /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__ + +# Use .jinja suffix for templates +_templates_suffix: .jinja 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 }}; }; } 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.jinja similarity index 85% rename from src/Main.hs rename to src/Main.hs.jinja index d8b3d4f..0b38397 100644 --- a/src/Main.hs +++ b/src/Main.hs.jinja @@ -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 }})" diff --git a/haskell-template.cabal b/{{ package_name }}.cabal.jinja similarity index 85% rename from haskell-template.cabal rename to {{ package_name }}.cabal.jinja index 01363dd..502fe3f 100644 --- a/haskell-template.cabal +++ b/{{ package_name }}.cabal.jinja @@ -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: {{ '%Y' | strftime }} {{ 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