feat: support yazi-cli for Nix flake (#944)

This commit is contained in:
XYenon 2024-04-24 17:44:04 +08:00 committed by GitHub
parent c65a14c0e6
commit 8fc8770c28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 94 additions and 72 deletions

View file

@ -1,7 +1,7 @@
[workspace]
resolver = "2"
members = [ "yazi-*" ]
default-members = [ "yazi-fm" ]
default-members = [ "yazi-fm", "yazi-cli" ]
[profile.release]
codegen-units = 1

18
flake.lock generated
View file

@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1701174899,
"narHash": "sha256-1W+FMe8mWsJKXoBc+QgKmEeRj33kTFnPq7XCjU+bfnA=",
"lastModified": 1713805509,
"narHash": "sha256-YgSEan4CcrjivCNO5ZNzhg7/8ViLkZ4CB/GrGBVSudo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "010c7296f3b19a58b206fdf7d68d75a5b0a09e9e",
"rev": "1e1dc66fe68972a76679644a5577828b6a7e8be4",
"type": "github"
},
"original": {
@ -51,11 +51,11 @@
]
},
"locked": {
"lastModified": 1701224160,
"narHash": "sha256-qnMmxNMKmd6Soel0cfauyMJ+LzuZbvmiDQPSIuTbQ+M=",
"lastModified": 1713924823,
"narHash": "sha256-kOeyS3GFwgnKvzuBMmFqEAX0xwZ7Nj4/5tXuvpZ0d4U=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "4a080e26d55eaedb95ab1bf8eeaeb84149c10f12",
"rev": "8a2edac3ae926a2a6ce60f4595dcc4540fc8cad4",
"type": "github"
},
"original": {

View file

@ -34,11 +34,15 @@
version = (builtins.fromTOML
(builtins.readFile ./yazi-fm/Cargo.toml)).package.version
+ versionSuffix;
yazi = pkgs.callPackage ./nix/yazi.nix { inherit version; };
yazi-unwrapped = pkgs.callPackage ./nix/yazi-unwrapped.nix { inherit version; };
yazi = pkgs.callPackage ./nix/yazi.nix { inherit yazi-unwrapped; };
in
{
packages.default = yazi;
packages.yazi = yazi;
packages = {
inherit yazi-unwrapped yazi;
default = yazi;
};
formatter = pkgs.nixpkgs-fmt;
@ -48,6 +52,7 @@
overlays = rec {
default = yazi;
yazi = final: prev: {
yazi-unwrapped = self.packages."${final.system}".yazi-unwrapped;
yazi = self.packages."${final.system}".yazi;
};
};

50
nix/yazi-unwrapped.nix Normal file
View file

@ -0,0 +1,50 @@
{ makeRustPlatform
, rustToolchain
, version ? "git"
, lib
, installShellFiles
, stdenv
, darwin
, imagemagick
}:
(makeRustPlatform { cargo = rustToolchain; rustc = rustToolchain; }).buildRustPackage rec {
pname = "yazi";
inherit version;
src = ../.;
cargoLock.lockFile = ../Cargo.lock;
env.YAZI_GEN_COMPLETIONS = true;
nativeBuildInputs = [ installShellFiles imagemagick ];
buildInputs = lib.optionals stdenv.isDarwin (
with darwin.apple_sdk.frameworks; [ Foundation ]
);
postInstall = ''
installShellCompletion --cmd yazi \
--bash ./yazi-boot/completions/yazi.bash \
--fish ./yazi-boot/completions/yazi.fish \
--zsh ./yazi-boot/completions/_yazi
# Resize logo
for RES in 16 24 32 48 64 128 256; do
mkdir -p $out/share/icons/hicolor/"$RES"x"$RES"/apps
convert assets/logo.png -resize "$RES"x"$RES" $out/share/icons/hicolor/"$RES"x"$RES"/apps/yazi.png
done
mkdir -p $out/share/applications
install -m644 assets/yazi.desktop $out/share/applications/
'';
meta = with lib; {
description = "Blazing fast terminal file manager written in Rust, based on async I/O";
homepage = "https://github.com/sxyazi/yazi";
license = licenses.mit;
mainProgram = "yazi";
};
}

View file

@ -1,12 +1,7 @@
{ makeRustPlatform
, rustToolchain
, version ? "git"
, lib
{ lib
, runCommand
, makeWrapper
, installShellFiles
, stdenv
, darwin
, yazi-unwrapped
, withFile ? true
, file
@ -26,57 +21,29 @@
, fzf
, withZoxide ? true
, zoxide
, imagemagick
}:
(makeRustPlatform { cargo = rustToolchain; rustc = rustToolchain; }).buildRustPackage {
pname = "yazi";
inherit version;
let
runtimePaths = with lib; [ ]
++ optional withFile file
++ optional withJq jq
++ optional withPoppler poppler_utils
++ optional withUnar unar
++ optional withFfmpegthumbnailer ffmpegthumbnailer
++ optional withFd fd
++ optional withRipgrep ripgrep
++ optional withFzf fzf
++ optional withZoxide zoxide;
in
runCommand yazi-unwrapped.name
{
inherit (yazi-unwrapped) pname version meta;
src = ../.;
YAZI_GEN_COMPLETIONS = true;
cargoLock.lockFile = ../Cargo.lock;
nativeBuildInputs = [ makeWrapper installShellFiles imagemagick ];
buildInputs = lib.optionals stdenv.isDarwin (
with darwin.apple_sdk.frameworks; [ Foundation ]
);
postInstall = with lib;
let
runtimePaths = [ ]
++ optional withFile file
++ optional withJq jq
++ optional withPoppler poppler_utils
++ optional withUnar unar
++ optional withFfmpegthumbnailer ffmpegthumbnailer
++ optional withFd fd
++ optional withRipgrep ripgrep
++ optional withFzf fzf
++ optional withZoxide zoxide;
in
''
wrapProgram $out/bin/yazi \
--prefix PATH : "${makeBinPath runtimePaths}"
installShellCompletion --cmd yazi \
--bash ./yazi-boot/completions/yazi.bash \
--fish ./yazi-boot/completions/yazi.fish \
--zsh ./yazi-boot/completions/_yazi
# Resize logo
for RES in 16 24 32 48 64 128 256; do
mkdir -p $out/share/icons/hicolor/"$RES"x"$RES"/apps
convert assets/logo.png -resize "$RES"x"$RES" $out/share/icons/hicolor/"$RES"x"$RES"/apps/yazi.png
done
mkdir -p $out/share/applications
install -m644 assets/yazi.desktop $out/share/applications/
'';
meta = with lib; {
description = "Blazing fast terminal file manager written in Rust, based on async I/O";
homepage = "https://github.com/sxyazi/yazi";
license = licenses.mit;
};
}
nativeBuildInputs = [ makeWrapper ];
} ''
mkdir -p $out/bin
ln -s ${yazi-unwrapped}/share $out/share
ln -s ${yazi-unwrapped}/bin/ya $out/bin/ya
makeWrapper ${yazi-unwrapped}/bin/yazi $out/bin/yazi \
--prefix PATH : "${lib.makeBinPath runtimePaths}"
''