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