refactor(nix): simplify package declaration
This commit is contained in:
44
flake.nix
44
flake.nix
@@ -41,36 +41,22 @@
|
||||
};
|
||||
in {
|
||||
formatter = alejandra.defaultPackage.${system};
|
||||
packages =
|
||||
(import ./nix/package.nix {inherit pkgs rustPlatform;})
|
||||
// {
|
||||
windows = let
|
||||
mingwPkgs = pkgs.pkgsCross.mingwW64;
|
||||
rustWindows = pkgs.rust-bin.stable.latest.default.override {
|
||||
targets = ["x86_64-pc-windows-gnu"];
|
||||
};
|
||||
rustPlatformWindows = mingwPkgs.makeRustPlatform {
|
||||
cargo = rustWindows;
|
||||
rustc = rustWindows;
|
||||
};
|
||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||
in
|
||||
rustPlatformWindows.buildRustPackage {
|
||||
pname = cargoToml.package.name;
|
||||
version = cargoToml.package.version;
|
||||
src = pkgs.lib.cleanSource ./.;
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
nativeBuildInputs = [pkgs.upx];
|
||||
doCheck = false;
|
||||
meta = {
|
||||
description = "Conventional commits for Jujutsu";
|
||||
homepage = "https://labs.phundrak.com/phundrak/jj-cz";
|
||||
};
|
||||
postBuild = ''
|
||||
${pkgs.upx}/bin/upx target/*/release/jj-cz.exe
|
||||
'';
|
||||
};
|
||||
packages = let
|
||||
nativeRustVersion = pkgs.rust-bin.stable.latest.default;
|
||||
nativeRustPlatform = pkgs.makeRustPlatform {
|
||||
cargo = nativeRustVersion;
|
||||
rustc = nativeRustVersion;
|
||||
};
|
||||
mingwPkgs = pkgs.pkgsCross.mingwW64;
|
||||
windowsRustVersion = pkgs.rust-bin.stable.latest.default.override {
|
||||
targets = ["x86_64-pc-windows-gnu"];
|
||||
};
|
||||
windowsRustPlatform = mingwPkgs.makeRustPlatform {
|
||||
cargo = windowsRustVersion;
|
||||
rustc = windowsRustVersion;
|
||||
};
|
||||
in
|
||||
import ./nix/package.nix {inherit pkgs nativeRustPlatform windowsRustPlatform;};
|
||||
devShell = import ./nix/shell.nix {
|
||||
inherit inputs pkgs rustVersion;
|
||||
};
|
||||
|
||||
@@ -1,26 +1,36 @@
|
||||
{
|
||||
pkgs,
|
||||
rustPlatform,
|
||||
nativeRustPlatform,
|
||||
windowsRustPlatform,
|
||||
...
|
||||
}: let
|
||||
cargoToml = fromTOML (builtins.readFile ../Cargo.toml);
|
||||
name = cargoToml.package.name;
|
||||
version = cargoToml.package.version;
|
||||
rustBuild = rustPlatform.buildRustPackage {
|
||||
buildArgs = {
|
||||
pname = name;
|
||||
inherit version;
|
||||
src = pkgs.lib.cleanSource ../.;
|
||||
cargoLock.lockFile = ../Cargo.lock;
|
||||
nativeBuildInputs = [pkgs.upx];
|
||||
useNextest = true;
|
||||
meta = {
|
||||
description = "Conventional commits for Jujutsu";
|
||||
homepage = "https://labs.phundrak.com/phundrak/jj-cz";
|
||||
inherit (cargoToml.package) description homepage;
|
||||
};
|
||||
postBuild = ''
|
||||
${pkgs.upx}/bin/upx target/*/release/${name}
|
||||
'';
|
||||
};
|
||||
nativeBuild =
|
||||
nativeRustPlatform.buildRustPackage buildArgs
|
||||
// {
|
||||
postBuild = "${pkgs.upx}/bin/upx target/*/release/${name}";
|
||||
};
|
||||
windowsBuild =
|
||||
windowsRustPlatform.buildRustPackage buildArgs
|
||||
// {
|
||||
postBuild = "${pkgs.upx}/bin/upx target/*/release/${name}.exe";
|
||||
};
|
||||
in {
|
||||
default = rustBuild;
|
||||
default = nativeBuild;
|
||||
windows = windowsBuild;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user