From 74b681d66552e24248a3c36524c932c4c796f985 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 7 Apr 2025 10:29:36 -0500 Subject: [PATCH] flake.nix: nixfmt -> treefmt Instead of managing our own formatter file, we can leverage a tool specifically tailored for formatting a repository and allowing configuration to be passed to formatters. --- flake.lock | 23 ++++++++++++++++++++++- flake.nix | 27 +++++++++++++++++++-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 7cfad76cd..942b67b62 100644 --- a/flake.lock +++ b/flake.lock @@ -18,7 +18,28 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1743748085, + "narHash": "sha256-uhjnlaVTWo5iD3LXics1rp9gaKgDRQj6660+gbUU3cE=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "815e4121d6a5d504c0f96e5be2dd7f871e4fd99d", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 96843fec5..29175de5e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,16 @@ { description = "Home Manager for Nix"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - outputs = { self, nixpkgs, ... }: + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, treefmt-nix, ... }: { nixosModules = rec { home-manager = ./nixos; @@ -39,13 +46,17 @@ lib = import ./lib { inherit (nixpkgs) lib; }; } // (let forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; + + treefmtEval = forAllSystems ( + system: + treefmt-nix.lib.evalModule nixpkgs.legacyPackages.${system} { + # Formatting configuration + programs = { + nixfmt.enable = true; + }; + }); in { - formatter = forAllSystems (system: - let pkgs = nixpkgs.legacyPackages.${system}; - in pkgs.linkFarm "format" [{ - name = "bin/format"; - path = ./format; - }]); + formatter = forAllSystems (system: treefmtEval.${system}.config.build.wrapper); packages = forAllSystems (system: let