From 29db607e10937ef4b9d4bf75f5dcf0615220927c Mon Sep 17 00:00:00 2001 From: Michael Forster Date: Thu, 26 Jan 2023 18:08:55 +0100 Subject: [PATCH] nix: replace manual system iteration by `flake-utils` Let's not reinvent the wheel. This makes the flake more readable, and also would detect typos in the system list. --- flake.lock | 11 +++++++---- flake.nix | 34 ++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/flake.lock b/flake.lock index 3e6328536..32be3e1d3 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -31,13 +31,16 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay" } }, "rust-overlay": { "inputs": { - "flake-utils": "flake-utils", + "flake-utils": [ + "flake-utils" + ], "nixpkgs": [ "nixpkgs" ] diff --git a/flake.nix b/flake.nix index a28086deb..f3ce41120 100644 --- a/flake.nix +++ b/flake.nix @@ -1,30 +1,32 @@ { - description = "jujutsu"; + description = "Jujutsu VCS, a Git-compatible DVCS that is both simple and powerful"; inputs = { + # For listing and iterating nix systems + flake-utils.url = "github:numtide/flake-utils"; + # For installing non-standard rustc versions rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; + rust-overlay.inputs.flake-utils.follows = "flake-utils"; }; - outputs = { self, nixpkgs, rust-overlay, ... }: + outputs = { self, nixpkgs, flake-utils, rust-overlay }: let - lib = nixpkgs.lib; - systems = [ - "aarch64-linux" - "aarch64-darwin" - "i686-linux" - "x86_64-darwin" - "x86_64-linux" + systems = with flake-utils.lib.system; [ + aarch64-linux + aarch64-darwin + i686-linux + x86_64-darwin + x86_64-linux ]; - foreachSystem = f: lib.foldl' (attrs: system: lib.recursiveUpdate attrs (f system)) { } systems; in { overlays.default = (final: prev: { jujutsu = self.packages.${final.system}.jujutsu; }); } // - (foreachSystem (system: + (flake-utils.lib.eachSystem systems (system: let pkgs = import nixpkgs { inherit system; @@ -34,7 +36,7 @@ }; in { - packages.${system} = { + packages = { jujutsu = pkgs.rustPlatform.buildRustPackage rec { pname = "jujutsu"; version = "unstable-${self.shortRev or "dirty"}"; @@ -70,19 +72,19 @@ }; default = self.packages.${system}.jujutsu; }; - apps.${system}.default = { + apps.default = { type = "app"; program = "${self.packages.${system}.jujutsu}/bin/jj"; }; - checks.${system}.jujutsu = self.packages.${system}.jujutsu.overrideAttrs ({ ... }: { + checks.jujutsu = self.packages.${system}.jujutsu.overrideAttrs ({ ... }: { cargoBuildType = "debug"; cargoCheckType = "debug"; preCheck = '' export RUST_BACKTRACE=1 ''; }); - formatter.${system} = pkgs.nixpkgs-fmt; - devShells.${system}.default = pkgs.mkShell { + formatter = pkgs.nixpkgs-fmt; + devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ # Using the minimal profile with explicit "clippy" extension to avoid # two versions of rustfmt