refactor(nix): home keeping (#1380)

This commit is contained in:
Isabel 2024-08-08 15:18:01 +01:00 committed by GitHub
parent 407ad266e9
commit e02b030258
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 193 additions and 135 deletions

12
flake.lock generated
View file

@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1722141560, "lastModified": 1722415718,
"narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=", "narHash": "sha256-5US0/pgxbMksF92k1+eOa8arJTJiPvsdZj9Dl+vJkM4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160", "rev": "c3392ad349a5227f4a3464dce87bcc5046692fce",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -48,11 +48,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722133294, "lastModified": 1722391647,
"narHash": "sha256-XKSVN+lmjVEFPjMa5Ui0VTay2Uvqa74h0MQT0HU1pqw=", "narHash": "sha256-JTi7l1oxnatF1uX/gnGMlRnyFMtylRw4MqhCUdoN2K4=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "9803f6e04ca37a2c072783e8297d2080f8d0e739", "rev": "0fd4a5d2098faa516a9b83022aec7db766cd1de8",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -4,10 +4,7 @@
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
rust-overlay = { rust-overlay = {
url = "github:oxalica/rust-overlay"; url = "github:oxalica/rust-overlay";
inputs = { inputs.nixpkgs.follows = "nixpkgs";
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
}; };
}; };
@ -15,47 +12,56 @@
{ {
self, self,
nixpkgs, nixpkgs,
flake-utils,
rust-overlay, 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 ( flake-utils.lib.eachDefaultSystem (
system: system:
let let
pkgs = import nixpkgs { inherit system overlays; }; pkgs = import nixpkgs {
rev = self.shortRev or "dirty"; 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"; date = self.lastModifiedDate or self.lastModified or "19700101";
version = version =
(builtins.fromTOML (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 = pkgs.callPackage ./nix/yazi.nix { inherit yazi-unwrapped; };
in in
{ {
packages = { packages = {
inherit yazi-unwrapped yazi; yazi-unwrapped = pkgs.callPackage ./nix/yazi-unwrapped.nix { inherit version rev date; };
default = yazi; 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; formatter = pkgs.nixfmt-rfc-style;
devShells.default = import ./nix/shell.nix { inherit pkgs inputs; };
} }
) )
// { // {
overlays = rec { overlays = {
default = yazi; default = self.overlays.yazi;
yazi = final: _: { inherit (self.packages."${final.system}") yazi yazi-unwrapped; }; yazi = _: prev: { inherit (self.packages.${prev.stdenv.system}) yazi yazi-unwrapped; };
}; };
}; };
} }

View file

@ -1,28 +1,24 @@
{ pkgs, ... }: {
callPackage,
pkgs.mkShell { rust-bin,
packages = with pkgs; [ nodePackages,
rustToolchain }:
rust-analyzer 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 nodePackages.cspell
] ++ (oa.nativeBuildInputs or [ ]);
file env.RUST_BACKTRACE = "1";
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";
};
}

View file

@ -1,67 +1,74 @@
{ {
makeRustPlatform, rustPlatform,
rustToolchain,
version ? "git", version ? "git",
rev, rev ? "unknown",
date, date ? "19700101",
lib, lib,
installShellFiles, installShellFiles,
stdenv, stdenv,
darwin, darwin,
rust-jemalloc-sys,
imagemagick, imagemagick,
}: }:
let
(makeRustPlatform { src = lib.fileset.toSource {
cargo = rustToolchain; root = ../.;
rustc = rustToolchain; fileset = lib.fileset.unions [
}).buildRustPackage ../assets
{ ../Cargo.toml
pname = "yazi"; ../Cargo.lock
inherit version; (lib.fileset.fromSource (lib.sources.sourceByRegex ../. [ "^yazi-.*" ]))
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 ]); };
in
rustPlatform.buildRustPackage rec {
pname = "yazi";
inherit version src;
postInstall = '' cargoLock = {
installShellCompletion --cmd yazi \ lockFile = "${src}/Cargo.lock";
--bash ./yazi-boot/completions/yazi.bash \ outputHashes = {
--fish ./yazi-boot/completions/yazi.fish \ "notify-6.1.1" = "sha256-5Ft2yvRPi2EaErcGBkF/3Xv6K7ijFGbdjmSqI4go/h4=";
--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";
}; };
} };
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";
};
}

View file

@ -1,41 +1,89 @@
{ {
lib, lib,
formats,
runCommand, runCommand,
makeWrapper, makeWrapper,
extraPackages ? [ ],
optionalDeps ? [
jq
poppler_utils
unar
ffmpegthumbnailer
fd
ripgrep
fzf
zoxide
],
# deps
file,
yazi-unwrapped, yazi-unwrapped,
withFile ? true, # optional deps
file,
withJq ? true,
jq, jq,
withPoppler ? true,
poppler_utils, poppler_utils,
withUnar ? true,
unar, unar,
withFfmpegthumbnailer ? true,
ffmpegthumbnailer, ffmpegthumbnailer,
withFd ? true,
fd, fd,
withRipgrep ? true,
ripgrep, ripgrep,
withFzf ? true,
fzf, fzf,
withZoxide ? true,
zoxide, zoxide,
}:
settings ? { },
plugins ? { },
flavors ? { },
initLua ? null,
}:
let let
inherit (lib) optional makeBinPath; inherit (lib)
runtimePaths = concatStringsSep
optional withFile file concatMapStringsSep
++ optional withJq jq optionalString
++ optional withPoppler poppler_utils makeBinPath
++ optional withUnar unar mapAttrsToList
++ optional withFfmpegthumbnailer ffmpegthumbnailer ;
++ optional withFd fd
++ optional withRipgrep ripgrep runtimePaths = [ file ] ++ optionalDeps ++ extraPackages;
++ optional withFzf fzf
++ optional withZoxide zoxide; 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 in
runCommand yazi-unwrapped.name runCommand yazi-unwrapped.name
{ {
@ -48,5 +96,6 @@ runCommand yazi-unwrapped.name
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 : "${makeBinPath runtimePaths}" --prefix PATH : "${makeBinPath runtimePaths}" \
${optionalString (configHome != null) "--set YAZI_CONFIG_HOME ${configHome}"}
'' ''