2018-01-04 12:21:06 +01:00
|
|
|
{ lib }:
|
|
|
|
|
|
|
|
rec {
|
|
|
|
# Produces a Bourne shell like variable export statement.
|
2020-02-02 00:39:17 +01:00
|
|
|
export = n: v: ''export ${n}="${toString v}"'';
|
2018-01-04 12:21:06 +01:00
|
|
|
|
2021-02-03 23:24:43 +01:00
|
|
|
export' = { colonVars ? [ ] }:
|
|
|
|
n: v:
|
|
|
|
let
|
|
|
|
replaceMatch = match:
|
|
|
|
lib.replaceStrings [ ":\$${match}:" ":\$${match}" "\$${match}:" ] [
|
|
|
|
"\${${match}:+:\$${match}:}"
|
|
|
|
"\${${match}:+:\$${match}}"
|
|
|
|
"\${${match}:+\$${match}:}"
|
|
|
|
];
|
|
|
|
|
|
|
|
mkValue = n: v:
|
|
|
|
if builtins.elem n colonVars then replaceMatch n v else toString v;
|
|
|
|
in ''export ${n}="${mkValue n v}"'';
|
|
|
|
|
2018-01-04 12:21:06 +01:00
|
|
|
# Given an attribute set containing shell variable names and their
|
|
|
|
# assignment, this function produces a string containing an export
|
|
|
|
# statement for each set entry.
|
|
|
|
exportAll = vars: lib.concatStringsSep "\n" (lib.mapAttrsToList export vars);
|
2021-02-03 23:24:43 +01:00
|
|
|
|
|
|
|
exportAll' = opts: vars:
|
|
|
|
lib.concatStringsSep "\n" (lib.mapAttrsToList (export' opts) vars);
|
2018-01-04 12:21:06 +01:00
|
|
|
}
|