summaryrefslogtreecommitdiff
path: root/modules/lib/write-text.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/lib/write-text.nix')
-rw-r--r--modules/lib/write-text.nix55
1 files changed, 55 insertions, 0 deletions
diff --git a/modules/lib/write-text.nix b/modules/lib/write-text.nix
new file mode 100644
index 0000000..f58a834
--- /dev/null
+++ b/modules/lib/write-text.nix
@@ -0,0 +1,55 @@
+{ lib, mkTextDerivation }:
+
+{ config, name, ... }:
+
+with lib;
+
+let
+
+ drv = mkTextDerivation name config.text;
+
+in
+
+{
+ options = {
+
+ enable = mkOption {
+ type = types.bool;
+ default = true;
+ description = ''
+ Whether this file should be generated.
+ This option allows specific files to be disabled.
+ '';
+ };
+
+ text = mkOption {
+ type = types.lines;
+ default = "";
+ description = ''
+ Text of the file.
+ '';
+ };
+
+ target = mkOption {
+ type = types.str;
+ default = name;
+ description = ''
+ Name of symlink. Defaults to the attribute name.
+ '';
+ };
+
+ source = mkOption {
+ type = types.path;
+ description = ''
+ Path of the source file.
+ '';
+ };
+
+ };
+
+ config = {
+
+ source = mkIf (config.text != "") (mkDefault drv);
+
+ };
+}