1 { config, lib, pkgs, ... }:
3 concatAndSort = name: files: pkgs.runCommand name {} ''
4 awk 1 ${lib.escapeShellArgs files} | sed '{ /^\s*$/d; s/^\s\+//; s/\s\+$// }' | sort | uniq > $out
9 environment.wordlist = {
10 enable = lib.mkEnableOption "environment variables for lists of words";
12 lists = lib.mkOption {
13 type = lib.types.attrsOf (lib.types.nonEmptyListOf lib.types.path);
16 WORDLIST = [ "${pkgs.scowl}/share/dict/words.txt" ];
19 defaultText = lib.literalExpression ''
21 WORDLIST = [ "''${pkgs.scowl}/share/dict/words.txt" ];
26 A set with the key names being the environment variable you'd like to
27 set and the values being a list of paths to text documents containing
28 lists of words. The various files will be merged, sorted, duplicates
29 removed, and extraneous spacing removed.
31 If you have a handful of words that you want to add to an already
32 existing wordlist, you may find `builtins.toFile` useful for this
36 example = lib.literalExpression ''
38 WORDLIST = [ "''${pkgs.scowl}/share/dict/words.txt" ];
39 AUGMENTED_WORDLIST = [
40 "''${pkgs.scowl}/share/dict/words.txt"
41 "''${pkgs.scowl}/share/dict/words.variants.txt"
42 (builtins.toFile "extra-words" '''
52 config = lib.mkIf config.environment.wordlist.enable {
53 environment.variables =
55 (name: value: "${concatAndSort "wordlist-${name}" value}")
56 config.environment.wordlist.lists;