Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(nix): cleanup and switch to nixfmt-rfc-style #1376

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,51 @@
};
};

outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }@inputs:
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
...
}@inputs:
let
# Nixpkgs overlays
overlays = [
rust-overlay.overlays.default
(final: prev: {
rustToolchain = final.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
};
(final: _: {
rustToolchain = final.rust-bin.stable.latest.default.override { extensions = [ "rust-src" ]; };
})
];
in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system overlays; };
rev = self.shortRev or "dirty";
date = (self.lastModifiedDate or self.lastModified or "19700101");
version = (builtins.fromTOML
(builtins.readFile ./yazi-fm/Cargo.toml)).package.version
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system overlays; };
rev = self.shortRev or "dirty";
date = self.lastModifiedDate or self.lastModified or "19700101";
version =
(builtins.fromTOML (builtins.readFile ./yazi-fm/Cargo.toml)).package.version
+ "pre${builtins.substring 0 8 date}_${rev}";

yazi-unwrapped = pkgs.callPackage ./nix/yazi-unwrapped.nix { inherit version rev date; };
yazi = pkgs.callPackage ./nix/yazi.nix { inherit yazi-unwrapped; };
in
{
packages = {
inherit yazi-unwrapped yazi;
default = yazi;
};
yazi-unwrapped = pkgs.callPackage ./nix/yazi-unwrapped.nix { inherit version rev date; };
yazi = pkgs.callPackage ./nix/yazi.nix { inherit yazi-unwrapped; };
in
{
packages = {
inherit yazi-unwrapped yazi;
default = yazi;
};

formatter = pkgs.nixpkgs-fmt;
formatter = pkgs.nixfmt-rfc-style;

devShells.default = import ./nix/shell.nix { inherit pkgs inputs; };
})
devShells.default = import ./nix/shell.nix { inherit pkgs inputs; };
}
)
// {
overlays = rec {
default = yazi;
yazi = final: prev: {
yazi-unwrapped = self.packages."${final.system}".yazi-unwrapped;
yazi = self.packages."${final.system}".yazi;
};
yazi = final: _: { inherit (self.packages."${final.system}") yazi yazi-unwrapped; };
};
};
}
10 changes: 6 additions & 4 deletions nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ pkgs.mkShell {
zoxide
];

buildInputs = with pkgs;
lib.optionals stdenv.isDarwin
(with darwin.apple_sdk.frameworks; [ Foundation ]);
buildInputs =
with pkgs;
lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Foundation ]);

env = { RUST_BACKTRACE = "1"; };
env = {
RUST_BACKTRACE = "1";
};
}
116 changes: 62 additions & 54 deletions nix/yazi-unwrapped.nix
Original file line number Diff line number Diff line change
@@ -1,59 +1,67 @@
{ makeRustPlatform
, rustToolchain
, version ? "git"
, rev
, date
, lib

, installShellFiles
, stdenv
, darwin

, imagemagick
{
makeRustPlatform,
rustToolchain,
version ? "git",
rev,
date,
lib,

installShellFiles,
stdenv,
darwin,

imagemagick,
}:

(makeRustPlatform { cargo = rustToolchain; rustc = rustToolchain; }).buildRustPackage rec {
pname = "yazi";
inherit version rev;
(makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
}).buildRustPackage
{
pname = "yazi";
inherit version;

src = ../.;

cargoLock = {
lockFile = ../Cargo.lock;
outputHashes = {
"notify-6.1.1" = "sha256-5Ft2yvRPi2EaErcGBkF/3Xv6K7ijFGbdjmSqI4go/h4=";
};
};

env = {
YAZI_GEN_COMPLETIONS = true;
VERGEN_GIT_SHA = rev;
VERGEN_BUILD_DATE = builtins.concatStringsSep "-" (builtins.match "(.{4})(.{2})(.{2}).*" date);
};

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
magick assets/logo.png -resize "$RES"x"$RES" $out/share/icons/hicolor/"$RES"x"$RES"/apps/yazi.png
done

src = ../.;
mkdir -p $out/share/applications
install -m644 assets/yazi.desktop $out/share/applications/
'';

cargoLock = {
lockFile = ../Cargo.lock;
outputHashes = {
"notify-6.1.1" = "sha256-5Ft2yvRPi2EaErcGBkF/3Xv6K7ijFGbdjmSqI4go/h4=";
meta = {
description = "Blazing fast terminal file manager written in Rust, based on async I/O";
homepage = "https://github.com/sxyazi/yazi";
license = lib.licenses.mit;
mainProgram = "yazi";
};
};

env.YAZI_GEN_COMPLETIONS = true;
env.VERGEN_GIT_SHA = rev;
env.VERGEN_BUILD_DATE = builtins.concatStringsSep "-" (builtins.match "(.{4})(.{2})(.{2}).*" date);

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
magick 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";
};
}
}
71 changes: 37 additions & 34 deletions nix/yazi.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
{ lib
, runCommand
, makeWrapper
, yazi-unwrapped
{
lib,
runCommand,
makeWrapper,
yazi-unwrapped,

, withFile ? true
, file
, withJq ? true
, jq
, withPoppler ? true
, poppler_utils
, withUnar ? true
, unar
, withFfmpegthumbnailer ? true
, ffmpegthumbnailer
, withFd ? true
, fd
, withRipgrep ? true
, ripgrep
, withFzf ? true
, fzf
, withZoxide ? true
, zoxide
withFile ? true,
file,
withJq ? true,
jq,
withPoppler ? true,
poppler_utils,
withUnar ? true,
unar,
withFfmpegthumbnailer ? true,
ffmpegthumbnailer,
withFd ? true,
fd,
withRipgrep ? true,
ripgrep,
withFzf ? true,
fzf,
withZoxide ? true,
zoxide,
}:

let
runtimePaths = with lib; [ ]
++ optional withFile file
inherit (lib) optional makeBinPath;
runtimePaths =
optional withFile file
++ optional withJq jq
++ optional withPoppler poppler_utils
++ optional withUnar unar
Expand All @@ -36,14 +38,15 @@ let
++ optional withZoxide zoxide;
in
runCommand yazi-unwrapped.name
{
inherit (yazi-unwrapped) pname version meta;
{
inherit (yazi-unwrapped) pname version meta;

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}"
''
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 : "${makeBinPath runtimePaths}"
''