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
This commit is contained in:
Jon Seager 2026-02-02 17:39:38 +00:00
parent c7ea7420ae
commit 583f249059
No known key found for this signature in database
2 changed files with 80 additions and 74 deletions

View file

@ -1,5 +1,23 @@
{ {
"nodes": { "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1763283776, "lastModified": 1763283776,
@ -16,31 +34,33 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_2": { "nixpkgs-lib": {
"locked": { "locked": {
"lastModified": 1744536153, "lastModified": 1769909678,
"narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", "narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=",
"owner": "NixOS", "owner": "nix-community",
"repo": "nixpkgs", "repo": "nixpkgs.lib",
"rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", "rev": "72716169fe93074c333e8d0173151350670b824c",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "nix-community",
"ref": "nixpkgs-unstable", "repo": "nixpkgs.lib",
"repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
} }
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_2" "nixpkgs": [
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1763433504, "lastModified": 1763433504,

114
flake.nix
View file

@ -4,6 +4,8 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
}; };
outputs = outputs =
@ -11,58 +13,21 @@
self, self,
nixpkgs, nixpkgs,
rust-overlay, rust-overlay,
}: flake-parts,
let }@inputs:
supportedSystems = [ flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux" "x86_64-linux"
"aarch64-linux" "aarch64-linux"
]; ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgsForSystem = perSystem =
system: { config, system, ... }:
(import nixpkgs { let
inherit system;
overlays = [ (import rust-overlay) ]; overlays = [ (import rust-overlay) ];
}); pkgs = import nixpkgs { inherit system overlays; };
in inherit (pkgs) lib rustPlatform;
{
packages = forAllSystems (
system:
let
inherit (pkgsForSystem system)
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 { rust = pkgs.rust-bin.stable.latest.default.override {
extensions = [ extensions = [
"rust-src" "rust-src"
@ -71,28 +36,49 @@
"rustfmt" "rustfmt"
]; ];
}; };
cargoToml = lib.trivial.importTOML ./Cargo.toml;
version = cargoToml.package.version;
in in
{ {
default = pkgs.mkShell { packages = {
name = "brewlog"; default = self.packages.${system}.brewlog;
NIX_CONFIG = "experimental-features = nix-command flakes"; brewlog = rustPlatform.buildRustPackage {
RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library"; pname = "brewlog";
inherit version;
src = lib.cleanSource ./.;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = meta = {
with pkgs; description = "Log your favourite roasters, roasts, brews and cafes!";
[ homepage = "https://github.com/jnsgruk/brewlog";
cargo-watch license = lib.licenses.asl20;
nil mainProgram = "brewlog";
nixfmt platforms = lib.platforms.unix;
sqlite maintainers = with lib.maintainers; [ jnsgruk ];
sqlx-cli };
] };
++ [
rust
];
}; };
}
); 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
]);
};
};
};
}; };
} }