diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml index 2ce7486..0f73792 100644 --- a/.github/workflows/build_nix.yml +++ b/.github/workflows/build_nix.yml @@ -10,4 +10,4 @@ jobs: - uses: actions/checkout@v2 - uses: cachix/install-nix-action@v12 - name: Building package - run: nix build .#all --extra-experimental-features 'nix-command flakes' + run: nix build .#workspace --extra-experimental-features 'nix-command flakes' diff --git a/flake.lock b/flake.lock index ab27893..f091dc4 100644 --- a/flake.lock +++ b/flake.lock @@ -1,27 +1,28 @@ { "nodes": { - "naersk": { + "crane": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1698420672, - "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", - "owner": "nix-community", - "repo": "naersk", - "rev": "aeb58d5e8faead8980a807c840232697982d47b9", + "lastModified": 1711586303, + "narHash": "sha256-iZDHWTqQj6z6ccqTSEOPOxQ8KMFAemInUObN2R9vHSs=", + "owner": "ipetkov", + "repo": "crane", + "rev": "a329cd00398379c62e76fc3b8d4ec2934260d636", "type": "github" }, "original": { - "owner": "nix-community", - "ref": "master", - "repo": "naersk", + "owner": "ipetkov", + "repo": "crane", "type": "github" } }, - "naersk_2": { + "naersk": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_2" }, "locked": { "lastModified": 1698420672, @@ -39,20 +40,6 @@ } }, "nixpkgs": { - "locked": { - "lastModified": 1710889954, - "narHash": "sha256-Pr6F5Pmd7JnNEMHHmspZ0qVqIBVxyZ13ik1pJtm2QXk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "7872526e9c5332274ea5932a0c3270d6e4724f3b", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs_2": { "locked": { "lastModified": 1710889954, "narHash": "sha256-Pr6F5Pmd7JnNEMHHmspZ0qVqIBVxyZ13ik1pJtm2QXk=", @@ -68,7 +55,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_2": { "locked": { "lastModified": 1708247094, "narHash": "sha256-H2VS7VwesetGDtIaaz4AMsRkPoSLEVzL/Ika8gnbUnE=", @@ -82,7 +69,7 @@ "type": "indirect" } }, - "nixpkgs_4": { + "nixpkgs_3": { "locked": { "lastModified": 1708247094, "narHash": "sha256-H2VS7VwesetGDtIaaz4AMsRkPoSLEVzL/Ika8gnbUnE=", @@ -100,8 +87,8 @@ }, "nixtract": { "inputs": { - "naersk": "naersk_2", - "nixpkgs": "nixpkgs_4", + "naersk": "naersk", + "nixpkgs": "nixpkgs_3", "utils": "utils" }, "locked": { @@ -120,8 +107,8 @@ }, "root": { "inputs": { - "naersk": "naersk", - "nixpkgs": "nixpkgs_2", + "crane": "crane", + "nixpkgs": "nixpkgs", "nixtract": "nixtract", "utils": "utils_2" } diff --git a/flake.nix b/flake.nix index 786b539..7810f5b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,10 @@ { inputs = { - naersk.url = "github:nix-community/naersk/master"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; utils.url = "github:numtide/flake-utils"; nixtract.url = "github:tweag/nixtract"; @@ -8,51 +12,107 @@ outputs = { self + , crane , nixpkgs , utils - , naersk , nixtract }: utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; - naersk-lib = pkgs.callPackage naersk { }; + crane-lib = crane.lib.${system}; cyclonedx = pkgs.callPackage ./nix/cyclonedx.nix { }; nixtract-cli = nixtract.defaultPackage.${system}; + + # Here we start the crane stuff + common-crane-args = { + pname = "genealogos"; + src = crane-lib.cleanCargoSource (crane-lib.path ./.); + strictDeps = true; + + cargoArtifacts = cargo-artifacts; + + # Genealogos uses the reqwest crate to query for narinfo on the substituters. + # reqwest depends on openssl. + nativeBuildInputs = with pkgs; [ pkg-config ]; + buildInputs = with pkgs; [ openssl ]; + }; + + cargo-artifacts = crane-lib.buildDepsOnly common-crane-args; + + workspace = (common-crane-args // { + cargoBuildCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack build --profile release"; + cargoTestCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack test --profile release"; + }); + + # Crane buildPackage arguments for every crate + crates = { + genealogos = (common-crane-args // { + cargoExtraArgs = "-p genealogos"; + }); + genealogos-cli = (common-crane-args // { + pname = "genealogos-cli"; + cargoExtraArgs = "-p genealogos-cli"; + }); + genealogos-api = (common-crane-args // { + pname = "genealogos-api"; + cargoExtraArgs = "-p genealogos-api"; + }); + }; + rust-packages = + builtins.mapAttrs (_: crane-lib.buildPackage) crates; in rec { - packages = import ./nix/packages.nix { inherit pkgs naersk-lib cyclonedx nixtract-cli; }; - devShells = { - default = - pkgs.mkShell { - buildInputs = with pkgs; [ - cargo - cargo-dist - rust-analyzer - rustPackages.clippy - rustc - rustfmt - - nixtract-cli - - pkg-config - openssl - - # https://github.com/rust-lang/cargo/issues/4463 - cargo-hack - ]; - RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; - RUST_BACKTRACE = 1; + checks = + # Builds + rust-packages + # Clippy + // builtins.mapAttrs + (_: args: crane-lib.cargoClippy (args // { + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + })) + crates + # Doc + // builtins.mapAttrs (_: crane-lib.cargoDoc) crates + # fmt + // builtins.mapAttrs (_: crane-lib.cargoFmt) crates; + + packages = + rust-packages // { + default = packages.genealogos; + + workspace = crane-lib.buildPackage workspace; + + update-fixture-output-files = pkgs.writeShellApplication { + name = "update-fixture-output-files"; + runtimeInputs = [ (packages.genealogos-cli.overrideAttrs (_: { doCheck = false; })) pkgs.jq ]; + text = builtins.readFile ./scripts/update-fixture-output-files.sh; }; - scripts = - pkgs.mkShell { - buildInputs = with packages; [ - update-fixture-input-files - update-fixture-output-files - verify-fixture-files - ]; + update-fixture-input-files = pkgs.writeShellApplication { + name = "update-fixture-input-files"; + runtimeInputs = [ nixtract-cli ]; + text = builtins.readFile ./scripts/update-fixture-input-files.sh; }; + verify-fixture-files = pkgs.writeShellApplication { + name = "verify-fixture-files"; + runtimeInputs = [ cyclonedx ]; + text = builtins.readFile ./scripts/verify-fixture-files.sh; + }; + }; + + apps.default = utils.lib.mkApp { + drv = packages.genealogos-cli; + }; + + + devShells.default = crane-lib.devShell { + inherit checks; + + packages = with pkgs; [ + rust-analyzer + cargo-hack + ]; }; }); } diff --git a/nix/packages.nix b/nix/packages.nix deleted file mode 100644 index fb72a8b..0000000 --- a/nix/packages.nix +++ /dev/null @@ -1,59 +0,0 @@ -# This nix file contains all our own packages! -{ pkgs, naersk-lib, nixtract-cli, cyclonedx }: -let - buildRustPackage = - { name } @ args: naersk-lib.buildPackage (args // { - src = ../.; - doCheck = true; - - cargoBuildOptions = x: x ++ [ "--package" name ]; - - # Setting this feature flag to disable tests that require recursive nix/an internet connection - cargoTestOptions = x: x ++ [ "--package" name "--features" "nix" ]; - - # Genealogos uses the reqwest crate to query for narinfo on the substituters. - # reqwest depends on openssl. - nativeBuildInputs = with pkgs; [ pkg-config ]; - buildInputs = with pkgs; [ openssl ]; - }); -in -rec { - default = genealogos; - genealogos = buildRustPackage { - name = "genealogos"; - }; - genealogos-cli = buildRustPackage { - name = "genealogos-cli"; - }; - genealogos-api = buildRustPackage { - name = "genealogos-api"; - }; - update-fixture-output-files = pkgs.writeShellApplication { - name = "update-fixture-output-files"; - runtimeInputs = [ (genealogos-cli.overrideAttrs (_: { doCheck = false; })) pkgs.jq ]; - text = builtins.readFile ../scripts/update-fixture-output-files.sh; - }; - update-fixture-input-files = pkgs.writeShellApplication { - name = "update-fixture-input-files"; - runtimeInputs = [ nixtract-cli ]; - text = builtins.readFile ../scripts/update-fixture-input-files.sh; - }; - verify-fixture-files = pkgs.writeShellApplication { - name = "verify-fixture-files"; - runtimeInputs = [ cyclonedx ]; - text = builtins.readFile ../scripts/verify-fixture-files.sh; - }; - - # This is a special package that we use mainly for CI. - # It uses naersk to build the entire rust workspace. - all = naersk-lib.buildPackage { - name = "genealogos"; - src = ../.; - doCheck = true; - cargoOptions = x: x ++ [ "hack" ]; - cargoTestOptions = x: x ++ [ "--features" "nix" ]; - nativeBuildInputs = with pkgs; [ pkg-config cargo-hack ]; - buildInputs = with pkgs; [ openssl ]; - RUST_BACKTRACE = 1; - }; -}