From b9639eb49c590709dbda6a535c3fbc2c0afe020b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Mon, 28 Jul 2025 12:11:02 +0200 Subject: [PATCH] packages: refactor cargo rust packages --- nix/packages/by-name/audio-lint/package.nix | 10 ++-- .../by-name/emoji-picker-rs/package.nix | 3 +- nix/packages/by-name/tokei/package.nix | 51 ++++++++++--------- .../by-name/typst-mutilate/package.nix | 12 +++-- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/nix/packages/by-name/audio-lint/package.nix b/nix/packages/by-name/audio-lint/package.nix index 5c736f76..5f95c4aa 100644 --- a/nix/packages/by-name/audio-lint/package.nix +++ b/nix/packages/by-name/audio-lint/package.nix @@ -1,11 +1,13 @@ { - lib, rustPlatform, fetchFromGitea, }: -rustPlatform.buildRustPackage (finalAttrs: { +rustPlatform.buildRustPackage (finalAttrs: let + cargoToml = fromTOML (builtins.readFile (finalAttrs.src + "/Cargo.toml")); + cargoLock = finalAttrs.src + "/Cargo.lock"; +in { pname = "audio-lint"; - version = lib.substring 0 8 finalAttrs.src.rev; + version = cargoToml.package.version; src = fetchFromGitea { domain = "git.confusedcompiler.org"; @@ -15,5 +17,5 @@ rustPlatform.buildRustPackage (finalAttrs: { hash = "sha256-h1SnWAh3FPL5GweOXVXXtp+swZApgecYaWjy7rM/J+w="; }; - cargoHash = "sha256-daaNDuxS/mbADCk4X+ZOrzEeu2vrQj1gDJ9y9bMihSk="; + cargoLock.lockFile = cargoLock; }) diff --git a/nix/packages/by-name/emoji-picker-rs/package.nix b/nix/packages/by-name/emoji-picker-rs/package.nix index 33287e34..f77dd4cf 100644 --- a/nix/packages/by-name/emoji-picker-rs/package.nix +++ b/nix/packages/by-name/emoji-picker-rs/package.nix @@ -8,6 +8,7 @@ }: rustPlatform.buildRustPackage (finalAttrs: let cargoToml = fromTOML (builtins.readFile (finalAttrs.src + "/Cargo.toml")); + cargoLock = finalAttrs.src + "/Cargo.lock"; in { pname = "emoji-picker"; version = cargoToml.package.version; @@ -19,7 +20,7 @@ in { hash = "sha256-ETZRqyQ5lzYA6NGOXLnxfpwb4qMMC1l7s5XA8H5s9Jw="; }; - cargoHash = "sha256-rJKFRWaqulnan2jtt0erj5cypSBe0Z5PiNcOXd3HCZs="; + cargoLock.lockFile = cargoLock; nativeBuildInputs = [ python3 diff --git a/nix/packages/by-name/tokei/package.nix b/nix/packages/by-name/tokei/package.nix index 7af4eebe..12f4080c 100644 --- a/nix/packages/by-name/tokei/package.nix +++ b/nix/packages/by-name/tokei/package.nix @@ -6,34 +6,35 @@ libiconv, darwin, zlib, -}: let - rev = "v13.0.0-alpha.8"; -in - rustPlatform.buildRustPackage { - pname = "tokei"; - version = rev; +}: +rustPlatform.buildRustPackage (finalAttrs: let + cargoToml = fromTOML (builtins.readFile (finalAttrs.src + "/Cargo.toml")); + cargoLock = finalAttrs.src + "/Cargo.lock"; +in { + pname = "tokei"; + version = cargoToml.package.version; - src = fetchFromGitHub { - owner = "XAMPPRocky"; - repo = "tokei"; - inherit rev; - hash = "sha256-jCI9VM3y76RI65E5UGuAPuPkDRTMyi+ydx64JWHcGfE="; - }; + src = fetchFromGitHub { + owner = "XAMPPRocky"; + repo = "tokei"; + rev = "v13.0.0-alpha.8"; + hash = "sha256-jCI9VM3y76RI65E5UGuAPuPkDRTMyi+ydx64JWHcGfE="; + }; - cargoHash = "sha256-LzlyrKaRjUo6JnVLQnHidtI4OWa+GrhAc4D8RkL+nmQ="; + cargoLock.lockFile = cargoLock; - patches = [ - ./skel.patch - ./why3.patch - ]; + patches = [ + ./skel.patch + ./why3.patch + ]; - buildInputs = lib.optionals stdenv.isDarwin [ - libiconv - darwin.Security - ]; + buildInputs = lib.optionals stdenv.isDarwin [ + libiconv + darwin.Security + ]; - checkInputs = lib.optionals stdenv.isDarwin [zlib]; + checkInputs = lib.optionals stdenv.isDarwin [zlib]; - # enable all output formats - buildFeatures = ["all"]; - } + # enable all output formats + buildFeatures = ["all"]; +}) diff --git a/nix/packages/by-name/typst-mutilate/package.nix b/nix/packages/by-name/typst-mutilate/package.nix index b5e53be3..1b11b08e 100644 --- a/nix/packages/by-name/typst-mutilate/package.nix +++ b/nix/packages/by-name/typst-mutilate/package.nix @@ -3,8 +3,12 @@ fetchFromGitHub, fetchpatch, }: -rustPlatform.buildRustPackage { - name = "typst-mutilate"; +rustPlatform.buildRustPackage (finalAttrs: let + cargoToml = fromTOML (builtins.readFile (finalAttrs.src + "/Cargo.toml")); + cargoLock = finalAttrs.src + "/Cargo.lock"; +in { + pname = "typst-mutilate"; + version = cargoToml.package.version; src = fetchFromGitHub { owner = "frozolotl"; @@ -13,7 +17,7 @@ rustPlatform.buildRustPackage { hash = "sha256-r4fkFv1np8xhff3m8yev1rU1vfKRz8zQMIKIc+fOjew="; }; - cargoHash = "sha256-QEOXPf/k+fCMNQxKGsW3FDsgH5XXUKob0XOef3DiB0s="; + cargoLock.lockFile = cargoLock; patches = [ (fetchpatch { @@ -22,4 +26,4 @@ rustPlatform.buildRustPackage { hash = "sha256-+6DMQo4cjVASgkX4gcYrEkwQ/uxttV/61fDnXBqbNcg="; }) ]; -} +})