From f1a3f0303b1fed8358026fbee4c71bdf61aa0f39 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 6 Feb 2025 20:08:13 +0100 Subject: [PATCH] feat: switch to flake-parts --- flake.lock | 47 ++++++++++----------- flake.nix | 117 ++++++++++++++++++++++++++++------------------------- 2 files changed, 83 insertions(+), 81 deletions(-) diff --git a/flake.lock b/flake.lock index c57b69c..cc6aa27 100644 --- a/flake.lock +++ b/flake.lock @@ -36,21 +36,21 @@ "type": "github" } }, - "flake-utils": { + "flake-parts": { "inputs": { - "systems": "systems" + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "lastModified": 1738453229, + "narHash": "sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm+zmZ7vxbJdo=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "32ea77a06711b758da0ad9bd6a844c5740a87abd", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, @@ -104,6 +104,18 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1738452942, + "narHash": "sha256-vJzFZGaCpnmo7I6i416HaBLpC+hvcURh/BQwROcGIp8=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat", @@ -129,26 +141,11 @@ "root": { "inputs": { "devshell": "devshell", - "flake-utils": "flake-utils", + "flake-parts": "flake-parts", "lib-net": "lib-net", "nixpkgs": "nixpkgs", "pre-commit-hooks": "pre-commit-hooks" } - }, - "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 5872d4d..378a562 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,7 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - flake-utils.url = "github:numtide/flake-utils"; + flake-parts.url = "github:hercules-ci/flake-parts"; lib-net = { url = "https://gist.github.com/duairc/5c9bb3c922e5d501a1edb9e7b3b845ba/archive/3885f7cd9ed0a746a9d675da6f265d41e9fd6704.tar.gz"; @@ -22,63 +22,68 @@ }; }; - outputs = { - self, - nixpkgs, - flake-utils, - devshell, - pre-commit-hooks, - ... - } @ inputs: - { - nixosModules.nixos-extra-modules = import ./modules; - nixosModules.default = self.nixosModules.nixos-extra-modules; - homeManagerModules.nixos-extra-modules = import ./hm-modules; - homeManagerModules.default = self.homeManagerModules.nixos-extra-modules; - overlays.nixos-extra-modules = import ./overlay.nix inputs; - overlays.default = self.overlays.nixos-extra-modules; - } - // flake-utils.lib.eachDefaultSystem (system: rec { - pkgs = import nixpkgs { - inherit system; - overlays = [ - devshell.overlays.default - self.overlays.default - ]; - }; + outputs = + { self, ... }@inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.devshell.flakeModule + inputs.pre-commit-hooks.flakeModule + ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; - # `nix flake check` - checks.pre-commit-hooks = pre-commit-hooks.lib.${system}.run { - src = nixpkgs.lib.cleanSource ./.; - hooks = { - alejandra.enable = true; - deadnix.enable = true; - statix.enable = true; + flake.modules = { + nixos = { + nixos-extra-modules = import ./modules; + default = self.modules.nixos.nixos-extra-modules; + }; + home-manager = { + nixos-extra-modules = import ./hm-modules; + default = self.modules.home-manager.nixos-extra-modules; }; }; - - # `nix fmt` - formatter = pkgs.alejandra; - - # `nix develop` - devShells.default = pkgs.devshell.mkShell { - name = "nixos-extra-modules"; - commands = with pkgs; [ - { - package = alejandra; - help = "Format nix code"; - } - { - package = statix; - help = "Lint nix code"; - } - { - package = deadnix; - help = "Find unused expressions in nix code"; - } - ]; - - devshell.startup.pre-commit.text = self.checks.${system}.pre-commit-hooks.shellHook; + flake.overlays = { + nixos-extra-modules = import ./overlay.nix inputs; + default = self.overlays.nixos-extra-modules; }; - }); + + perSystem = + { + pkgs, + system, + config, + ... + }: + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ + self.overlays.default + ]; + }; + # `nix flake check` + pre-commit.settings.hooks = { + nixfmt-rfc-style.enable = true; + deadnix.enable = true; + statix.enable = true; + }; + formatter = pkgs.nixfmt-rfc-style; + devshells.default = { + commands = with pkgs; [ + { + package = statix; + help = "Lint nix code"; + } + { + package = deadnix; + help = "Find unused expressions in nix code"; + } + ]; + devshell.startup.pre-commit.text = config.pre-commit.installationScript; + }; + }; + }; }