refactor(nix): simplify package declaration

This commit is contained in:
2026-03-25 18:46:26 +01:00
parent a5b2bc41aa
commit 1c983f3a8d
2 changed files with 31 additions and 35 deletions

View File

@@ -41,36 +41,22 @@
}; };
in { in {
formatter = alejandra.defaultPackage.${system}; formatter = alejandra.defaultPackage.${system};
packages = packages = let
(import ./nix/package.nix {inherit pkgs rustPlatform;}) nativeRustVersion = pkgs.rust-bin.stable.latest.default;
// { nativeRustPlatform = pkgs.makeRustPlatform {
windows = let cargo = nativeRustVersion;
rustc = nativeRustVersion;
};
mingwPkgs = pkgs.pkgsCross.mingwW64; mingwPkgs = pkgs.pkgsCross.mingwW64;
rustWindows = pkgs.rust-bin.stable.latest.default.override { windowsRustVersion = pkgs.rust-bin.stable.latest.default.override {
targets = ["x86_64-pc-windows-gnu"]; targets = ["x86_64-pc-windows-gnu"];
}; };
rustPlatformWindows = mingwPkgs.makeRustPlatform { windowsRustPlatform = mingwPkgs.makeRustPlatform {
cargo = rustWindows; cargo = windowsRustVersion;
rustc = rustWindows; rustc = windowsRustVersion;
}; };
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in in
rustPlatformWindows.buildRustPackage { import ./nix/package.nix {inherit pkgs nativeRustPlatform windowsRustPlatform;};
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
'';
};
};
devShell = import ./nix/shell.nix { devShell = import ./nix/shell.nix {
inherit inputs pkgs rustVersion; inherit inputs pkgs rustVersion;
}; };

View File

@@ -1,26 +1,36 @@
{ {
pkgs, pkgs,
rustPlatform, nativeRustPlatform,
windowsRustPlatform,
... ...
}: let }: let
cargoToml = fromTOML (builtins.readFile ../Cargo.toml); cargoToml = fromTOML (builtins.readFile ../Cargo.toml);
name = cargoToml.package.name; name = cargoToml.package.name;
version = cargoToml.package.version; version = cargoToml.package.version;
rustBuild = rustPlatform.buildRustPackage { buildArgs = {
pname = name; pname = name;
inherit version; inherit version;
src = pkgs.lib.cleanSource ../.; src = pkgs.lib.cleanSource ../.;
cargoLock.lockFile = ../Cargo.lock; cargoLock.lockFile = ../Cargo.lock;
nativeBuildInputs = [pkgs.upx];
useNextest = true; useNextest = true;
meta = { meta = {
description = "Conventional commits for Jujutsu"; inherit (cargoToml.package) description homepage;
homepage = "https://labs.phundrak.com/phundrak/jj-cz";
}; };
postBuild = '' postBuild = ''
${pkgs.upx}/bin/upx target/*/release/${name} ${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 { in {
default = rustBuild; default = nativeBuild;
windows = windowsBuild;
} }