lib/shell: add library of convenience functions

This library holds a few convenience functions for generating shell
code.
This commit is contained in:
Robert Helgesson 2018-01-04 12:21:06 +01:00
parent df6590abfc
commit 58a629b02e
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
2 changed files with 13 additions and 0 deletions

View file

@ -15,4 +15,6 @@
entryAfter = d.dagEntryAfter;
entryBefore = d.dagEntryBefore;
};
shell = import ./shell.nix { inherit lib; };
}

11
modules/lib/shell.nix Normal file
View file

@ -0,0 +1,11 @@
{ lib }:
rec {
# Produces a Bourne shell like variable export statement.
export = n: v: "export ${n}=\"${toString 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);
}