Tweak toInit input structure

Using an attrset instead of a list allows using Nix's shorthand for
nested attrsets, which is much more readable for the simple cases toInit
is used for.
This commit is contained in:
Marien Zwart 2024-06-16 23:04:24 +10:00
parent c61cd622b7
commit f8012b8785
No known key found for this signature in database
2 changed files with 19 additions and 13 deletions

View file

@ -37,7 +37,7 @@ let
};
mkDoom = args: (makeDoomPackages (common // args)).doomEmacs;
mkDoomDir = args: writeTextDir "init.el" (toInit args);
minimalDoomDir = mkDoomDir { config = [ "default" ]; };
minimalDoomDir = mkDoomDir { config.default = true; };
doomTest = name: init: doomArgs: testers.testEqualContents {
assertion = "name = ${name}; modules = ${toPretty {} init}; args = ${toPretty {} doomArgs};";
expected = writeText "doom-expected" "Doom functions";
@ -77,14 +77,14 @@ in {
doomDir = ./doomdir;
profileName = "";
};
interactive = doomTest "nix-profile" { config = [ "default" ]; } { };
interactive-without-loader = doomTest "no-profile" { config = [ "default" ]; } { profileName = ""; };
interactive-no-profile-hack = doomTest "no-profile" { config = [ "default" ]; } { noProfileHack = true; };
interactive = doomTest "nix-profile" { config.default = true; } { };
interactive-without-loader = doomTest "no-profile" { config.default = true; } { profileName = ""; };
interactive-no-profile-hack = doomTest "no-profile" { config.default = true; } { noProfileHack = true; };
org-re-reveal = doomTest "org-re-reveal" { lang = [ [ "org" "+present" ] ]; } { };
org-re-reveal = doomTest "org-re-reveal" { lang.org = [ "+present" ]; } { };
# Various tests of module combinations.
unpinned-org = doomTest "external-org" { app = [ [ "rss" "+org" ] ]; } { };
unpinned-org = doomTest "external-org" { app.rss = [ "+org" ]; } { };
extraPackages = doomTest "extraPackages" { config = [ "default" ]; } { extraPackages = epkgs: [ epkgs.vterm ]; };
extraPackages = doomTest "extraPackages" { config.default = true; } { extraPackages = epkgs: [ epkgs.vterm ]; };
}

View file

@ -52,8 +52,14 @@
in
pkgs.callPackages self mergedArgs;
# Convert a Nix expression to a `doom!` block suitable for init.el.
#
# Input: a nested attribute set.
# The keys of the first level are categories (like `lang`).
# The keys of the second level are module names (like `nix`).
# The values are lists of module flags, or `true` for no flags.
toInit = let
inherit (nixpkgs.lib) concatLines concatStringsSep isList isString mapAttrsToList toPretty;
inherit (nixpkgs.lib) concatLines concatStringsSep isList mapAttrsToList toPretty;
in
attrs:
concatLines (
@ -62,11 +68,11 @@
cat: modules:
(concatLines (
[ (":" + cat) ]
++ (map (
mod:
if isString mod then mod
else if isList mod then "(" + (concatStringsSep " " mod) + ")"
else abort "${toPretty mod} not supported"
++ (mapAttrsToList (
mod: value:
if value == true then mod
else if isList value then "(${mod} ${concatStringsSep " " value})"
else abort "${toPretty value} not supported"
))
modules
))