From 4597bb574e8df115701d1abe84ad053f07f6677f Mon Sep 17 00:00:00 2001 From: Marien Zwart Date: Sat, 25 May 2024 20:30:33 +1000 Subject: [PATCH] Add generator for init.el To be used for more concise tests of specific module combinations. --- checks.nix | 8 ++++++-- flake.nix | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/checks.nix b/checks.nix index 1e0f758..85caa92 100644 --- a/checks.nix +++ b/checks.nix @@ -18,7 +18,9 @@ testers, tmux, writeText, + writeTextDir, makeDoomPackages, + toInit, }: let common = { @@ -27,6 +29,8 @@ let doomLocalDir = "~/.local/share/nix-doom-unstraightened"; }; mkDoom = args: (makeDoomPackages (common // args)).doomEmacs; + mkDoomDir = args: writeTextDir "init.el" (toInit args); + minimalDoomDir = mkDoomDir { config = [ "default" ]; }; doomTest = assertion: args: testers.testEqualContents { inherit assertion; expected = writeText "doom-expected" "Doom functions"; @@ -46,11 +50,11 @@ let in { minimal = mkDoom { doomDir = ./doomdirs/minimal; }; minimalEmacs = (makeDoomPackages (common // { - doomDir = ./doomdirs/minimal; + doomDir = minimalDoomDir; })).emacsWithDoom; full = mkDoom { full = true; - doomDir = ./doomdirs/minimal; + doomDir = minimalDoomDir; }; example = mkDoom { doomDir = ./doomdirs/example; }; example-without-loader = mkDoom { diff --git a/flake.nix b/flake.nix index eda9b8b..c015a1f 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,7 @@ eachSystem = nixpkgs.lib.genAttrs (import systems); in f: eachSystem (system: f nixpkgs.legacyPackages.${system}); + doomFromPackages = pkgs: args: let # Hack to avoid pkgs.extend having to instantiate an additional nixpkgs. # @@ -50,8 +51,32 @@ }; in pkgs.callPackages self mergedArgs; + + toInit = let + inherit (nixpkgs.lib) concatLines concatStringsSep isList isString mapAttrsToList toPretty; + in + attrs: + concatLines ( + [ "(doom!" ] + ++ (mapAttrsToList ( + cat: modules: + (concatLines ( + [ (":" + cat) ] + ++ (map ( + mod: + if isString mod then mod + else if isList mod then "(" + (concatStringsSep " " mod) + ")" + else abort "${toPretty mod} not supported" + )) + modules + )) + ) attrs) + ++ [ ")" ] + ); + in { checks = perSystemPackages (pkgs: pkgs.callPackages ./checks.nix { + inherit toInit; makeDoomPackages = doomFromPackages pkgs; }); packages = perSystemPackages (pkgs: {