diff --git a/flake.lock b/flake.lock index 215a6a93..68c9f694 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1722141560, - "narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=", + "lastModified": 1722415718, + "narHash": "sha256-5US0/pgxbMksF92k1+eOa8arJTJiPvsdZj9Dl+vJkM4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160", + "rev": "c3392ad349a5227f4a3464dce87bcc5046692fce", "type": "github" }, "original": { @@ -48,11 +48,11 @@ ] }, "locked": { - "lastModified": 1722133294, - "narHash": "sha256-XKSVN+lmjVEFPjMa5Ui0VTay2Uvqa74h0MQT0HU1pqw=", + "lastModified": 1722391647, + "narHash": "sha256-JTi7l1oxnatF1uX/gnGMlRnyFMtylRw4MqhCUdoN2K4=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "9803f6e04ca37a2c072783e8297d2080f8d0e739", + "rev": "0fd4a5d2098faa516a9b83022aec7db766cd1de8", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 9daddfc3..c6a11b0a 100644 --- a/flake.nix +++ b/flake.nix @@ -4,10 +4,7 @@ flake-utils.url = "github:numtide/flake-utils"; rust-overlay = { url = "github:oxalica/rust-overlay"; - inputs = { - nixpkgs.follows = "nixpkgs"; - flake-utils.follows = "flake-utils"; - }; + inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -15,47 +12,56 @@ { self, nixpkgs, - flake-utils, rust-overlay, + flake-utils, ... - }@inputs: - let - # Nixpkgs overlays - overlays = [ - rust-overlay.overlays.default - (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"; + pkgs = import nixpkgs { + inherit system; + overlays = [ + rust-overlay.overlays.default + ( + final: prev: + let + toolchain = final.rust-bin.stable.latest.default; + in + { + rustPlatform = prev.makeRustPlatform { + cargo = toolchain; + rustc = toolchain; + }; + } + ) + ]; + }; + + rev = self.shortRev or self.dirtyShortRev 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 (self.packages.${system}) yazi-unwrapped; }; + default = self.packages.${system}.yazi; + }; + + devShells = { + default = pkgs.callPackage ./nix/shell.nix { }; }; formatter = pkgs.nixfmt-rfc-style; - - devShells.default = import ./nix/shell.nix { inherit pkgs inputs; }; } ) // { - overlays = rec { - default = yazi; - yazi = final: _: { inherit (self.packages."${final.system}") yazi yazi-unwrapped; }; + overlays = { + default = self.overlays.yazi; + yazi = _: prev: { inherit (self.packages.${prev.stdenv.system}) yazi yazi-unwrapped; }; }; }; } diff --git a/nix/shell.nix b/nix/shell.nix index 3f3a4782..a6750e43 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -1,28 +1,24 @@ -{ pkgs, ... }: - -pkgs.mkShell { - packages = with pkgs; [ - rustToolchain - rust-analyzer +{ + callPackage, + rust-bin, + nodePackages, +}: +let + mainPkg = callPackage ./yazi.nix { }; +in +mainPkg.overrideAttrs (oa: { + nativeBuildInputs = [ + (rust-bin.stable.latest.default.override { + extensions = [ + "rust-src" + "rustfmt" + "rust-analyzer" + "clippy" + ]; + }) nodePackages.cspell + ] ++ (oa.nativeBuildInputs or [ ]); - file - jq - poppler_utils - unar - ffmpegthumbnailer - fd - ripgrep - fzf - zoxide - ]; - - 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 3dff3206..587dbdb2 100644 --- a/nix/yazi-unwrapped.nix +++ b/nix/yazi-unwrapped.nix @@ -1,67 +1,74 @@ { - makeRustPlatform, - rustToolchain, + rustPlatform, version ? "git", - rev, - date, + rev ? "unknown", + date ? "19700101", lib, installShellFiles, stdenv, darwin, + rust-jemalloc-sys, imagemagick, }: - -(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 +let + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.unions [ + ../assets + ../Cargo.toml + ../Cargo.lock + (lib.fileset.fromSource (lib.sources.sourceByRegex ../. [ "^yazi-.*" ])) ]; - buildInputs = lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Foundation ]); + }; +in +rustPlatform.buildRustPackage rec { + pname = "yazi"; + inherit version src; - 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 = { - 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"; + cargoLock = { + lockFile = "${src}/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 = [ + rust-jemalloc-sys + ] ++ 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 = { + 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 d71a2bf8..5a1eac9c 100644 --- a/nix/yazi.nix +++ b/nix/yazi.nix @@ -1,41 +1,89 @@ { lib, + formats, runCommand, makeWrapper, + + extraPackages ? [ ], + optionalDeps ? [ + jq + poppler_utils + unar + ffmpegthumbnailer + fd + ripgrep + fzf + zoxide + ], + + # deps + file, yazi-unwrapped, - withFile ? true, - file, - withJq ? true, + # optional deps jq, - withPoppler ? true, poppler_utils, - withUnar ? true, unar, - withFfmpegthumbnailer ? true, ffmpegthumbnailer, - withFd ? true, fd, - withRipgrep ? true, ripgrep, - withFzf ? true, fzf, - withZoxide ? true, zoxide, -}: + settings ? { }, + plugins ? { }, + flavors ? { }, + initLua ? null, +}: let - inherit (lib) optional makeBinPath; - 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; + inherit (lib) + concatStringsSep + concatMapStringsSep + optionalString + makeBinPath + mapAttrsToList + ; + + runtimePaths = [ file ] ++ optionalDeps ++ extraPackages; + + settingsFormat = formats.toml { }; + + files = [ + "yazi" + "theme" + "keymap" + ]; + + configHome = + if (settings == { } && initLua == null && plugins == { } && flavors == { }) then + null + else + runCommand "YAZI_CONFIG_HOME" { } '' + mkdir -p $out + ${concatMapStringsSep "\n" ( + name: + optionalString (settings ? ${name} && settings.${name} != { }) '' + ln -s ${settingsFormat.generate "${name}.toml" settings.${name}} $out/${name}.toml + '' + ) files} + + mkdir $out/plugins + ${optionalString (plugins != { }) '' + ${concatStringsSep "\n" ( + mapAttrsToList (name: value: "ln -s ${value} $out/plugins/${name}") plugins + )} + ''} + + mkdir $out/flavors + ${optionalString (flavors != { }) '' + ${concatStringsSep "\n" ( + mapAttrsToList (name: value: "ln -s ${value} $out/flavors/${name}") flavors + )} + ''} + + + ${optionalString (initLua != null) "ln -s ${initLua} $out/init.lua"} + ''; in runCommand yazi-unwrapped.name { @@ -48,5 +96,6 @@ runCommand yazi-unwrapped.name 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}" + --prefix PATH : "${makeBinPath runtimePaths}" \ + ${optionalString (configHome != null) "--set YAZI_CONFIG_HOME ${configHome}"} ''