2024-12-10 20:26:33 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2022-02-03 14:48:10 -05:00
|
|
|
let
|
2024-12-10 20:26:33 +01:00
|
|
|
concatAndSort =
|
|
|
|
name: files:
|
|
|
|
pkgs.runCommand name { } ''
|
|
|
|
awk 1 ${lib.escapeShellArgs files} | sed '{ /^\s*$/d; s/^\s\+//; s/\s\+$// }' | sort | uniq > $out
|
|
|
|
'';
|
2022-02-03 14:48:10 -05:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
environment.wordlist = {
|
2024-08-28 21:18:52 +02:00
|
|
|
enable = lib.mkEnableOption "environment variables for lists of words";
|
2022-02-03 14:48:10 -05:00
|
|
|
|
2024-08-28 21:18:52 +02:00
|
|
|
lists = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf (lib.types.nonEmptyListOf lib.types.path);
|
2022-02-03 14:48:10 -05:00
|
|
|
|
|
|
|
default = {
|
|
|
|
WORDLIST = [ "${pkgs.scowl}/share/dict/words.txt" ];
|
|
|
|
};
|
|
|
|
|
2024-08-28 21:18:52 +02:00
|
|
|
defaultText = lib.literalExpression ''
|
2022-02-03 14:48:10 -05:00
|
|
|
{
|
|
|
|
WORDLIST = [ "''${pkgs.scowl}/share/dict/words.txt" ];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2022-02-03 14:48:10 -05:00
|
|
|
A set with the key names being the environment variable you'd like to
|
|
|
|
set and the values being a list of paths to text documents containing
|
|
|
|
lists of words. The various files will be merged, sorted, duplicates
|
|
|
|
removed, and extraneous spacing removed.
|
|
|
|
|
|
|
|
If you have a handful of words that you want to add to an already
|
|
|
|
existing wordlist, you may find `builtins.toFile` useful for this
|
|
|
|
task.
|
|
|
|
'';
|
|
|
|
|
2024-08-28 21:18:52 +02:00
|
|
|
example = lib.literalExpression ''
|
2022-02-03 14:48:10 -05:00
|
|
|
{
|
|
|
|
WORDLIST = [ "''${pkgs.scowl}/share/dict/words.txt" ];
|
|
|
|
AUGMENTED_WORDLIST = [
|
|
|
|
"''${pkgs.scowl}/share/dict/words.txt"
|
|
|
|
"''${pkgs.scowl}/share/dict/words.variants.txt"
|
|
|
|
(builtins.toFile "extra-words" '''
|
|
|
|
desynchonization
|
|
|
|
oobleck''')
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-28 21:18:52 +02:00
|
|
|
config = lib.mkIf config.environment.wordlist.enable {
|
2024-12-10 20:26:33 +01:00
|
|
|
environment.variables = lib.mapAttrs (
|
|
|
|
name: value: "${concatAndSort "wordlist-${name}" value}"
|
|
|
|
) config.environment.wordlist.lists;
|
2022-02-03 14:48:10 -05:00
|
|
|
};
|
|
|
|
}
|