diff options
author | zimbatm <zimbatm@zimbatm.com> | 2020-10-09 17:07:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-09 17:07:51 +0000 |
commit | d8e4c8e612b05e00b7ead45d57547e4d24a3dc65 (patch) | |
tree | 914da1008841e2fbad81b7b092b80b8a63126192 | |
parent | 73155864faf6c9b00e6e1b58d913bd3980bdf0a1 (diff) | |
parent | 035627dff23c4524345c4013e5e01ca95597452b (diff) |
Merge pull request #96641 from zimbatm/data-module-imports
nixos: Data module imports
-rw-r--r-- | lib/default.nix | 2 | ||||
-rw-r--r-- | lib/modules.nix | 17 | ||||
-rw-r--r-- | lib/trivial.nix | 6 |
3 files changed, 24 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix index 43b9ab5930c4..44076d295176 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -66,7 +66,7 @@ let stringLength sub substring tail; inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor bitNot boolToString mergeAttrs flip mapNullable inNixShell min max - importJSON warn info showWarnings nixpkgsVersion version mod compare + importJSON importTOML warn info showWarnings nixpkgsVersion version mod compare splitByAndCompare functionArgs setFunctionArgs isFunction toHexString toBaseDigits; inherit (fixedPoints) fix fix' converge extends composeExtensions makeExtensible makeExtensibleWithCustomName; diff --git a/lib/modules.nix b/lib/modules.nix index 02a669df6593..df3a2ad17e5f 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -875,4 +875,21 @@ rec { ]; }; + /* Use this function to import a JSON file as NixOS configuration. + + importJSON -> path -> attrs + */ + importJSON = file: { + _file = file; + config = lib.importJSON file; + }; + + /* Use this function to import a TOML file as NixOS configuration. + + importTOML -> path -> attrs + */ + importTOML = file: { + _file = file; + config = lib.importTOML file; + }; } diff --git a/lib/trivial.nix b/lib/trivial.nix index 9501a2906cae..268f39d32103 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -281,6 +281,12 @@ rec { importJSON = path: builtins.fromJSON (builtins.readFile path); + /* Reads a TOML file. + + Type :: path -> any + */ + importTOML = path: + builtins.fromTOML (builtins.readFile path); ## Warnings |