-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
70 lines (66 loc) · 1.57 KB
/
default.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
# A pure Nix library that handles the treefmt configuration.
let
# The base module configuration that generates and wraps the treefmt config
# with Nix.
module-options = ./module-options.nix;
# Program to formatter mapping
programs = import ./modules;
all-modules = nixpkgs:
[
{
_module.args = {
pkgs = nixpkgs;
lib = nixpkgs.lib;
};
}
module-options
]
++ programs.modules;
# treefmt-nix can be loaded into a submodule. In this case we get our `pkgs` from
# our own standard option `pkgs`; not externally.
submodule-modules =
[
({
config,
lib,
...
}: let
inherit
(lib)
mkOption
types
;
in {
options.pkgs = mkOption {
type = types.uniq (types.lazyAttrsOf (types.raw or types.unspecified));
description = ''
Nixpkgs to use.
'';
};
config._module.args = {
pkgs = config.pkgs;
};
})
module-options
]
++ programs.modules;
# Use the Nix module system to validate the treefmt config file format.
#
# nixpkgs is an instance of <nixpkgs> that contains treefmt.
# configuration is an attrset used to configure the nix module
evalModule = nixpkgs: inputs: configuration:
nixpkgs.lib.evalModules {
specialArgs = {
inherit inputs;
};
modules = all-modules nixpkgs ++ [configuration];
};
in {
inherit
module-options
programs
all-modules
submodule-modules
evalModule
;
}