-
Notifications
You must be signed in to change notification settings - Fork 78
/
default.nix
84 lines (78 loc) · 2.14 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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;
# 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 in `treefmt`.
'';
};
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: 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
submodule-modules
evalModule
mkConfigFile
mkWrapper
;
}