From cbde891d1ced129f6284cbadade652182aa5d2fb Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 14 Feb 2024 15:13:20 -0600 Subject: Fixing my earlier mistakes --- modules/lib/file.nix | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 modules/lib/file.nix (limited to 'modules/lib/file.nix') 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; + }; + }) + ]; + })) +} -- cgit v1.2.3