1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00
home-manager/modules/lib/shell.nix

29 lines
903 B
Nix
Raw Normal View History

{ 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}"'';
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}"'';
# 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);
}