From de8ccbdc89a9a344a5821b252f66fb3cb1c9ec39 Mon Sep 17 00:00:00 2001 From: toastal Date: Wed, 15 May 2024 23:10:16 +0700 Subject: [PATCH 1/2] flake: remove flake-utils dependency --- flake.lock | 34 ---------------------------------- flake.nix | 39 ++++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 53 deletions(-) diff --git a/flake.lock b/flake.lock index b15f9485..eb6da9a3 100644 --- a/flake.lock +++ b/flake.lock @@ -16,24 +16,6 @@ "type": "github" } }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "gitignore": { "inputs": { "nixpkgs": [ @@ -89,26 +71,10 @@ "root": { "inputs": { "flake-compat": "flake-compat", - "flake-utils": "flake-utils", "gitignore": "gitignore", "nixpkgs": "nixpkgs", "nixpkgs-stable": "nixpkgs-stable" } - }, - "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 c937ea24..220277dc 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,6 @@ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-23.11"; - inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-compat = { url = "github:edolstra/flake-compat"; flake = false; @@ -13,7 +12,7 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, flake-utils, gitignore, nixpkgs-stable, ... }: + outputs = { self, nixpkgs, gitignore, nixpkgs-stable, ... }: let lib = nixpkgs.lib; defaultSystems = [ @@ -22,6 +21,12 @@ "x86_64-darwin" "x86_64-linux" ]; + depsFor = lib.genAttrs defaultSystems (system: { + pkgs = nixpkgs.legacyPackages.${system}; + exposed = import ./nix { inherit nixpkgs system; gitignore-nix-src = gitignore; isFlakes = true; }; + exposed-stable = import ./nix { nixpkgs = nixpkgs-stable; inherit system; gitignore-nix-src = gitignore; isFlakes = true; }; + }); + forAllSystems = fn: lib.genAttrs defaultSystems (system: fn depsFor.${system}); in { flakeModule = ./flake-module.nix; @@ -32,27 +37,23 @@ A template with flake-parts and nixpkgs-fmt. ''; }; - } - // flake-utils.lib.eachSystem defaultSystems (system: - let - exposed = import ./nix { inherit nixpkgs system; gitignore-nix-src = gitignore; isFlakes = true; }; - exposed-stable = import ./nix { nixpkgs = nixpkgs-stable; inherit system; gitignore-nix-src = gitignore; isFlakes = true; }; - in - { - packages = exposed.packages // { - default = exposed.packages.pre-commit; - }; - devShells.default = nixpkgs.legacyPackages.${system}.mkShell { + packages = forAllSystems ({ exposed, ... }: exposed.packages // { + default = exposed.packages.pre-commit; + }); + + devShells = forAllSystems ({ pkgs, exposed, ... }: { + default = pkgs.mkShellNoCC { inherit (exposed.checks.pre-commit-check) shellHook; }; + }); - checks = lib.filterAttrs (k: v: v != null) + checks = forAllSystems ({ exposed, exposed-stable, ... }: + lib.filterAttrs (k: v: v != null) (exposed.checks - // (lib.mapAttrs' (name: value: lib.nameValuePair "stable-${name}" value) - exposed-stable.checks)); + // (lib.mapAttrs' (name: value: lib.nameValuePair "stable-${name}" value) + exposed-stable.checks))); - lib = { inherit (exposed) run; }; - } - ); + lib = forAllSystems ({ exposed, ... }: { inherit (exposed) run; }); + }; } From 8803a39afa8b3bfc88b7e3646a07450b57f4e27a Mon Sep 17 00:00:00 2001 From: toastal Date: Wed, 15 May 2024 23:11:29 +0700 Subject: [PATCH 2/2] readme: remove flake-utils reference --- README.md | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e4b66200..8c48c5c9 100644 --- a/README.md +++ b/README.md @@ -29,25 +29,30 @@ Given the following `flake.nix` example: description = "An example project."; inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; - inputs.flake-utils.url = "github:numtide/flake-utils"; - - outputs = { self, nixpkgs, pre-commit-hooks, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - { - checks = { - pre-commit-check = pre-commit-hooks.lib.${system}.run { - src = ./.; - hooks = { - nixpkgs-fmt.enable = true; - }; + + outputs = { self, nixpkgs, ... }@inputs: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + in + { + checks = forAllSystems (system: { + pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixpkgs-fmt.enable = true; }; }; - devShell = nixpkgs.legacyPackages.${system}.mkShell { + }); + + devShells = forAllSystems (system: { + default = nixpkgs.legacyPackages.${system}.mkShell { inherit (self.checks.${system}.pre-commit-check) shellHook; buildInputs = self.checks.${system}.pre-commit-check.enabledPackages; }; - } - ); + }); + }; } ```