From cf0aad391c10473fa7613dcc41b1f6a366d03148 Mon Sep 17 00:00:00 2001 From: Jonas Holst Damtoft Date: Sat, 29 Dec 2018 21:21:11 +0100 Subject: [PATCH] emacs: fix merging of `extraPackages` and `overrides` Because `extraPackages` and `overrides` expect functions as values it has not been possible to perform merges. This adds suitable types for these options that allow reasonable merging. --- modules/lib/types.nix | 28 ++++++++++++++++++++++++++++ modules/programs/emacs.nix | 4 ++++ 2 files changed, 32 insertions(+) create mode 100644 modules/lib/types.nix diff --git a/modules/lib/types.nix b/modules/lib/types.nix new file mode 100644 index 000000000..1b514d20a --- /dev/null +++ b/modules/lib/types.nix @@ -0,0 +1,28 @@ +{ lib }: + +with lib; + +{ + + selectorFunction = mkOptionType { + name = "selectorFunction"; + description = + "Function that takes an attribute set and returns a list" + + " containing a selection of the values of the input set"; + check = isFunction; + merge = _loc: defs: + as: concatMap (select: select as) (getValues defs); + }; + + overlayFunction = mkOptionType { + name = "overlayFunction"; + description = + "An overlay function, takes self and super and returns" + + " an attribute set overriding the desired attributes."; + check = isFunction; + merge = _loc: defs: + self: super: + foldl' (res: def: mergeAttrs res (def.value self super)) {} defs; + }; + +} diff --git a/modules/programs/emacs.nix b/modules/programs/emacs.nix index a7f8b94cd..fc796af56 100644 --- a/modules/programs/emacs.nix +++ b/modules/programs/emacs.nix @@ -4,6 +4,8 @@ with lib; let + hmTypes = import ../lib/types.nix { inherit lib; }; + cfg = config.programs.emacs; # Copied from all-packages.nix, with modifications to support @@ -34,6 +36,7 @@ in extraPackages = mkOption { default = self: []; + type = hmTypes.selectorFunction; defaultText = "epkgs: []"; example = literalExample "epkgs: [ epkgs.emms epkgs.magit ]"; description = "Extra packages available to Emacs."; @@ -41,6 +44,7 @@ in overrides = mkOption { default = self: super: {}; + type = hmTypes.overlayFunction; defaultText = "self: super: {}"; example = literalExample '' self: super: rec {