From f2ea15fa7caf37357d517ceb1d2ae5014d917843 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Mon, 23 Dec 2024 19:21:49 -0600 Subject: [PATCH] Elixir --- templates/elixir/.gitignore | 3 +++ templates/elixir/nix/checks.nix | 22 +++++++++++++++++----- templates/elixir/nix/packages.nix | 1 + templates/elixir/nix/shells.nix | 9 +++++++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/templates/elixir/.gitignore b/templates/elixir/.gitignore index 8cf7b60..4b64fa1 100644 --- a/templates/elixir/.gitignore +++ b/templates/elixir/.gitignore @@ -20,3 +20,6 @@ erl_crash.dump # direnv cache /.direnv + +# nix-generated pre commit hooks +.pre-commit-config.yaml diff --git a/templates/elixir/nix/checks.nix b/templates/elixir/nix/checks.nix index d6e6f79..c88dd7d 100644 --- a/templates/elixir/nix/checks.nix +++ b/templates/elixir/nix/checks.nix @@ -2,16 +2,28 @@ git-hooks, pkgs, ... -}: { +}: let + hook = { + command, + stages ? ["pre-commit"], + ... + }: { + inherit stages; + enable = true; + name = command; + entry = command; + pass_filenames = false; + }; +in { git-hooks = git-hooks.lib.${pkgs.system}.run { src = ./..; hooks = { alejandra.enable = true; convco.enable = true; - credo.enable = true; - dialyzer.enable = true; - mix-format.enable = true; - mix-test.enable = true; + credo = hook {command = "mix credo --strict";}; + formatting = hook {command = "mix format --check-formatted";}; + dialyzer = hook {command = "mix dialyzer";}; + test = hook {command = "mix test";}; }; }; } diff --git a/templates/elixir/nix/packages.nix b/templates/elixir/nix/packages.nix index ed886a4..3be71ed 100644 --- a/templates/elixir/nix/packages.nix +++ b/templates/elixir/nix/packages.nix @@ -14,6 +14,7 @@ in { pname = "mix-deps-${pname}"; sha256 = pkgs.lib.fakeSha256; }; + LANG = "C.UTF-8"; # buildInputs = with pkgs; []; # HOME = "$(pwd)"; # MIX_XDG = "$HOME"; diff --git a/templates/elixir/nix/shells.nix b/templates/elixir/nix/shells.nix index 7a7512a..91dcd91 100644 --- a/templates/elixir/nix/shells.nix +++ b/templates/elixir/nix/shells.nix @@ -1,15 +1,20 @@ { pkgs, - # self, + self, ... }: { elixir-dev = pkgs.mkShell { - shellHook = "export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive"; + shellHook = '' + ${self.checks.${pkgs.system}.git-hooks.shellHook} + export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive + ''; # inputsFrom = [self.packages.${pkgs.system}.my-package]; buildInputs = with pkgs; [ elixir elixir-ls inotify-tools ]; + MIX_ENV = "dev"; }; + default = self.outputs.devShells.${pkgs.system}.elixir-dev; }