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

bug: programs.aerc.extraConfig.filters attrs are order-sensitive #6059

Open
2 tasks done
happy-dude opened this issue Nov 8, 2024 · 4 comments
Open
2 tasks done

bug: programs.aerc.extraConfig.filters attrs are order-sensitive #6059

happy-dude opened this issue Nov 8, 2024 · 4 comments
Assignees
Labels
bug mail triage Issues or feature request that have not been triaged yet

Comments

@happy-dude
Copy link

happy-dude commented Nov 8, 2024

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

This issue is similar to #2519 and NixOS/nixpkgs#258083.

aerc's config (aerc.conf) allow various filters to customize how different mimetypes are viewed and paged.

For instance, the following is a valid setting:

text/plain=colorize
text/calendar=calendar
message/delivery-status=colorize
message/rfc822=colorize
text/html=pandoc -f html -t plain | colorize
text/html=html | colorize
text/*=bat -fP --file-name="$AERC_FILENAME"
.headers=colorize

Note that there are two text/html filters (which home-manager attrs only allow 1 key-value mapping), and the text/* filter at the end to match all general text content.

Unfortunately when I try to configure this for home-manager in a nix file, the order is not preserved (and does not allow duplicate keys for text/html):

      filters = {
        "text/plain" = "colorize";
        "text/calendar" = "calendar";
        "message/delivery-status" = "colorize";
        "message/rfc822" = "colorize";
        #"text/html" = "pandoc -f html -t plain | colorize";
        "text/html" = "html | colorize";
        ".headers" = "colorize";
      };

Is there any way to improve this setting and perhaps have it take a literal block of text?

Thanks a ton! Please let me know how I can help facilitate further.

Maintainer CC

@lukasngl

System information

❯ nix-shell -p nix-info --run "nix-info -m"
these 3 paths will be fetched (0.03 MiB download, 0.12 MiB unpacked):
  /nix/store/g45nm13bwh1jxypl33wxi016yjzbidkp-gcc-wrapper-13.3.0
  /nix/store/mxj4mx3p39qfrj5q4bdcsxrisx0zwgzh-nix-info
  /nix/store/jvq7h4nv8fvi0l2s7a9b6dm00fcy8sv6-stdenv-linux
copying path '/nix/store/mxj4mx3p39qfrj5q4bdcsxrisx0zwgzh-nix-info' from 'https://cache.nixos.org'...
copying path '/nix/store/g45nm13bwh1jxypl33wxi016yjzbidkp-gcc-wrapper-13.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/jvq7h4nv8fvi0l2s7a9b6dm00fcy8sv6-stdenv-linux' from 'https://cache.nixos.org'...
 - system: `"aarch64-linux"`
 - host os: `Linux 6.11.0-9-generic, Ubuntu, 24.10 (Oracular Oriole), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.10`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/home/stanleychan/.nix-defexpr/channels/nixpkgs
@happy-dude happy-dude added bug triage Issues or feature request that have not been triaged yet labels Nov 8, 2024
@lukasMeKo
Copy link

Hi, thanks for reporting the issue and for the additional resources, I had not seen this yet.

At this point I have only rough ideas of how one could fix this, but as an escape hatch programs.aerc.extraConfig also accepts text, so you could try the following as a quick fix:

{
    programs.aerc = {
      extraConfig = let
        iniFormat = pkgs.formats.iniWithGlobalSection {};
        cfgText = iniFormat.generate "aerc.conf" {
          globalSection = {
            unsafe-accounts-conf = true;
          };
          sections = {
            /* your config without filters */
          };
        };
      in
      ''
        ${builtins.readFile cfgText}

        [filter]
        # your filters
      '';
    };
}

You will get a warning about unsafe-accounts-conf, which you can simply ignore.

@happy-dude
Copy link
Author

happy-dude commented Nov 8, 2024

At this point I have only rough ideas of how one could fix this, but as an escape hatch programs.aerc.extraConfig also accepts text, so you could try the following as a quick fix:

Thanks! This is a decent workaround for the time being.
I was also looking for some perspective here: is creating xdg symlinks to copies of the config files in my dotfiles directory advised against?

Something like:

  home.file.".notmuch-config".source = ./.notmuch-config;
  home.file.".mbsyncrc".source = ./.mbsyncrc;

  xdg.configFile."aerc/aerc.conf".source = ./.config/aerc/aerc.conf;
  xdg.configFile."aerc/accounts.conf".source = ./.config/aerc/accounts.conf;
  xdg.configFile."aerc/binds.conf".source = ./.config/aerc/binds.conf;
  xdg.configFile."aerc/notmuch-map.conf".source = ./.config/aerc/notmuch-map.conf;

  xdg.configFile."aerc/stylesets/gruvbox".source = ./.config/aerc/stylesets/gruvbox;
  xdg.configFile."aerc/stylesets/gruvbox_material_dark_hard".source = ./.config/aerc/stylesets/gruvbox_material_dark_hard;
  xdg.configFile."aerc/stylesets/gruvbox_material_dark_medium".source = ./.config/aerc/stylesets/gruvbox_material_dark_medium;
  xdg.configFile."aerc/stylesets/gruvbox_material_dark_soft".source = ./.config/aerc/stylesets/gruvbox_material_dark_soft;

  xdg.configFile."aerc/templates/quoted_thanks".source = ./.config/aerc/templates/quoted_thanks;
  xdg.configFile."aerc/templates/thanks".source = ./.config/aerc/templates/thanks;

I was having permissions(?) problems with accounts.conf when I was doing that, but wouldn't the end result would be similar to the above recommendation and using ${builtins.readFile location/in/repo/file.conf} ?

@happy-dude
Copy link
Author

Ended up with https://github.com/happy-dude/dotfiles/blob/work/aerc/default.nix, which is probably not the most idiomatic nix (letting nix / home-manager generate and render the files), but it's still largely compatible with gnu stow and whatnot 😳

@lukasngl
Copy link
Contributor

lukasngl commented Nov 9, 2024 via email

@teto teto added the mail label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mail triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

7 participants