From 583f2490597f748f83f512b27529ca1986a51d4f Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Mon, 2 Feb 2026 17:39:38 +0000 Subject: [PATCH] refactor(nix): migrate flake.nix to flake-parts - Replace manual forAllSystems pattern with flake-parts.lib.mkFlake - Use perSystem for packages and devShells definitions - Pin rust-overlay's nixpkgs to follow main nixpkgs input - No functional changes to package or dev shell --- flake.lock | 40 ++++++++++++++----- flake.nix | 114 +++++++++++++++++++++++------------------------------ 2 files changed, 80 insertions(+), 74 deletions(-) diff --git a/flake.lock b/flake.lock index ba98655..c1fcba2 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,23 @@ { "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1769996383, + "narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "57928607ea566b5db3ad13af0e57e921e6b12381", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1763283776, @@ -16,31 +34,33 @@ "type": "github" } }, - "nixpkgs_2": { + "nixpkgs-lib": { "locked": { - "lastModified": 1744536153, - "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "lastModified": 1769909678, + "narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "72716169fe93074c333e8d0173151350670b824c", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", + "owner": "nix-community", + "repo": "nixpkgs.lib", "type": "github" } }, "root": { "inputs": { + "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay" } }, "rust-overlay": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { "lastModified": 1763433504, diff --git a/flake.nix b/flake.nix index cb8d5a7..6663fbf 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,8 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; rust-overlay.url = "github:oxalica/rust-overlay"; + rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; + flake-parts.url = "github:hercules-ci/flake-parts"; }; outputs = @@ -11,58 +13,21 @@ self, nixpkgs, rust-overlay, - }: - let - supportedSystems = [ + flake-parts, + }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" "aarch64-linux" ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - pkgsForSystem = - system: - (import nixpkgs { - inherit system; + perSystem = + { config, system, ... }: + let overlays = [ (import rust-overlay) ]; - }); - in - { - packages = forAllSystems ( - system: - let - inherit (pkgsForSystem system) - lib - rustPlatform - ; + pkgs = import nixpkgs { inherit system overlays; }; + inherit (pkgs) lib rustPlatform; - cargoToml = lib.trivial.importTOML ./Cargo.toml; - version = cargoToml.package.version; - in - rec { - default = brewlog; - - brewlog = rustPlatform.buildRustPackage { - pname = "brewlog"; - version = version; - src = lib.cleanSource ./.; - cargoLock.lockFile = ./Cargo.lock; - - meta = { - description = "Log your favourite roasters, roasts, brews and cafes!"; - homepage = "https://github.com/jnsgruk/brewlog"; - license = lib.licenses.asl20; - mainProgram = "brewlog"; - platforms = lib.platforms.unix; - maintainers = with lib.maintainers; [ jnsgruk ]; - }; - }; - } - ); - - devShells = forAllSystems ( - system: - let - pkgs = pkgsForSystem system; rust = pkgs.rust-bin.stable.latest.default.override { extensions = [ "rust-src" @@ -71,28 +36,49 @@ "rustfmt" ]; }; + + cargoToml = lib.trivial.importTOML ./Cargo.toml; + version = cargoToml.package.version; in { - default = pkgs.mkShell { - name = "brewlog"; + packages = { + default = self.packages.${system}.brewlog; - NIX_CONFIG = "experimental-features = nix-command flakes"; - RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library"; + brewlog = rustPlatform.buildRustPackage { + pname = "brewlog"; + inherit version; + src = lib.cleanSource ./.; + cargoLock.lockFile = ./Cargo.lock; - buildInputs = - with pkgs; - [ - cargo-watch - nil - nixfmt - sqlite - sqlx-cli - ] - ++ [ - rust - ]; + meta = { + description = "Log your favourite roasters, roasts, brews and cafes!"; + homepage = "https://github.com/jnsgruk/brewlog"; + license = lib.licenses.asl20; + mainProgram = "brewlog"; + platforms = lib.platforms.unix; + maintainers = with lib.maintainers; [ jnsgruk ]; + }; + }; }; - } - ); + + devShells = { + default = pkgs.mkShell { + name = "brewlog"; + + NIX_CONFIG = "experimental-features = nix-command flakes"; + RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library"; + + buildInputs = + [ rust ] + ++ (with pkgs; [ + cargo-watch + nil + nixfmt + sqlite + sqlx-cli + ]); + }; + }; + }; }; }