forked from hercules-ci/flake.parts-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore-modules.nix
139 lines (125 loc) · 5.92 KB
/
core-modules.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
The modules from the flake-parts repo get a special treatment in the menu and
the options for the core module need to be filtered differently.
Furthermore, this module is required by the render module, so we include it
in flakeModules.empty-site. (It's _comparatively_ empty.)
*/
{ lib, ... }: {
config.perSystem = { config, ... }:
let
inputs = config.render.officialFlakeInputs;
in
{
render.inputs = {
flake-parts = {
title = "Core Options";
baseUrl = "https://github.com/hercules-ci/flake-parts/blob/main";
getModules = _: [ ];
intro = ''
These options are provided by default. They reflect what Nix expects,
plus a small number of helpful options, notably [`perSystem`](#opt-perSystem).
'';
installation = "";
menu.enable = false;
};
flake-parts-easyOverlay =
let sourceSubpath = "/extras/easyOverlay.nix";
in
{
_module.args.name = lib.mkForce "flake-parts";
flake = inputs.flake-parts;
title = "flake-parts.easyOverlay";
baseUrl = "https://github.com/hercules-ci/flake-parts/blob/main${sourceSubpath}";
getModules = f: [ f.flakeModules.easyOverlay ];
intro = ''
## WARNING
This module does NOT make _consuming_ an overlay easy. This module is intended for _creating_ overlays.
While it is possible to consume the overlay created by this module using the `final` module argument, this is somewhat unconventional. Instead:
- _Avoid_ overlays. Many flakes can do without them.
- Initialize `pkgs` yourself:
```
perSystem = { system, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.foo.overlays.default
(final: prev: {
# ... things you really need to patch ...
})
];
config = { };
};
};
```
## Who this is for
This module is for flake authors who need to provide a simple overlay in addition to the common flake attributes. It is not for users who want to consume an overlay.
## What it actually does
This module overrides the `pkgs` module argument and provides the `final` module argument so that the `perSystem` module can be evaluated as an overlay. Attributes added by the overlay must be defined in `overlayAttrs`. The resulting overlay is defined in the `overlays.default` output.
The resulting behavior tends to be not 100% idiomatic. A hand-written overlay would usually use `final` more often, but nonetheless it gets the job done for simple use cases; certainly the simple use cases where overlays aren't strictly necessary.
## The status of this module
It has an unfortunate name and may be renamed. Alternatively, its functionality may be moved out of flake-parts, into some Nixpkgs module. Certainly until then, feel free to use the module if you understand what it does.
'';
installationDeclareInput = false;
attributePath = [ "flakeModules" "easyOverlay" ];
separateEval = true;
filterTransformOptions =
{ sourceName, sourcePath, baseUrl, coreOptDecls }:
let sourcePathStr = toString sourcePath + sourceSubpath;
in
opt:
let
declarations = lib.concatMap
(decl:
if lib.hasPrefix sourcePathStr (toString decl)
then
let subpath = lib.removePrefix sourcePathStr (toString decl);
in [{ url = baseUrl + subpath; name = sourceName + subpath; }]
else [ ]
)
opt.declarations;
in
if declarations == [ ]
then opt // { visible = false; }
else opt // { inherit declarations; };
menu.enable = false;
};
flake-parts-flakeModules =
let sourceSubpath = "/extras/flakeModules.nix";
in
{
_module.args.name = lib.mkForce "flake-parts";
flake = inputs.flake-parts;
title = "flake-parts.flakeModules";
baseUrl = "https://github.com/hercules-ci/flake-parts/blob/main${sourceSubpath}";
getModules = f: [ f.flakeModules.flakeModules ];
intro = ''
Adds the `flakeModules` attribute and `flakeModule` alias.
This module makes deduplication and `disabledModules` work, even if the definitions are inline modules or [`importApply`](../define-module-in-separate-file.html#importapply).
'';
installationDeclareInput = false;
attributePath = [ "flakeModules" "easyOverlay" ];
separateEval = true;
filterTransformOptions =
{ sourceName, sourcePath, baseUrl, coreOptDecls }:
let sourcePathStr = toString sourcePath + sourceSubpath;
in
opt:
let
declarations = lib.concatMap
(decl:
if lib.hasPrefix sourcePathStr (toString decl)
then
let subpath = lib.removePrefix sourcePathStr (toString decl);
in [{ url = baseUrl + subpath; name = sourceName + subpath; }]
else [ ]
)
opt.declarations;
in
if declarations == [ ]
then opt // { visible = false; }
else opt // { inherit declarations; };
menu.enable = false;
};
};
};
}