ref(nix): split package to default.nix

This commit is contained in:
b4mbus
2024-06-09 02:34:30 +02:00
parent 81306e93c6
commit 4d5e2212e3
2 changed files with 51 additions and 36 deletions

42
default.nix Normal file
View File

@@ -0,0 +1,42 @@
{
lib,
stdenv,
rust-bin, # From overlay
makeRustPlatform,
packageToml,
rust,
libiconv,
darwin,
python3,
}: let
testDeps = [
python3
];
buildDeps = rust:
[
rust
]
++ (lib.optionals stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.Foundation
])
++ testDeps;
mkPackage = rust:
(makeRustPlatform {
cargo = rust;
rustc = rust;
})
.buildRustPackage {
pname = packageToml.name;
inherit (packageToml) version;
src = builtins.path {
path = ./.;
inherit (packageToml) name;
};
cargoLock.lockFile = ./Cargo.lock;
buildInputs = buildDeps rust;
dontUseCargoParallelTests = true;
};
in (mkPackage rust-bin.stable.latest.minimal)

View File

@@ -25,46 +25,18 @@
packageToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package;
msrv = packageToml.rust-version;
buildDeps = rust:
with pkgs;
[
rust
]
++ (lib.optionals stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.Foundation
])
++ testDeps;
testDeps = with pkgs; [
python3
];
mkDevShell = rust:
pkgs.mkShell {
packages = buildDeps (rust.override {
extensions = ["rust-src"];
});
inputsFrom = [
(config.packages.default.override {
rust = rust.override {
extensions = ["rust-src"];
};
})
];
env.RUST_BACKTRACE = 1;
};
mkPackage = rust:
(pkgs.makeRustPlatform {
cargo = rust;
rustc = rust;
})
.buildRustPackage {
pname = packageToml.name;
inherit (packageToml) version;
src = builtins.path {
path = ./.;
inherit (packageToml) name;
};
cargoLock.lockFile = ./Cargo.lock;
buildInputs = buildDeps rust;
dontUseCargoParallelTests = true;
};
in {
_module.args = {
pkgs = import inputs.nixpkgs {
@@ -79,7 +51,8 @@
default = mkDevShell pkgs.rust-bin.stable.latest.default;
msrv = mkDevShell pkgs.rust-bin.stable.${msrv}.default;
};
packages.default = mkPackage pkgs.rust-bin.stable.latest.minimal;
packages.default = pkgs.callPackage ./default.nix {inherit packageToml;};
};
};
}