From 1652b1d4123871d9f5235a4c35bffccbfbdc6db3 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Wed, 7 Aug 2019 13:10:28 -0400 Subject: [PATCH] twiddle comment style --- nixos/lib/ini.nix | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/nixos/lib/ini.nix b/nixos/lib/ini.nix index 39a0f96b..ab085c8b 100644 --- a/nixos/lib/ini.nix +++ b/nixos/lib/ini.nix @@ -3,34 +3,40 @@ let lib = pkgs.lib; in rec { # Get the .ini-file-appropriate string representation of a simple value. # - # toINIString "hello" -> "hello" - # toINIString true -> "true" + # > toINIString "hello" + # "hello" + # > toINIString true + # "true" toINIString = v: if builtins.isBool v then builtins.toJSON v else builtins.toString v; # Map a function over an attrset and concatenate the string results. # - # concatMapAttrsToList (n: v: "${n} = ${v}\n") { a = "b"; c = "d"; } -> "a = b\nc = d\n" + # > concatMapAttrsToList (n: v: "${n} = ${v}\n") { a = "b"; c = "d"; } + # "a = b\nc = d\n" concatMapAttrsToList = f: a: lib.strings.concatStrings (lib.attrsets.mapAttrsToList f a); # Generate one line of configuration defining one item in one section. # - # oneConfigItemText "foo" "bar" -> "foo = bar\n" + # > oneConfigItemText "foo" "bar" + # "foo = bar\n" oneConfigItemText = name: value: "${name} = ${toINIString value}\n"; # Generate all lines of configuration defining all items in one section. # - # allConfigItemsText { foo = "bar"; baz = "quux"; } -> "foo = bar\nbaz = quux" + # > allConfigItemsText { foo = "bar"; baz = "quux"; } + # "foo = bar\nbaz = quux" allConfigItemsText = items: concatMapAttrsToList oneConfigItemText items; # Generate all lines of configuration for one section, header # and items included. # - # oneConfigSectionText "foo" { bar = "baz"; } -> "[foo]\nbar = baz\n" + # > oneConfigSectionText "foo" { bar = "baz"; } + # "[foo]\nbar = baz\n" oneConfigSectionText = name: value: '' [${name}] ${allConfigItemsText value}''; @@ -38,7 +44,8 @@ in rec { # Generate all lines of configuration for all sections, headers # and items included. # - # allConfigSectionsText { foo = { bar = "baz"; }; } -> "[foo]\nbar = baz\n" + # > allConfigSectionsText { foo = { bar = "baz"; }; } + # "[foo]\nbar = baz\n" allConfigSectionsText = sections: concatMapAttrsToList oneConfigSectionText sections; } -- GitLab