diff options
| author | Chris Wells <chris@mathematicaster.org> | 2024-02-14 15:13:20 -0600 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2024-02-14 15:13:20 -0600 |
| commit | cbde891d1ced129f6284cbadade652182aa5d2fb (patch) | |
| tree | 8c09770b3e4082dd3d205695e3d1827daba14ffc /modules/lib/file.nix | |
| parent | 51ae706e6c007cdda2ebb8317c1d438dff9ed570 (diff) | |
| download | kobo-manager-cbde891d1ced129f6284cbadade652182aa5d2fb.tar kobo-manager-cbde891d1ced129f6284cbadade652182aa5d2fb.tar.gz kobo-manager-cbde891d1ced129f6284cbadade652182aa5d2fb.tar.bz2 kobo-manager-cbde891d1ced129f6284cbadade652182aa5d2fb.tar.lz kobo-manager-cbde891d1ced129f6284cbadade652182aa5d2fb.tar.xz kobo-manager-cbde891d1ced129f6284cbadade652182aa5d2fb.tar.zst kobo-manager-cbde891d1ced129f6284cbadade652182aa5d2fb.zip | |
Fixing my earlier mistakes
Diffstat (limited to 'modules/lib/file.nix')
| -rw-r--r-- | modules/lib/file.nix | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/lib/file.nix b/modules/lib/file.nix new file mode 100644 index 0000000..4e7a595 --- /dev/null +++ b/modules/lib/file.nix @@ -0,0 +1,43 @@ +{ lib, pkgs, ... }: +with builtins // lib; + +basePath: +rec { + option = mkOption { + type = fileType; + default = {}; + description = "Files relative to ${basePath}"; + }; + + type = types.attrsOf (types.submodule ({ name, config, ... }: { + options = { + enable = mkEnableOption name // { default = text != ""; }; + target = mkOption { + type = types.str; + default = name; + apply = p: if basePath == "" || isPrefix basePath p then p else "${basePath}/${p}"; + }; + executable = mkOption { + type = with types; nullOr bool; + default = null; + }; + source = mkOption { + type = types.path; + }; + text = mkOption { + type = with types; nullOr lines; + default = null; + }; + }; + + config = mkMerge [ + (mkIf (config.text != null) { + source = mkDefault pkgs.writeTextFile { + inherit name; + inherit (config) text; + executable = config.executable == true; + }; + }) + ]; + })) +} |
