diff --git a/.gitignore b/.gitignore index c5edab1..7a6353d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ .envrc -.direnv/ diff --git a/flake.lock b/flake.lock index 3ea27c6..42b5046 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1755577059, - "narHash": "sha256-5hYhxIpco8xR+IpP3uU56+4+Bw7mf7EMyxS/HqUYHQY=", + "lastModified": 1783279667, + "narHash": "sha256-/NAkDSsve+GNM0Bt6tleJdCGfsTlK89nPjkVOzZMo0s=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "97eb7ee0da337d385ab015a23e15022c865be75c", + "rev": "f205b5574fd0cb7da5b702a2da51507b7f4fdd1b", "type": "github" }, "original": { @@ -18,7 +18,28 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1780220602, + "narHash": "sha256-eynAfOmbmxJnkp7YewvCEbShNnnYJ9gLLqkzsYtBPeM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "db947814a175b7ca6ded66e21383d938df01c227", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 24210ba..8e095e0 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,18 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = {nixpkgs, ...} @ inputs: let + outputs = { + self, + nixpkgs, + treefmt-nix, + ... + }: let lib = nixpkgs.lib; supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; forEachSupportedSystem = f: @@ -11,27 +20,27 @@ f { pkgs = import nixpkgs {inherit system;}; }); + treefmtEval = forEachSupportedSystem ({pkgs, ...}: treefmt-nix.lib.evalModule pkgs ./treefmt.nix); in { - devShells = forEachSupportedSystem ({pkgs}: { + devShells = forEachSupportedSystem ({pkgs, ...}: { default = pkgs.mkShell { packages = with pkgs; [ gleam - erlang_28 - beam28Packages.rebar3 - jq + beamMinimal29Packages.erlang + beamMinimal29Packages.rebar3 ]; }; }); - apps = forEachSupportedSystem ({pkgs}: let + + apps = forEachSupportedSystem ({pkgs, ...}: let cdInto = service: '' rootDir=$(jj --ignore-working-copy root || git rev-parse --show-toplevel) || (echo "error: can't find repo root?"; exit 1) cd "$rootDir/${service}" ''; - # TODO: dedup depencency decl. runtimeInputs = with pkgs; [ gleam - erlang_28 - beam28Packages.rebar3 + beamMinimal29Packages.erlang + beamMinimal29Packages.rebar3 ]; in { # TODO: Check if env vars are already set @@ -61,31 +70,12 @@ ''; })}/bin/run-web"; }; - test-api = { - type = "app"; - program = "${(pkgs.writeShellApplication { - inherit runtimeInputs; - name = "test-api"; - text = '' - ${cdInto "api"} - export KATARI_SRD_PATH="$rootDir/srd" - ${pkgs.gleam}/bin/gleam test - ''; - })}/bin/test-api"; - }; - test-web = { - type = "app"; - program = "${(pkgs.writeShellApplication { - inherit runtimeInputs; - name = "test-web"; - text = '' - ${cdInto "web"} - export KATARI_SRD_PATH="$rootDir/srd" - export KATARI_API_DOCS=true - ${pkgs.gleam}/bin/gleam test - ''; - })}/bin/test-web"; - }; + }); + + formatter = forEachSupportedSystem ({pkgs, ...}: treefmtEval.${pkgs.stdenv.hostPlatform.system}.config.build.wrapper); + checks = forEachSupportedSystem ({pkgs, ...}: { + formatting = + treefmtEval.${pkgs.stdenv.hostPlatform.system}.config.build.check self; }); }; } diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..15a8d59 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,5 @@ +{pkgs, ...}: { + projectRootFile = "flake.nix"; + programs.gleam.enable = true; + programs.alejandra.enable = true; +}