From 27fd2912fc4c30639588608ce7a04e8d83be0461 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 10 Feb 2024 09:39:02 +0100 Subject: [PATCH] flake: minor changes --- flake.lock | 19 ++++--- flake.nix | 160 ++++++++++++++++++++++++++--------------------------- 2 files changed, 89 insertions(+), 90 deletions(-) diff --git a/flake.lock b/flake.lock index b5687e1..055722e 100644 --- a/flake.lock +++ b/flake.lock @@ -58,7 +58,9 @@ }, "flake-utils": { "inputs": { - "systems": "systems" + "systems": [ + "systems" + ] }, "locked": { "lastModified": 1705309234, @@ -97,11 +99,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1707546158, - "narHash": "sha256-nYYJTpzfPMDxI8mzhQsYjIUX+grorqjKEU9Np6Xwy/0=", + "lastModified": 1706913249, + "narHash": "sha256-x3M7iV++CsvRXI1fpyFPduGELUckZEhSv0XWnUopAG8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d934204a0f8d9198e1e4515dd6fec76a139c87f0", + "rev": "e92b6015881907e698782c77641aa49298330223", "type": "github" }, "original": { @@ -163,7 +165,8 @@ "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "pre-commit-hooks-nix": "pre-commit-hooks-nix", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "systems": "systems" } }, "rust-overlay": { @@ -176,11 +179,11 @@ ] }, "locked": { - "lastModified": 1707617562, - "narHash": "sha256-Kk2vv5e4MqKPjelKoYsa6YaUyv3pvjWY9nJSnP2QU9w=", + "lastModified": 1707012820, + "narHash": "sha256-4cxIaHUx6/DSEVHJfK0gx4DZkJ5xHugan27KfuVPnj0=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "a22bbbee9b479c6d95b4819135e856a6d447b3ba", + "rev": "b83b8c3ef16d15a4ae3843d74f32dfc86caed60f", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 4b9ccb9..addb70a 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,12 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; + systems.url = "github:nix-systems/default"; + + flake-utils = { + url = "github:numtide/flake-utils"; + inputs.systems.follows = "systems"; + }; flake-compat = { url = "github:edolstra/flake-compat"; @@ -39,107 +44,98 @@ }; - outputs = inputs@{ self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } (_: - let - # This is effectively just boilerplate to allow us to keep the `lib` - # output. - libOutputModule = { lib, ... }: flake-parts.lib.mkTransposedPerSystemModule { - name = "lib"; - option = lib.mkOption { - type = lib.types.lazyAttrsOf lib.types.anything; - default = { }; + outputs = inputs@{ self, flake-parts, systems, ... }: flake-parts.lib.mkFlake { inherit inputs; } { + systems = import systems; + + imports = + let + # This is effectively just boilerplate to allow us to keep the `lib` + # output. + libOutputModule = { lib, ... }: flake-parts.lib.mkTransposedPerSystemModule { + name = "lib"; + option = lib.mkOption { + type = lib.types.lazyAttrsOf lib.types.anything; + default = { }; + }; + file = ""; }; - file = ""; - }; - in - { - - imports = [ + in + [ inputs.pre-commit-hooks-nix.flakeModule libOutputModule ]; - flake = { - templates.default = { - path = builtins.filterSource (path: type: baseNameOf path == "flake.nix") - ./examples/flakes; - description = "Build a Bom for GNU hello"; - }; + flake = { + templates.default = { + path = builtins.filterSource (path: type: baseNameOf path == "flake.nix") + ./examples/flakes; + description = "Build a Bom for GNU hello"; }; + }; - systems = [ - "x86_64-linux" - "aarch64-linux" - - "x86_64-darwin" - "aarch64-darwin" - ]; - - perSystem = { config, system, ... }: - let - pkgs = import inputs.nixpkgs { - inherit system; - overlays = [ (import inputs.rust-overlay) ]; - }; - - rustToolChain = pkgs.rust-bin.fromRustupToolchainFile ./transformer/rust-toolchain.toml; - craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolChain; - - # Include the Git commit hash as the version of bombon in generated Boms - GIT_COMMIT = pkgs.lib.optionalString (self ? rev) self.rev; + perSystem = { config, system, pkgs, lib, ... }: + let + rustToolChain = pkgs.rust-bin.fromRustupToolchainFile ./transformer/rust-toolchain.toml; + craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolChain; - commonArgs = { - src = craneLib.cleanCargoSource ./transformer; - inherit GIT_COMMIT; - }; - cargoArtifacts = craneLib.buildDepsOnly commonArgs; - transformer = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); + # Include the Git commit hash as the version of bombon in generated Boms + GIT_COMMIT = lib.optionalString (self ? rev) self.rev; - buildBom = pkgs.callPackage ./build-bom.nix { - inherit transformer; - buildtimeDependencies = pkgs.callPackage ./buildtime-dependencies.nix { }; - runtimeDependencies = pkgs.callPackage ./runtime-dependencies.nix { }; - }; - in - { + commonArgs = { + src = craneLib.cleanCargoSource ./transformer; + inherit GIT_COMMIT; + }; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + transformer = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); - lib = { inherit buildBom; }; + buildBom = pkgs.callPackage ./build-bom.nix { + inherit transformer; + buildtimeDependencies = pkgs.callPackage ./buildtime-dependencies.nix { }; + runtimeDependencies = pkgs.callPackage ./runtime-dependencies.nix { }; + }; + in + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ (import inputs.rust-overlay) ]; + }; - packages = { - # This is mostly here for development - inherit transformer; - default = transformer; - }; + lib = { inherit buildBom; }; - checks = { - clippy = craneLib.cargoClippy (commonArgs // { inherit cargoArtifacts; }); - rustfmt = craneLib.cargoFmt (commonArgs // { inherit cargoArtifacts; }); - } // import ./tests { inherit pkgs buildBom; }; + packages = { + # This is mostly here for development + inherit transformer; + default = transformer; + }; - pre-commit = { - check.enable = true; + checks = { + clippy = craneLib.cargoClippy (commonArgs // { inherit cargoArtifacts; }); + rustfmt = craneLib.cargoFmt (commonArgs // { inherit cargoArtifacts; }); + } // import ./tests { inherit pkgs buildBom; }; - settings = { - hooks = { - nixpkgs-fmt.enable = true; - typos.enable = true; - }; + pre-commit = { + check.enable = true; - settings.statix.ignore = [ "sources.nix" ]; + settings = { + hooks = { + nixpkgs-fmt.enable = true; + typos.enable = true; }; + settings.statix.ignore = [ "sources.nix" ]; }; + }; - devShells.default = pkgs.mkShell { - shellHook = '' - ${config.pre-commit.installationScript} - ''; - - inputsFrom = [ transformer ]; + devShells.default = pkgs.mkShell { + shellHook = '' + ${config.pre-commit.installationScript} + ''; - inherit GIT_COMMIT; - }; + inputsFrom = [ transformer ]; + inherit GIT_COMMIT; }; - }); + + }; + }; }