{ writeTextFile, lib, ... }: { name, config, ... }: with builtins // lib; let sanitize = p: let safeChars = [ "+" "." "_" "?" "=" ] ++ lowerChars ++ upperChars ++ stringToCharacters "0123456789"; empties = l: genList (_: "") (length l); unsafeInName = stringToCharacters (replaceStrings safeChars (empties safeChars) p; in "kobo_" + replaceStrings unsafeInName (empties unsafeInName) p; in { options = { enable = mkEnableOption name // { default = true; }; name = mkOption { type = types.str; }; target = mkOption { type = types.str; default = name; apply = x: if isPrefix "/" x then x else "/${x}"; }; executable = mkOption { type = with types; nullOr bool; default = null; }; text = mkOption { type = with types; nullOr lines; default = null; }; source = mkOption { type = types.path; }; }; config = { source = mkIf (cfg.text != null) (mkDefault (writeTextFile { inherit (config) text; name = sanitieze name; executable = config.executable == true; })); }; }