From 2559f5ff0df4742d017fd5501debc47c848eac6f Mon Sep 17 00:00:00 2001 From: ditsuke Date: Fri, 23 Feb 2024 22:13:48 +0530 Subject: [PATCH] build(nix): Introduce flake.formatter for `nix fmt` --- flake.lock | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 9 ++++++ 2 files changed, 99 insertions(+) diff --git a/flake.lock b/flake.lock index 47d6448b5..84ed2b9d9 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -18,6 +34,48 @@ "type": "github" } }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixfmt": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1707402853, + "narHash": "sha256-d7a6xfqhbyLikHultxjHO33SqUcif/8eGyxhRZ9PvZk=", + "owner": "piegamesde", + "repo": "nixfmt", + "rev": "ca1fe3572ea6134551ee6af40ae735a1a1ed0d35", + "type": "github" + }, + "original": { + "owner": "piegamesde", + "ref": "rfc101-style", + "repo": "nixfmt", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1708118438, @@ -52,11 +110,43 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1696039360, + "narHash": "sha256-g7nIUV4uq1TOVeVIDEZLb005suTWCUjSY0zYOlSBsyE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "32dcb45f66c0487e92db8303a798ebc548cadedc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flake-parts": "flake-parts", + "nixfmt": "nixfmt", "nixpkgs": "nixpkgs" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index dc4e503c3..fd4bdddfc 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,10 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; + nixfmt = { + url = "github:piegamesde/nixfmt/rfc101-style"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; # There's an optional binary cache available. The details are below, but they're commented out. @@ -131,6 +135,11 @@ ... }: { + # For standardised reproducible formatting with `nix fmt` + # HELP: why does the per system formatter not work? + # formatter = inputs.nixfmt.packages.${system}.nixfmt; + formatter = if (system == "x86_64-linux") then inputs.nixfmt.packages.${system}.nixfmt else null; + # Unlike `.#packages`, legacyPackages may contain values of # arbitrary types (including nested attrsets) and may even throw # exceptions. This attribute isn't recursed into by `nix flake