nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
7.15k stars 1.85k forks source link

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

Open happy-dude opened 2 weeks ago

happy-dude commented 2 weeks ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

This issue is similar to https://github.com/nix-community/home-manager/issues/2519 and https://github.com/NixOS/nixpkgs/issues/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
lukasMeKo commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 :flushed:

lukasngl commented 2 weeks ago

To my knowledge, using xdg.configFile and friends is perfectly fine and relatively common, to augment a stow based setup.

I personally would stick with the symlink, as using the readFile approach produces another copy of the file in the nix-store. The quickfix only makes sense if you would have used attrsets for the module options.

Regarding the permission problems, you have to set unsafe-accounts-conf = true 1 in your config and not put plain passwords in there, as nix store path are readable by any user.