From c7b002581a14f870a6d36292766e185ebad43b51 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:01:07 -0400 Subject: [PATCH] refactor(nix): cleanup and switch to `nixfmt-rfc-style` (#1376) Co-authored-by: Isabel --- flake.nix | 59 ++++++++++++------------ nix/shell.nix | 10 +++-- nix/yazi-unwrapped.nix | 100 ++++++++++++++++++++++------------------- nix/yazi.nix | 71 +++++++++++++++-------------- 4 files changed, 128 insertions(+), 112 deletions(-) diff --git a/flake.nix b/flake.nix index 94ba0378..9daddfc3 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; }; }; } diff --git a/nix/shell.nix b/nix/shell.nix index 42d6ddf8..3f3a4782 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -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"; + }; } diff --git a/nix/yazi-unwrapped.nix b/nix/yazi-unwrapped.nix index c1d7db1a..3dff3206 100644 --- a/nix/yazi-unwrapped.nix +++ b/nix/yazi-unwrapped.nix @@ -1,59 +1,67 @@ -{ makeRustPlatform -, rustToolchain -, version ? "git" -, rev -, date -, lib +{ + makeRustPlatform, + rustToolchain, + version ? "git", + rev, + date, + lib, -, installShellFiles -, stdenv -, darwin + installShellFiles, + stdenv, + darwin, -, imagemagick + imagemagick, }: -(makeRustPlatform { cargo = rustToolchain; rustc = rustToolchain; }).buildRustPackage rec { - pname = "yazi"; - inherit version rev; +(makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; +}).buildRustPackage + { + pname = "yazi"; + inherit version; - src = ../.; + src = ../.; - cargoLock = { - lockFile = ../Cargo.lock; - outputHashes = { - "notify-6.1.1" = "sha256-5Ft2yvRPi2EaErcGBkF/3Xv6K7ijFGbdjmSqI4go/h4="; + cargoLock = { + lockFile = ../Cargo.lock; + outputHashes = { + "notify-6.1.1" = "sha256-5Ft2yvRPi2EaErcGBkF/3Xv6K7ijFGbdjmSqI4go/h4="; + }; }; - }; - env.YAZI_GEN_COMPLETIONS = true; - env.VERGEN_GIT_SHA = rev; - env.VERGEN_BUILD_DATE = builtins.concatStringsSep "-" (builtins.match "(.{4})(.{2})(.{2}).*" date); + 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 ] - ); + 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 + 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 + # 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/ - ''; + 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"; - }; -} + 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"; + }; + } diff --git a/nix/yazi.nix b/nix/yazi.nix index 3df2fe93..d71a2bf8 100644 --- a/nix/yazi.nix +++ b/nix/yazi.nix @@ -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 @@ -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}" + ''