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

Yazi "extraConfig" Attribute #4706

Closed
ghost opened this issue Nov 27, 2023 · 10 comments
Closed

Yazi "extraConfig" Attribute #4706

ghost opened this issue Nov 27, 2023 · 10 comments
Assignees

Comments

@ghost
Copy link

ghost commented Nov 27, 2023

Description

Using the “settings” attribute to configure the yazi home manager module is not optimal, as it is based on nix and has compatibility issues. A better alternative would be to implement the “extraConfig” attribute, which would allow for more adaptable and effective configuration possibilities.

Maintainers

@XYenon

Note: Thank you for your previous assistance with yazi. I really appreciate it.

@ghost ghost added the feature request label Nov 27, 2023
@ghost ghost assigned berbiche, rycee and sumnerevans Nov 27, 2023
@XYenon
Copy link
Contributor

XYenon commented Nov 28, 2023

As manual say

If the software uses a structured configuration format like a JSON, YAML, INI, TOML, or even a plain list of key/value pairs then consider using a settings option as described in Nix RFC 42.

Could you give some examples of compatibility issue?

@ghost
Copy link
Author

ghost commented Nov 28, 2023

Update 1: I succesfully managed to fix my nix language in the "settings" attribute, but there's no change to yazi after rebuilding.
Update 2: I fixed almost everything. The link that you got from the manual helped me a lot!

    programs.yazi = {
        enable = true;
        enableNushellIntegration = true;
        settings = {
            manager = {
            layout         = [ 1 4 3 ];
            sort_by        = "alphabetical";
            sort_sensitive = true;
            sort_reverse   = true;
            sort_dir_first = true;
            linemode       = "size";
            show_hidden    = true;
            show_symlink   = true;
            };

            preview = {
            tab_size        = 2;
            max_width       = 600;
            max_height      = 900;
            cache_dir       = "";
            ueberzug_scale  = 1;
            ueberzug_offset = [ 0 0 0 0 ];
            };

            tasks = {
            micro_workers = 5;
            macro_workers = 10;
            bizarre_retry = 5;
            };

            log = {
            enabled = false;
            };
        };
        theme = {
            manager = {
            border_symbol = " ";
            };
        };
    };

I can't yet fix the code below, so any help would be great for this:

opener = {
    edit = [
                { exec = '$EDITOR "$@"', block = true,  for = "unix" };
                { exec = 'code "%*"',    orphan = true, for = "windows" };
           ];
};

Sure, the "extraConfig" attribute would still be convenient, as there are 312 lines in the theme.toml alone, but not needed anymore. I'll close the issue immediately after I resolve the code snippet.

@Misterio77
Copy link
Contributor

Misterio77 commented Nov 28, 2023

This should do the trick:

opener = {
  edit = [
    { exec = "$EDITOR \"$@\""; block = true;  for = "unix"; }
    { exec = "code \"%*\"";    orphan = true; for = "windows"; }
  ];
};

Or:

opener.edit = [
  {
    exec = "$EDITOR \"$@\"";
    block = true;
    for = "unix";
  }
  {
    exec = "code \"%*\"";
    orphan = true;
    for = "windows";
  }
];

Just as a nix syntax refresher:

[ 1 2 3 4 ]
{
  name = "John";
  age = 21;
}
[
  { foo = "bar"; hi = "hello"; }
  { bar = "foo"; }
]

JSON equivalent:

[ 1, 2, 3, 4 ]
{
  "name": "John",
  "age": 21
}
[
  { "foo": "bar", "hi": "hello" },
  { "bar": "foo" }
]

The main differences are:

  • Lists (square braces) on nix are space-separated (as opposed to JSON commas)
  • Attribute sets (curly braces) elements are always followed by semicolons, even if they're the last element in the set (as opposed to JSON using commas on all except the last element)

@Misterio77
Copy link
Contributor

Misterio77 commented Nov 28, 2023

And keep in mind you can easily write TOML (or any text file, really) either inside a nix string, or including a TOML file:

{
  xdg.configFile."yazi/theme.toml".text = ''
    [foo]
    bar=true
  '';
}
{
  xdg.configFile."yazi/theme.toml".source = ./file-on-the-same-dir.toml;
}

@ghost ghost closed this as completed Nov 28, 2023
@ghost
Copy link
Author

ghost commented Dec 17, 2023

Hey, @Misterio77! Sorry for the notification, but I can't seem to make this work. Perhaps you might know why.

keymap = {
    manager.keymap = [
        { exec = "'shell 'dragon -x -i -T \"$1\"' --confirm'"; on = [ "<C-n>" ]; }
    ];
};

I've tried exec = "\"shell \"dragon -x -i -T \"$1\"\" --confirm\""; too, but that does not seem to do the trick either. Nixos rebuild works, but yazi won't accept any input for some reason. Thank you in advance!

@Misterio77
Copy link
Contributor

Misterio77 commented Dec 17, 2023

No prob!

Maybe you have extra single quotes? As a rule of thumb, if the format requires additional escaping, nix handles it for you, just write the nix string without bothering with TOML rules.
If you want the TOML to look like:

exec = "shell 'dragon -x -i -T \"$1\"' --confirm"

This (the exact same) should do the trick:

exec = "shell 'dragon -x -i -T \"$1\"' --confirm";

Otherwise, see if you can manually make a TOML that works, and I can show you the equivalent nix :)

@ghost
Copy link
Author

ghost commented Dec 17, 2023

This is the TOML, taken directly from the Yazi Wiki:

{ on = [ "<C-n>" ], exec = '''
    shell 'dragon -x -i -T "$1"' --confirm
''' }

References that I used:
Yazi Wiki
MyNixOS

@Misterio77
Copy link
Contributor

Yeah the example I provided should work, then. If you specifically want to use multiline string like the toml example does, this is the nix equivalent:

exec = ''
  shell 'dragon -x -i -T "$1"' --confirm
'';

@ghost
Copy link
Author

ghost commented Dec 17, 2023

That worked, thank you!

I realized a bit later that by setting the nixos declarative keymap option, it overwrote the nondeclarative one, so I had to convert the TOML file into nix language.

For anyone who might find this issue in the future, you can check it below:
Keymap Gist

@dmyTRUEk
Copy link

dmyTRUEk commented Apr 6, 2024

Could you give some examples of compatibility issue?

Yazi supports lua scripting (mentioned in yazi's tips, plugins, and for example here), so it would be pretty good to have option to set it from home manager.

Sure, extraConfig probably isn't the right name, maybe something like extraLuaInit would do, but probably even better solution would be to add support for arbitrary extra config files like this: extraConfigFiles."init.lua" (inspired by anyrun's extraConfigFiles option, here's how i use it). I imagine it would work like this:

extraConfigFiles."init.lua".text = ''
    -- lua things go here
'';

update: here is open PR in nixPkgs for initLua

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants