Use crane to build the nix package
crane (https://github.com/ipetkov/crane) builds the dependencies separately and stores them in the nix store, so they get reused on subsequent builds.
This commit is contained in:
parent
64acda457c
commit
eb12b75604
2 changed files with 84 additions and 55 deletions
68
flake.lock
68
flake.lock
|
@ -1,5 +1,32 @@
|
|||
{
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-utils": [
|
||||
"flake-utils"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-overlay": [
|
||||
"rust-overlay"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1673056065,
|
||||
"narHash": "sha256-a68tMDTDqdAauxq377ALl4Uwm6oh9MeoY2WbTYRWZoo=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "0144134311767fcee80213321f079a8ffa0b9cc1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
|
@ -16,6 +43,22 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat_2": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1668681692,
|
||||
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1667395993,
|
||||
|
@ -52,27 +95,6 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"naersk": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1662220400,
|
||||
"narHash": "sha256-9o2OGQqu4xyLZP9K6kNe1pTHnyPz0Wr3raGYnr9AIgY=",
|
||||
"owner": "nmattia",
|
||||
"repo": "naersk",
|
||||
"rev": "6944160c19cb591eb85bbf9b2f2768a935623ed3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nmattia",
|
||||
"ref": "master",
|
||||
"repo": "naersk",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1669542132,
|
||||
|
@ -123,7 +145,7 @@
|
|||
},
|
||||
"pre-commit-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-compat": "flake-compat_2",
|
||||
"flake-utils": [
|
||||
"flake-utils"
|
||||
],
|
||||
|
@ -147,8 +169,8 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"flake-utils": "flake-utils",
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": "pre-commit-hooks",
|
||||
"rust-overlay": "rust-overlay"
|
||||
|
|
71
flake.nix
71
flake.nix
|
@ -3,10 +3,7 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
naersk = {
|
||||
url = "github:nmattia/naersk/master";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
@ -16,48 +13,46 @@
|
|||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.flake-utils.follows = "flake-utils";
|
||||
};
|
||||
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.flake-utils.follows = "flake-utils";
|
||||
inputs.rust-overlay.follows = "rust-overlay";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, naersk, rust-overlay, pre-commit-hooks }:
|
||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, pre-commit-hooks, crane }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs { inherit system overlays; };
|
||||
naersk-lib = pkgs.callPackage naersk { };
|
||||
rustToolchain =
|
||||
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
|
||||
crane-lib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
src = crane-lib.cleanCargoSource ./.;
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
] ++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkgconf
|
||||
];
|
||||
|
||||
cargoArtifacts = crane-lib.buildDepsOnly {
|
||||
inherit src buildInputs nativeBuildInputs;
|
||||
};
|
||||
|
||||
ha-now-playing = crane-lib.buildPackage {
|
||||
inherit cargoArtifacts src buildInputs nativeBuildInputs;
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
formatter = pkgs.nixpkgs-fmt;
|
||||
|
||||
packages = {
|
||||
ha-now-playing = (naersk-lib.override {
|
||||
cargo = rustToolchain;
|
||||
rustc = rustToolchain;
|
||||
}).buildPackage
|
||||
{
|
||||
pname = "ha-now-playing";
|
||||
root = ./.;
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
rustToolchain
|
||||
openssl
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkgconf
|
||||
cargo-edit
|
||||
cargo-expand
|
||||
cargo-diet
|
||||
cargo-feature
|
||||
cargo-outdated
|
||||
rust-analyzer
|
||||
pre-commit
|
||||
jq
|
||||
gitflow
|
||||
yaml-language-server
|
||||
];
|
||||
};
|
||||
inherit ha-now-playing;
|
||||
};
|
||||
packages.default = self.packages.${system}.ha-now-playing;
|
||||
|
||||
|
@ -71,6 +66,17 @@
|
|||
};
|
||||
|
||||
checks = {
|
||||
inherit ha-now-playing;
|
||||
|
||||
ha-now-playing-clippy = crane-lib.cargoClippy {
|
||||
inherit cargoArtifacts src buildInputs nativeBuildInputs;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
};
|
||||
|
||||
ha-now-playing-fmt = crane-lib.cargoFmt {
|
||||
inherit src;
|
||||
};
|
||||
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
|
@ -97,6 +103,7 @@
|
|||
|
||||
name = "ha-now-playing";
|
||||
inputsFrom = [ self.packages.${system}.ha-now-playing ];
|
||||
nativeBuildInputs = [ rustToolchain ];
|
||||
};
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue