Skip to content

Commit dbd36b0

Browse files
authored
refactor(nix): add shell completion and avoid impure (sxyazi#293)
1 parent 283f937 commit dbd36b0

File tree

6 files changed

+55
-210
lines changed

6 files changed

+55
-210
lines changed

Diff for: .envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ config/completions
55

66
result
77
result-*
8-
.devenv*
8+
.direnv

Diff for: flake.lock

+19-190
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flake.nix

+19-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@
22
inputs = {
33
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
44
flake-utils.url = "github:numtide/flake-utils";
5-
devenv = {
6-
url = "github:cachix/devenv";
7-
inputs.nixpkgs.follows = "nixpkgs";
5+
rust-overlay = {
6+
url = "github:oxalica/rust-overlay";
7+
inputs = {
8+
nixpkgs.follows = "nixpkgs";
9+
flake-utils.follows = "flake-utils";
10+
};
811
};
912
};
1013

11-
outputs = { self, nixpkgs, flake-utils, ... } @ inputs:
14+
outputs = { self, nixpkgs, flake-utils, rust-overlay, ... } @ inputs:
15+
let
16+
# Nixpkgs overlays
17+
overlays = [
18+
rust-overlay.overlays.default
19+
(final: prev: {
20+
rustToolchain = final.rust-bin.stable.latest.default.override {
21+
extensions = [ "rust-src" ];
22+
};
23+
})
24+
];
25+
in
1226
flake-utils.lib.eachDefaultSystem (system:
1327
let
14-
pkgs = nixpkgs.legacyPackages.${system};
28+
pkgs = import nixpkgs { inherit system overlays; };
1529
versionSuffix = "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}";
1630
version = (builtins.fromTOML (builtins.readFile ./app/Cargo.toml)).package.version + versionSuffix;
1731
yazi = pkgs.callPackage ./nix/yazi.nix { inherit version; };

Diff for: nix/shell.nix

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
{ pkgs, inputs, ... }:
1+
{ pkgs, ... }:
22

33
pkgs.mkShell {
44
packages = with pkgs; [
5+
rustToolchain
6+
rust-analyzer
7+
58
nodePackages.cspell
69

710
file
@@ -15,18 +18,11 @@ pkgs.mkShell {
1518
zoxide
1619
];
1720

18-
buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin (
19-
with pkgs.darwin.apple_sdk.frameworks; [ Foundation ]
21+
buildInputs = with pkgs; lib.optionals stdenv.isDarwin (
22+
with darwin.apple_sdk.frameworks; [ Foundation ]
2023
);
2124

22-
inputsFrom = [
23-
(inputs.devenv.lib.mkShell {
24-
inherit inputs pkgs;
25-
modules = [
26-
({ pkgs, ... }: {
27-
languages.rust.enable = true;
28-
})
29-
];
30-
})
31-
];
25+
env = {
26+
RUST_BACKTRACE = "1";
27+
};
3228
}

Diff for: nix/yazi.nix

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
, lib
44

55
, makeWrapper
6+
, installShellFiles
67
, stdenv
78
, darwin
89

@@ -34,7 +35,7 @@ rustPlatform.buildRustPackage {
3435

3536
cargoLock.lockFile = ../Cargo.lock;
3637

37-
nativeBuildInputs = [ makeWrapper ];
38+
nativeBuildInputs = [ makeWrapper installShellFiles ];
3839
buildInputs = lib.optionals stdenv.isDarwin (
3940
with darwin.apple_sdk.frameworks; [ Foundation ]
4041
);
@@ -55,6 +56,10 @@ rustPlatform.buildRustPackage {
5556
''
5657
wrapProgram $out/bin/yazi \
5758
--prefix PATH : "${makeBinPath runtimePaths}"
59+
installShellCompletion --cmd yazi \
60+
--bash ./config/completions/yazi.bash \
61+
--fish ./config/completions/yazi.fish \
62+
--zsh ./config/completions/_yazi
5863
'';
5964

6065
meta = with lib; {

0 commit comments

Comments
 (0)