forked from numtide/treefmt-nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
59 lines (54 loc) · 1.52 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
# 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 ./programs;
all-modules = nixpkgs: [
{
_module.args = {
pkgs = nixpkgs;
lib = nixpkgs.lib;
};
}
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: configuration:
nixpkgs.lib.evalModules {
modules = all-modules nixpkgs ++ [ configuration ];
};
# Returns a treefmt.toml generated from the passed configuration.
#
# nixpkgs is an instance of <nixpkgs> that contains treefmt.
# configuration is an attrset used to configure the nix module
mkConfigFile = nixpkgs: configuration:
let
mod = evalModule nixpkgs configuration;
in
mod.config.build.configFile;
# Returns an instance of treefmt, wrapped with some configuration.
#
# nixpkgs is an instance of <nixpkgs> that contains treefmt.
# configuration is an attrset used to configure the nix module
mkWrapper = nixpkgs: configuration:
let
mod = evalModule nixpkgs configuration;
in
mod.config.build.wrapper;
in
{
inherit
module-options
programs
all-modules
evalModule
mkConfigFile
mkWrapper
;
}