Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: adding plugins as modules #9

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e85bd69
update starship
haennes Dec 14, 2024
15599a6
update bypass
haennes Dec 14, 2024
1d15131
update relative-motions
haennes Dec 14, 2024
b7f2a6f
update official plugins
haennes Dec 14, 2024
3e6986a
change loader in preparation for hmModule
haennes Dec 15, 2024
3bdfcdc
wip
haennes Dec 15, 2024
70b53ca
after works
haennes Dec 16, 2024
adf1025
after works
haennes Dec 16, 2024
630d9ef
after works
haennes Dec 16, 2024
6ff7f9a
after works
haennes Dec 16, 2024
f6c25f9
after fail
haennes Dec 16, 2024
d52d0eb
mkKeyOption try
haennes Dec 16, 2024
0ee55ba
after fail
haennes Dec 16, 2024
406c7e2
after fail
haennes Dec 16, 2024
7783e67
after fail (set default)
haennes Dec 16, 2024
c47d77c
after fail
haennes Dec 16, 2024
6315333
after works
haennes Dec 16, 2024
db5151f
after works (setKeys)
haennes Dec 16, 2024
04cff06
bypass done
haennes Dec 16, 2024
b311242
after works (fix package)
haennes Dec 16, 2024
dbf5a18
after works fmt
haennes Dec 16, 2024
42ecd17
after works (add packages to plugins)
haennes Dec 16, 2024
8f8940c
after fails
haennes Dec 16, 2024
552f1db
after works (add chmod plugin)
haennes Dec 16, 2024
499f647
after works (fix default value package)
haennes Dec 16, 2024
d65a9dc
add full-border plugin
haennes Dec 16, 2024
c64dd33
add hide-preview plugin
haennes Dec 16, 2024
0b52050
add plugin starship
haennes Dec 16, 2024
b5c1028
add plugin jump-to-char
haennes Dec 16, 2024
4cdb88c
add plugin max-preview
haennes Dec 16, 2024
a2bb75c
add plugin smart-filter
haennes Dec 16, 2024
ac57edc
add plugin relative-motions
haennes Dec 16, 2024
d114bad
fix: use correct package and make it ignorable
haennes Dec 16, 2024
65735d5
add runtimeDeps
haennes Dec 25, 2024
944b297
fmt
haennes Dec 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 134 additions & 26 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,121 @@
}:
let
inherit (self) outputs;
instantiate_lib = lib: pkgs: rec {
inherit (pkgs) callPackage;
inherit (lib)
mapAttrs
mapAttrsToList
listToAttrs
filterAttrs
mkMerge
attrValues
filter
flatten
attrByPath
mkOption
mkEnableOption
;
# bypass.package = ...
# -> bypass = ...
CondRaiseAttrs = n: set: mapAttrs (_n: v: v."${n}") (filterAttrs (_n: v: v ? "${n}") set);

packages = (CondRaiseAttrs "package" YaziPlugins);

homeManagerModulesRaised = (CondRaiseAttrs "hm-module" YaziPlugins);
homeManagerModulesImports = (
map (
v:
inputs@{ config, lib, ... }:
#inputs_outer@{ pkgs, ... }:
let
cfg = config.programs.yazi.yaziPlugins.plugins.${v.name};
in
{
imports = (
filter (v: v != { }) [
(
{ pkgs, ... }@inputs:
lib.mkIf (cfg.enable && inputs.config.programs.yazi.yaziPlugins.enable) (
v.config ({ inherit cfg; } // (import ./lib.nix inputs)) inputs
)
)
(_: {
config = lib.mkIf (cfg.enable && cfg.package != null) {
programs.yazi.plugins.${v.name} = cfg.package;
};
})
(_: {
config = lib.mkIf (cfg.enable && cfg ? "runtimeDeps") {
programs.yazi.yaziPlugins.runtimeDeps = cfg.runtimeDeps;
};
})
#(v.config cfg)
({ pkgs, ... }@inputs: (v.options ({ inherit cfg; } // (import ./lib.nix inputs))) inputs)
(
{ pkgs, ... }@innerInputs:
{
options.programs.yazi.yaziPlugins.plugins.${v.name} = {
package = mkOption {
type = lib.types.nullOr lib.types.package;
description = "The ${v.name} package to use";
default = self.packages.${innerInputs.pkgs.system}.${v.name};
};
enable = mkEnableOption v.name;
};
}
)
]
);
}
) (attrValues homeManagerModulesRaised)
);

YaziPlugins =
let
AttrName = path: builtins.baseNameOf (builtins.dirOf path);
in
haumea.lib.load {
src = ./plugins;
inputs =
(removeAttrs pkgs [
"self"
"super"
"root"
])
// {
flake = self;
};
# Call files like with callPackage
loader = [
{
matches = str: str == "package.nix";
loader = inputs: path: (haumea.lib.loaders.callPackage inputs path);
}
{
matches = str: str == "hm-module.nix";
loader =
_: path:
let
value = haumea.lib.loaders.verbatim { } path;
name = AttrName path;
in
{
inherit name;
options =
if value ? "options" then
(outer_inputs: inputs: {
options.programs.yazi.yaziPlugins.plugins.${name} = value.options outer_inputs inputs;
})
else
_: _: { };
config = if value ? "config" then value.config else _: _: { };
};
}
];
};
};

callYaziPlugins =
pkgs:
haumea.lib.load {
src = ./plugins;
inputs =
(removeAttrs pkgs [
"self"
"super"
"root"
])
// {
flake = self;
};
# Call files like with callPackage
loader =
with pkgs.lib;
inputs: path:
if hasSuffix "default.nix" "${path}" then
haumea.lib.loaders.default inputs path
else
haumea.lib.loaders.callPackage inputs path;
# Make the default.nix's attrs directly children of lib
transformer = haumea.lib.transformers.liftDefault;
};
in
flake-utils-plus.lib.mkFlake {
inherit self inputs;
Expand All @@ -62,12 +152,30 @@
channels:
let
pkgs = channels.nixpkgs;
lib = inputs.nixpkgs.lib;
instance = (instantiate_lib lib pkgs);
in
{
packages = callYaziPlugins pkgs;
inherit (instance) packages;
formatter = pkgs.nixfmt-rfc-style;

};

overlays.default = final: prev: { yaziPlugins = callYaziPlugins prev; };
overlays.default =
let
lib = inputs.nixpkgs.lib;
in
final: prev: { yaziPlugins = (instantiate_lib lib prev).packages; };

homeManagerModules = rec {
yaziPlugins =
{ lib, ... }:
{
imports =
((instantiate_lib lib (inputs.nixpkgs.legacyPackages.x86_64-linux)).homeManagerModulesImports)
++ [ ./module.nix ];
};
default = yaziPlugins;
};
};
}
66 changes: 66 additions & 0 deletions lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{ lib, ... }:
let
inherit (lib) mkOption isList;
inherit (lib.types)
submodule
str
either
listOf
;
in
{
setKeys = keys: {
programs.yazi.keymap.manager.prepend_keymap = lib.mapAttrsToList (_: key: {
inherit (key) on run desc;
}) keys;
};
mkRuntimeDeps =
{ pkgs }:
mkOption {
type = lib.types.listOf (lib.types.either lib.types.package lib.types.str);
description = ''
Additional runtime packages to add
to deactivate overlaying lib.mkForce [] the parent option
'';
default = pkgs;
};
mkKeyOption =
{
on,
run,
desc,
}:
mkOption {
description = desc;
type = either (submodule {
options = {
on = mkOption {
type = listOf str;
default = on;
};
run = mkOption {
type = str;
default = run;
};

desc = mkOption {
type = str;
default = desc;
};
};
}) (listOf str);
default = {
inherit on run desc;
};
apply =
old:
if isList old then
{
on = old;
run = run;
}
else
old;
};

}
31 changes: 31 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
pkgs,
lib,
config,
...
}:
let
inherit (lib) mkEnableOption mkOption;
inherit (lib.types) lines;
cfg = config.programs.yazi.yaziPlugins;
in
{
options.programs.yazi.yaziPlugins = {
enable = mkEnableOption "yaziPlugins";
runtimeDeps = mkOption {
type = lib.types.listOf (lib.types.either lib.types.package lib.types.str);
description = ''
Additional runtime packages to add
gets set by some modules
to deactivate overlaying set this to
lib.mkForce []
'';
default = [ ];
};
};
config = lib.mkIf (cfg.runtimeDeps != [ ]) {
programs.yazi.package = pkgs.yazi.override {
extraPackages = config.programs.yazi.yaziPlugins.runtimeDeps;
};
};
}
20 changes: 20 additions & 0 deletions plugins/bypass/hm-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
options =
{ cfg, mkKeyOption, ... }:
{ lib, ... }:
{
keys = {
left = mkKeyOption {
on = [ "l" ];
run = "plugin bypass --args=smart_enter";
desc = "Open a file, or recursively enter child directory, skipping children with only a single subdirectory";
};
right = mkKeyOption {
on = [ "h" ];
run = "plugin bypass --args=reverse";
desc = "Recursively enter parent directory, skipping parents with only a single subdirectory";
};
};
};
config = { cfg, setKeys, ... }: { config, lib, ... }: { } // (setKeys cfg.keys);
}
6 changes: 3 additions & 3 deletions plugins/bypass/default.nix → plugins/bypass/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

stdenv.mkDerivation {
pname = "yaziPlugins-bypass";
version = "unstable-2024-05-13";
version = "unstable-2024-12-14";

src = fetchFromGitHub {
owner = "Rolv-Apneseth";
repo = "bypass.yazi";
rev = "619500e8ae64e1c0e970a7637b877c3aa6a5a32a";
sha256 = "17dmgpvsxin77rn2invh32csf0i3fbvpgz93dsp0jgayx8pirwn5";
rev = "6c5414f532ede57a74687c53fee3409a38746c04";
sha256 = "sha256-jzE6U9RgRF0oy4HQ91WjoftZ47EXPwb7bRtlVwL8vOQ=";
};

buildPhase = ''
Expand Down
18 changes: 18 additions & 0 deletions plugins/chmod/hm-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
options =
{ cfg, mkKeyOption, ... }:
{ lib, ... }:
{
keys = {
mod = mkKeyOption {
on = [
"c"
"m"
];
run = "plugin chmod";
desc = "Chmod on selected files";
};
};
};
config = { cfg, setKeys, ... }: { config, lib, ... }: { } // (setKeys cfg.keys);
}
File renamed without changes.
7 changes: 7 additions & 0 deletions plugins/full-border/hm-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
config = _: _: {
programs.yazi.initLua = ''
require("full-border"):setup()
'';
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

stdenv.mkDerivation {
pname = "yaziPlugins-full-border";
version = "unstable-2024-08-21";
version = "unstable-2024-12-14";

src = fetchFromGitHub {
owner = "yazi-rs";
repo = "plugins";
rev = "b6597919540731691158831bf1ff36ed38c1964e";
sha256 = "07dm70s48mas4d38zhnrfw9p3sgk83ki70xi1jb2d191ya7a2p3j";
rev = "62f078905b4de55f19e328452c8a1f889ff2f6f4";
sha256 = "sha256-PSVzjC1sdaIOtK5ave4kn3Ck8YwpjO3N9uV/WE6Skdo=";
};

buildPhase = ''
Expand Down
14 changes: 14 additions & 0 deletions plugins/hide-preview/hm-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
options =
{ mkKeyOption, ... }:
_: {
keys = {
toggle = mkKeyOption {
on = [ "T" ];
run = "plugin hide-preview";
desc = "Hide or show preview";
};
};
};
config = { cfg, setKeys, ... }: _: (setKeys cfg.keys);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

stdenv.mkDerivation {
pname = "yaziPlugins-hide-preview";
version = "unstable-2024-08-21";
version = "unstable-2024-12-14";

src = fetchFromGitHub {
owner = "yazi-rs";
repo = "plugins";
rev = "b6597919540731691158831bf1ff36ed38c1964e";
sha256 = "07dm70s48mas4d38zhnrfw9p3sgk83ki70xi1jb2d191ya7a2p3j";
rev = "62f078905b4de55f19e328452c8a1f889ff2f6f4";
sha256 = "sha256-PSVzjC1sdaIOtK5ave4kn3Ck8YwpjO3N9uV/WE6Skdo=";
};

buildPhase = ''
Expand Down
Loading