summaryrefslogtreecommitdiff
path: root/openwrt/etc.nix
diff options
context:
space:
mode:
authorpennae <pennae.git@eno.space>2023-09-22 20:55:05 +0200
committerpennae <pennae.git@eno.space>2023-09-22 21:06:55 +0200
commit66c6d2c1dfd4b3ef222bb64d3ccef9be915e0895 (patch)
tree0dde64acbdf9aa61134cdf066723bd731101f767 /openwrt/etc.nix
downloaddewclaw-66c6d2c1dfd4b3ef222bb64d3ccef9be915e0895.tar.gz
dewclaw-66c6d2c1dfd4b3ef222bb64d3ccef9be915e0895.tar.xz
dewclaw-66c6d2c1dfd4b3ef222bb64d3ccef9be915e0895.zip
initial commit
without warranty of any kind, express or impliend
Diffstat (limited to 'openwrt/etc.nix')
-rw-r--r--openwrt/etc.nix41
1 files changed, 41 insertions, 0 deletions
diff --git a/openwrt/etc.nix b/openwrt/etc.nix
new file mode 100644
index 0000000..8231125
--- /dev/null
+++ b/openwrt/etc.nix
@@ -0,0 +1,41 @@
+{ config, lib, ... }:
+
+let
+ cfg = config.etc;
+in
+
+{
+ options.etc = lib.mkOption {
+ type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
+ options = {
+ enable = lib.mkEnableOption "this `/etc` file" // {
+ default = true;
+ };
+
+ text = lib.mkOption {
+ type = lib.types.lines;
+ description = ''
+ Contents of the file.
+ '';
+ };
+ };
+ }));
+ default = {};
+ };
+
+ config = lib.mkIf (cfg != {}) {
+ deploySteps.etc = {
+ priority = 8000;
+ apply =
+ lib.concatStrings
+ (lib.mapAttrsToList
+ (name: file: lib.optionalString (file.enable) ''
+ ${lib.optionalString (dirOf name != ".") ''
+ mkdir -p ${lib.escapeShellArg (dirOf name)}
+ ''}
+ echo ${lib.escapeShellArg file.text} >${lib.escapeShellArg "/etc/${name}"}
+ '')
+ cfg);
+ };
+ };
+}