-
Notifications
You must be signed in to change notification settings - Fork 4
/
nushell.nix
102 lines (99 loc) · 2.29 KB
/
nushell.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
config,
lib,
pkgs,
...
}:
with lib;
let
cfg = config.programs.nushell;
formatNuValue =
let
indentation = " ";
indent =
str:
let
lines = splitString "\n" str;
indentedLines = map (line: "${indentation}${line}") lines;
in
lib.concatStringsSep "\n" indentedLines;
in
value:
{
bool = v: if v then "true" else "false";
int = toString;
float = toString;
string = builtins.toJSON;
null = v: "null";
path = v: formatNuValue (toString v);
list = v: "[${lib.concatStrings (map (v: "\n${indent (formatNuValue v)}") v)}\n]";
set =
v:
if nuExpressionType.check v then
v.__nu
else
"{${lib.concatStrings (mapAttrsToList (k: v: "\n${indent "${k}: ${formatNuValue v}"}") v)}\n}";
}
.${builtins.typeOf value}
value;
nuExpressionType = mkOptionType {
name = "nu";
description = "Nu expression";
check = x: isAttrs x && x ? __nu && isString x.__nu;
merge = mergeEqualOption;
};
in
{
meta.maintainers = [ maintainers.bobvanderlinden ];
options = {
programs.nushell = {
settingss = mkOption {
type =
with lib.types;
let
valueType =
nullOr (oneOf [
nuExpressionType
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "Nu value type";
};
in
valueType;
default = { };
example = literalExpression ''
{
show_banner = false;
}
'';
description = ''
Configuration written to
<filename>$XDG_CONFIG_HOME/pueue/pueue.yml</filename>.
'';
};
};
};
config = mkIf cfg.enable (mkMerge [
{
programs.nushell.extraConfig = mkBefore ''
let-env config = ${formatNuValue cfg.settingss}
'';
}
{
programs.nushell.extraConfig = mkAfter (
lib.concatLines (
mapAttrsToList (k: v: ''
alias ${k} = ${v}
'') cfg.shellAliases
)
);
}
]);
}