From bd5b563921367ec1d46c66d13db5a48b4d643779 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 | 69 ++++++++++++++++------- flake.nix | 163 ++++++++++++++++++++++++----------------------------- 2 files changed, 123 insertions(+), 109 deletions(-) diff --git a/flake.lock b/flake.lock index b5687e1..157d266 100644 --- a/flake.lock +++ b/flake.lock @@ -21,26 +21,22 @@ } }, "flake-compat": { - "flake": false, "locked": { "lastModified": 1696426674, "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", - "repo": "flake-compat", "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "type": "github" + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" } }, "flake-parts": { "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { "lastModified": 1706830856, @@ -51,9 +47,8 @@ "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" + "id": "flake-parts", + "type": "indirect" } }, "flake-utils": { @@ -97,11 +92,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": { @@ -111,6 +106,24 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1706550542, + "narHash": "sha256-UcsnCG6wx++23yeER4Hg18CXWbgNpqNXcHIo5/1Y+hc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "97b17f32362e475016f942bbdfda4a4a72a8a652", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-stable": { "locked": { "lastModified": 1704874635, @@ -163,7 +176,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_2" } }, "rust-overlay": { @@ -176,11 +190,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": { @@ -203,6 +217,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "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 4b9ccb9..84a9a93 100644 --- a/flake.nix +++ b/flake.nix @@ -7,15 +7,9 @@ flake-utils.url = "github:numtide/flake-utils"; - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; + flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; + systems.url = "github:nix-systems/default"; rust-overlay = { url = "github:oxalica/rust-overlay"; @@ -39,107 +33,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; }; - }); + + }; + }; }