diff options
| author | Chris Wells <chris@mathematicaster.org> | 2024-09-03 12:13:30 -0500 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2024-09-03 12:13:30 -0500 |
| commit | 849bdb056feb8e064396970f79c8962b20b0c07f (patch) | |
| tree | 03c220b6f90ad1f68a45bb55cfba377c11260cf9 /modules/lib/file-type.nix | |
| parent | d7483ed8505710033384d7fabad34470818bc760 (diff) | |
| download | kobo-manager-849bdb056feb8e064396970f79c8962b20b0c07f.tar kobo-manager-849bdb056feb8e064396970f79c8962b20b0c07f.tar.gz kobo-manager-849bdb056feb8e064396970f79c8962b20b0c07f.tar.bz2 kobo-manager-849bdb056feb8e064396970f79c8962b20b0c07f.tar.lz kobo-manager-849bdb056feb8e064396970f79c8962b20b0c07f.tar.xz kobo-manager-849bdb056feb8e064396970f79c8962b20b0c07f.tar.zst kobo-manager-849bdb056feb8e064396970f79c8962b20b0c07f.zip | |
Re-doing a bunch of this
Diffstat (limited to 'modules/lib/file-type.nix')
| -rw-r--r-- | modules/lib/file-type.nix | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/lib/file-type.nix b/modules/lib/file-type.nix new file mode 100644 index 0000000..c95c0d4 --- /dev/null +++ b/modules/lib/file-type.nix @@ -0,0 +1,42 @@ +{ 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; + })); + }; +} |
