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

Co-authored-by: Isabel <isabel@isabelroses.com>
This commit is contained in:
uncenter 2024-07-31 23:01:07 -04:00 committed by GitHub
parent bb29e238b5
commit c7b002581a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 128 additions and 112 deletions

View file

@ -11,26 +11,31 @@
}; };
}; };
outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }@inputs: outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
...
}@inputs:
let let
# Nixpkgs overlays # Nixpkgs overlays
overlays = [ overlays = [
rust-overlay.overlays.default rust-overlay.overlays.default
(final: prev: { (final: _: {
rustToolchain = final.rust-bin.stable.latest.default.override { rustToolchain = final.rust-bin.stable.latest.default.override { extensions = [ "rust-src" ]; };
extensions = [ "rust-src" ];
};
}) })
]; ];
in in
flake-utils.lib.eachDefaultSystem flake-utils.lib.eachDefaultSystem (
(system: system:
let let
pkgs = import nixpkgs { inherit system overlays; }; pkgs = import nixpkgs { inherit system overlays; };
rev = self.shortRev or "dirty"; rev = self.shortRev or "dirty";
date = (self.lastModifiedDate or self.lastModified or "19700101"); date = self.lastModifiedDate or self.lastModified or "19700101";
version = (builtins.fromTOML version =
(builtins.readFile ./yazi-fm/Cargo.toml)).package.version (builtins.fromTOML (builtins.readFile ./yazi-fm/Cargo.toml)).package.version
+ "pre${builtins.substring 0 8 date}_${rev}"; + "pre${builtins.substring 0 8 date}_${rev}";
yazi-unwrapped = pkgs.callPackage ./nix/yazi-unwrapped.nix { inherit version rev date; }; yazi-unwrapped = pkgs.callPackage ./nix/yazi-unwrapped.nix { inherit version rev date; };
@ -42,17 +47,15 @@
default = 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 { overlays = rec {
default = yazi; default = yazi;
yazi = final: prev: { yazi = final: _: { inherit (self.packages."${final.system}") yazi yazi-unwrapped; };
yazi-unwrapped = self.packages."${final.system}".yazi-unwrapped;
yazi = self.packages."${final.system}".yazi;
};
}; };
}; };
} }

View file

@ -18,9 +18,11 @@ pkgs.mkShell {
zoxide zoxide
]; ];
buildInputs = with pkgs; buildInputs =
lib.optionals stdenv.isDarwin with pkgs;
(with darwin.apple_sdk.frameworks; [ Foundation ]); lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Foundation ]);
env = { RUST_BACKTRACE = "1"; }; env = {
RUST_BACKTRACE = "1";
};
} }

View file

@ -1,20 +1,25 @@
{ makeRustPlatform {
, rustToolchain makeRustPlatform,
, version ? "git" rustToolchain,
, rev version ? "git",
, date rev,
, lib date,
lib,
, installShellFiles installShellFiles,
, stdenv stdenv,
, darwin darwin,
, imagemagick imagemagick,
}: }:
(makeRustPlatform { cargo = rustToolchain; rustc = rustToolchain; }).buildRustPackage rec { (makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
}).buildRustPackage
{
pname = "yazi"; pname = "yazi";
inherit version rev; inherit version;
src = ../.; src = ../.;
@ -25,14 +30,17 @@
}; };
}; };
env.YAZI_GEN_COMPLETIONS = true; env = {
env.VERGEN_GIT_SHA = rev; YAZI_GEN_COMPLETIONS = true;
env.VERGEN_BUILD_DATE = builtins.concatStringsSep "-" (builtins.match "(.{4})(.{2})(.{2}).*" date); VERGEN_GIT_SHA = rev;
VERGEN_BUILD_DATE = builtins.concatStringsSep "-" (builtins.match "(.{4})(.{2})(.{2}).*" date);
};
nativeBuildInputs = [ installShellFiles imagemagick ]; nativeBuildInputs = [
buildInputs = lib.optionals stdenv.isDarwin ( installShellFiles
with darwin.apple_sdk.frameworks; [ Foundation ] imagemagick
); ];
buildInputs = lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Foundation ]);
postInstall = '' postInstall = ''
installShellCompletion --cmd yazi \ installShellCompletion --cmd yazi \
@ -50,10 +58,10 @@
install -m644 assets/yazi.desktop $out/share/applications/ install -m644 assets/yazi.desktop $out/share/applications/
''; '';
meta = with lib; { meta = {
description = "Blazing fast terminal file manager written in Rust, based on async I/O"; description = "Blazing fast terminal file manager written in Rust, based on async I/O";
homepage = "https://github.com/sxyazi/yazi"; homepage = "https://github.com/sxyazi/yazi";
license = licenses.mit; license = lib.licenses.mit;
mainProgram = "yazi"; mainProgram = "yazi";
}; };
} }

View file

@ -1,31 +1,33 @@
{ lib {
, runCommand lib,
, makeWrapper runCommand,
, yazi-unwrapped makeWrapper,
yazi-unwrapped,
, withFile ? true withFile ? true,
, file file,
, withJq ? true withJq ? true,
, jq jq,
, withPoppler ? true withPoppler ? true,
, poppler_utils poppler_utils,
, withUnar ? true withUnar ? true,
, unar unar,
, withFfmpegthumbnailer ? true withFfmpegthumbnailer ? true,
, ffmpegthumbnailer ffmpegthumbnailer,
, withFd ? true withFd ? true,
, fd fd,
, withRipgrep ? true withRipgrep ? true,
, ripgrep ripgrep,
, withFzf ? true withFzf ? true,
, fzf fzf,
, withZoxide ? true withZoxide ? true,
, zoxide zoxide,
}: }:
let let
runtimePaths = with lib; [ ] inherit (lib) optional makeBinPath;
++ optional withFile file runtimePaths =
optional withFile file
++ optional withJq jq ++ optional withJq jq
++ optional withPoppler poppler_utils ++ optional withPoppler poppler_utils
++ optional withUnar unar ++ optional withUnar unar
@ -40,10 +42,11 @@ runCommand yazi-unwrapped.name
inherit (yazi-unwrapped) pname version meta; inherit (yazi-unwrapped) pname version meta;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
} '' }
''
mkdir -p $out/bin mkdir -p $out/bin
ln -s ${yazi-unwrapped}/share $out/share ln -s ${yazi-unwrapped}/share $out/share
ln -s ${yazi-unwrapped}/bin/ya $out/bin/ya ln -s ${yazi-unwrapped}/bin/ya $out/bin/ya
makeWrapper ${yazi-unwrapped}/bin/yazi $out/bin/yazi \ makeWrapper ${yazi-unwrapped}/bin/yazi $out/bin/yazi \
--prefix PATH : "${lib.makeBinPath runtimePaths}" --prefix PATH : "${makeBinPath runtimePaths}"
'' ''