-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfile-format.nix
29 lines (29 loc) · 1.06 KB
/
file-format.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
format: {pkgs, config, lib, ...}:
let
yj-args.hcl = "-jc";
yj-args.json = "-jji";
yj-args.toml = "-jt";
yj-args.yaml = "-jy";
yj-arg = yj-args.${format};
cfg = config.files.${format};
type = (pkgs.formats.json {}).type;
gen = name: value: pkgs.runCommand ".dsf${lib.strings.sanitizeDerivationName name}" {
nativeBuildInputs = [ pkgs.yj ];
passAsFile = [ "value" ];
value = builtins.toJSON value;
} ''yj ${yj-arg} < $valuePath > $out'';
toFile = name: value: {
source = gen name value;
git-add = lib.mkIf config.files.git.auto-add (lib.mkDefault true);
on-enter = lib.mkIf config.files.on-call (lib.mkDefault false);
};
in {
options.files.${format} = lib.mkOption {
default = {};
description = ''Create ${format} files with correponding content'';
type = lib.types.attrsOf type;
example."/hellaos.${format}".greeting = "hello World";
example."/hellows.${format}".greetings = [ ["Hello World"] ["Ola Mundo" ["Holla Que Tal"]]];
};
config.file = lib.mapAttrs toFile cfg;
}