forked from nixbuild/nix-quick-install-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnix_config.nix
46 lines (40 loc) · 1.04 KB
/
nix_config.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
with builtins; let
boolToString = b:
if b
then "true"
else "false";
/*
Check whether a value can be coerced to a string.
The value must be a string, path, or attribute set.
String-like values can be used without explicit conversion in
string interpolations and in most functions that expect a string.
*/
isStringLike = x:
isString x
|| isPath x
|| x ? outPath
|| x ? __toString;
mapAttrsToList =
# A function, given an attribute's name and value, returns a new value.
f:
# Attribute set to map over.
attrs:
map (name: f name attrs.${name}) (attrNames attrs);
mkValueString = v:
if v == null
then ""
else if isInt v
then toString v
else if isBool v
then boolToString v
else if isFloat v
then toString v
else if isList v
then concatStringsSep " " v
else if isStringLike v
then v
else "";
mkKeyValue = k: v: "${k} = ${mkValueString v}";
mkKeyValuePairs = attrs: concatStringsSep "\n" (mapAttrsToList mkKeyValue attrs);
in
mkKeyValuePairs