nix: build with crane
This commit is contained in:
16
flake.lock
generated
16
flake.lock
generated
@@ -1,5 +1,20 @@
|
||||
{
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1770419512,
|
||||
"narHash": "sha256-o8Vcdz6B6bkiGUYkZqFwH3Pv1JwZyXht3dMtS7RchIo=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "2510f2cbc3ccd237f700bb213756a8f35c32d8d7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1769170682,
|
||||
@@ -18,6 +33,7 @@
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
|
||||
30
flake.nix
30
flake.nix
@@ -4,9 +4,11 @@
|
||||
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
||||
crane.url = "github:ipetkov/crane";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, rust-overlay}:
|
||||
outputs = { self, nixpkgs, rust-overlay, crane }:
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
|
||||
@@ -71,6 +73,9 @@
|
||||
roowho2 = final: prev: {
|
||||
inherit (self.packages.${prev.stdenv.hostPlatform.system}) roowho2;
|
||||
};
|
||||
roowho2-crane = final: prev: {
|
||||
roowho2 = self.packages.${prev.stdenv.hostPlatform.system}.roowho2-crane;
|
||||
};
|
||||
};
|
||||
|
||||
nixosModules.default = ./nix/module.nix;
|
||||
@@ -79,12 +84,13 @@
|
||||
let
|
||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||
cargoLock = ./Cargo.lock;
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain(p: p.rust-bin.nightly.latest.default);
|
||||
|
||||
src = lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset = lib.fileset.unions [
|
||||
./src
|
||||
./Cargo.toml
|
||||
./Cargo.lock
|
||||
(craneLib.fileset.commonCargoSources ./.)
|
||||
# ./assets
|
||||
];
|
||||
};
|
||||
|
||||
@@ -93,13 +99,25 @@
|
||||
cargo = pkgs.rust-bin.nightly.latest.cargo;
|
||||
};
|
||||
in {
|
||||
default = self.packages.${system}.roowho2;
|
||||
default = self.packages.${system}.roowho2-crane;
|
||||
|
||||
roowho2 = pkgs.callPackage ./nix/package.nix { inherit cargoToml cargoLock src rustPlatform; };
|
||||
roowho2 = pkgs.callPackage ./nix/package.nix {
|
||||
inherit cargoToml cargoLock src rustPlatform;
|
||||
};
|
||||
|
||||
roowho2-crane = pkgs.callPackage ./nix/package.nix {
|
||||
useCrane = true;
|
||||
inherit cargoToml cargoLock src craneLib;
|
||||
};
|
||||
|
||||
filteredSource = pkgs.runCommandLocal "filtered-source" { } ''
|
||||
ln -s ${src} $out
|
||||
'';
|
||||
});
|
||||
|
||||
checks = forAllSystems (system: pkgs: _: {
|
||||
# NOTE: the non-crane build runs tests during checkPhase
|
||||
inherit (self.packages.${system}) roowho2;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,22 +10,62 @@
|
||||
, cargoToml
|
||||
, cargoLock
|
||||
, src
|
||||
|
||||
, useCrane ? false
|
||||
, craneLib ? null
|
||||
}:
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "roowho2";
|
||||
let
|
||||
mainProgram = "roowhod";
|
||||
buildFunction = if useCrane then craneLib.buildPackage else rustPlatform.buildRustPackage;
|
||||
|
||||
pnameCraneSuffix = lib.optionalString useCrane "-crane";
|
||||
pname = "${cargoToml.package.name}${pnameCraneSuffix}";
|
||||
|
||||
rustPlatformArgs = {
|
||||
buildType = "releaselto";
|
||||
buildFeatures = lib.optionals stdenv.hostPlatform.isLinux [
|
||||
"systemd"
|
||||
];
|
||||
cargoLock.lockFile = cargoLock;
|
||||
|
||||
doCheck = true;
|
||||
useNextest = true;
|
||||
nativeCheckInputs = [
|
||||
versionCheckHook
|
||||
];
|
||||
cargoCheckFeatures = lib.optionals stdenv.hostPlatform.isLinux [
|
||||
"systemd"
|
||||
];
|
||||
};
|
||||
|
||||
craneArgs = {
|
||||
cargoLock = cargoLock;
|
||||
cargoExtraArgs = lib.escapeShellArgs [ "--features" (lib.concatStringsSep "," (
|
||||
lib.optionals stdenv.hostPlatform.isLinux [
|
||||
"systemd"
|
||||
]
|
||||
)) ];
|
||||
cargoArtifacts = craneLib.buildDepsOnly {
|
||||
inherit pname;
|
||||
inherit (cargoToml.package) version;
|
||||
src = lib.fileset.toSource {
|
||||
root = ../.;
|
||||
fileset = lib.fileset.unions [
|
||||
(craneLib.fileset.cargoTomlAndLock ../.)
|
||||
];
|
||||
};
|
||||
|
||||
cargoLock = cargoLock;
|
||||
};
|
||||
};
|
||||
in
|
||||
buildFunction ({
|
||||
inherit pname;
|
||||
inherit (cargoToml.package) version;
|
||||
inherit src;
|
||||
|
||||
cargoLock.lockFile = cargoLock;
|
||||
|
||||
buildType = "releaselto";
|
||||
|
||||
RUSTFLAGS = "-Zhigher-ranked-assumptions";
|
||||
|
||||
buildFeatures = lib.optionals stdenv.hostPlatform.isLinux [
|
||||
"systemd"
|
||||
];
|
||||
|
||||
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
|
||||
systemdLibs
|
||||
];
|
||||
@@ -46,7 +86,11 @@ rustPlatform.buildRustPackage {
|
||||
in lib.concatStringsSep "\n" installShellCompletions;
|
||||
|
||||
meta = with lib; {
|
||||
license = licenses.mit;
|
||||
license = licenses.bsdOriginalUC;
|
||||
platforms = platforms.linux ++ platforms.darwin;
|
||||
inherit mainProgram;
|
||||
};
|
||||
}
|
||||
//
|
||||
(if useCrane then craneArgs else rustPlatformArgs)
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
self.overlays.default
|
||||
self.overlays.roowho2-crane
|
||||
];
|
||||
};
|
||||
in
|
||||
|
||||
Reference in New Issue
Block a user