Skip to content

Commit 70a32f4

Browse files
authored
feat(integrations): integration with other module systems (#227)
changed outputs.wrappedModules to outputs.wrappers (Sorry! But also this is much better. You have 8 months to change it before the old one is removed. This name will not change again) Added flake-parts module for setting up your outputs, and building packages Added function for creating nixos and home manager modules from any wrapper module. Added flakeModules nixosModules and homeModules outputs to the main flake. Improved documentation. Did the treewide update for checks from outputs.wrappedModules to outputs.wrappers Added specific dates of removal to some deprecations.
1 parent 8aa2e22 commit 70a32f4

File tree

29 files changed

+536
-68
lines changed

29 files changed

+536
-68
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Example:
133133
self,
134134
}:
135135
let
136-
gitWrapped = self.wrappedModules.git.wrap {
136+
gitWrapped = self.wrappers.git.wrap {
137137
inherit pkgs;
138138
settings = {
139139
user = {
@@ -154,7 +154,7 @@ pkgs.runCommand "git-test" { } ''
154154
If your module declares a list of valid platforms via its `meta.platforms` option, you should disable your test on the relevant platforms like so:
155155

156156
```nix
157-
if builtins.elem pkgs.stdenv.hostPlatform.system self.wrappedModules.waybar.meta.platforms then
157+
if builtins.elem pkgs.stdenv.hostPlatform.system self.wrappers.waybar.meta.platforms then
158158
pkgs.runCommand "waybar-test" { } ''
159159
"${waybarWrapped}/bin/waybar" --version | grep -q "${waybarWrapped.version}"
160160
touch $out

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ What if I told you, you can solve all those problems, and gain a really nice, co
7676
And it uses something you already know! The module system!
7777

7878
```nix
79-
inputs.nix-wrapper-modules.wrappedModules.alacritty.wrap {
79+
inputs.nix-wrapper-modules.wrappers.alacritty.wrap {
8080
inherit pkgs;
8181
settings.terminal.shell.program = "${pkgs.zsh}/bin/zsh";
8282
settings.terminal.shell.args = [ "-l" ];

docs/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ let
201201
echo >> $out/src/SUMMARY.md
202202
echo '- [Intro](./home.md)' >> $out/src/SUMMARY.md
203203
echo '- [Getting Started](./getting-started.md)' >> $out/src/SUMMARY.md
204-
echo '- [Core Options Set](./core.md)' >> $out/src/SUMMARY.md
205-
echo '- [`wlib.modules.default`](./default.md)' >> $out/src/SUMMARY.md
206204
echo '- [Lib Functions](./lib-intro.md)' >> $out/src/SUMMARY.md
207205
echo ' - [`wlib`](./wlib.md)' >> $out/src/SUMMARY.md
208206
echo ' - [`wlib.types`](./types.md)' >> $out/src/SUMMARY.md
209207
echo ' - [`wlib.dag`](./dag.md)' >> $out/src/SUMMARY.md
208+
echo '- [Core Options Set](./core.md)' >> $out/src/SUMMARY.md
209+
echo '- [`wlib.modules.default`](./default.md)' >> $out/src/SUMMARY.md
210210
echo '- [Helper Modules](./helper-modules.md)' >> $out/src/SUMMARY.md
211211
${mkSubLinks (builtins.removeAttrs module_docs [ "default" ])}
212212
echo '- [Wrapper Modules](./wrapper-modules.md)' >> $out/src/SUMMARY.md

docs/md/getting-started.md

Lines changed: 163 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ And it serves as a repository for modules for wrapping the programs themselves,
1515

1616
For that it offers:
1717
- `wlib.wrapperModules`: Pre-made wrapper modules for common packages (`tmux`, `wezterm`, etc.)
18-
- `outputs.wrappedModules`: a flake output containing partially evaluated forms of the modules in `wrapperModules` for easier access to `.wrap` and other values in the module system directly.
18+
- `outputs.wrappers`: a flake output containing partially evaluated forms of the modules in `wrapperModules` for easier access to `.wrap` and other values in the module system directly.
1919

2020
## Usage
2121

@@ -56,7 +56,7 @@ They will get you started with a module file and the default one also gives you
5656
forAllSystems = with nixpkgs.lib; genAttrs platforms.all;
5757
in {
5858
packages = forAllSystems (system: {
59-
default = wrappers.wrappedModules.mpv.wrap (
59+
default = wrappers.wrappers.mpv.wrap (
6060
{config, wlib, lib, pkgs, ...}: {
6161
pkgs = import nixpkgs { inherit system; };
6262
scripts = [ pkgs.mpvScripts.mpris ];
@@ -89,7 +89,7 @@ The package (via `passthru`) and the modules under `.config` both offer all 3 fu
8989
```nix
9090
# Apply initial configuration
9191
# you can use `.eval` `.apply` or `.wrap` for this.
92-
initialConfig = (wrappers.wrappedModules.tmux.eval ({config, pkgs, ...}{
92+
initialConfig = (inputs.wrappers.wrappers.tmux.eval ({config, pkgs, ...}{
9393
# but if you don't plan to provide pkgs yet, you can't use `.wrap` or `.wrapper` yet.
9494
# config.pkgs = pkgs;
9595
# but we can still use `pkgs` before that inside!
@@ -128,15 +128,19 @@ packageAgain = apackage.wrap ({config, pkgs, ...}: {
128128
### Creating Custom Wrapper Modules
129129

130130
```nix
131-
{ wlib, lib }:
132-
133-
(wlib.evalModule ({ config, wlib, lib, pkgs, ... }: {
131+
inputs:
132+
(inputs.wrappers.lib.evalModule ({ config, wlib, lib, pkgs, ... }: {
134133
# You can only grab the final package if you supply pkgs!
135134
# But if you were making it for someone else, you would want them to do that!
136135
137136
# config.pkgs = pkgs;
138137
139-
imports = [ wlib.modules.default ]; # <-- includes wlib.modules.symlinkScript and wlib.modules.makeWrapper
138+
# include wlib.modules.makeWrapper and wlib.modules.symlinkScript
139+
imports = [ wlib.modules.default ];
140+
# The core options are focused on building a wrapper derivation.
141+
# different wrapper options may be implemented on top, for things like bubblewrap or other tools.
142+
# `wlib.modules.default` gives you a great module-based pkgs.makeWrapper to use.
143+
140144
options = {
141145
profile = lib.mkOption {
142146
type = lib.types.enum [ "fast" "quality" ];
@@ -162,27 +166,161 @@ packageAgain = apackage.wrap ({config, pkgs, ...}: {
162166

163167
`wrapPackage` comes with `wlib.modules.default` already included, and outputs the package directly!
164168

165-
Use this for quickly creating a custom wrapped program within your configuration!
169+
Use this for quickly creating a one-off wrapped program within your configuration!
166170

167171
```nix
168-
{ pkgs, wrappers, ... }:
169-
170-
wrappers.lib.wrapPackage ({ config, wlib, lib, ... }: {
171-
inherit pkgs; # you can only grab the final package if you supply pkgs!
172-
package = pkgs.curl;
173-
extraPackages = [ pkgs.jq ];
174-
env = {
175-
CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
172+
inputs: # <- get the lib somehow
173+
{ pkgs, ... }: {
174+
home.shellAliases = let
175+
curlwrapped = inputs.wrappers.lib.wrapPackage ({ config, wlib, lib, ... }: {
176+
inherit pkgs; # you can only grab the final package if you supply pkgs!
177+
package = pkgs.curl;
178+
extraPackages = [ pkgs.jq ];
179+
env = {
180+
CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
181+
};
182+
flags = {
183+
"--silent" = true;
184+
"--connect-timeout" = "30";
185+
};
186+
flagSeparator = "="; # Use --flag=value instead of --flag value (default is " ")
187+
runShell = [
188+
''
189+
echo "Making request..." >&2
190+
''
191+
];
192+
});
193+
in {
194+
runCurl = "${lib.getExe curlwrapped}";
176195
};
177-
flags = {
178-
"--silent" = true;
179-
"--connect-timeout" = "30";
196+
}
197+
```
198+
199+
### `nixos`, `home-manager`, And Friends
200+
201+
Because it uses the regular module system and evaluates as a `lib.types.submodule` option,
202+
this library has excellent integration with `nixos`, `home-manager`, `nix-darwin` and any other such systems.
203+
204+
With a single, simple function, you can use any wrapper module directly as a module in `configuration.nix` or `home.nix`!
205+
206+
```nix
207+
# in a nixos module
208+
{ ... }: {
209+
imports = [
210+
(inputs.wrappers.lib.mkInstallModule { name = "tmux"; value = inputs.wrappers.lib.wrapperModules.tmux; })
211+
];
212+
config.wrappers.tmux = {
213+
enable = true;
214+
modeKeys = "vi";
215+
statusKeys = "vi";
216+
vimVisualKeys = true;
180217
};
181-
flagSeparator = "="; # Use --flag=value instead of --flag value (default is " ")
182-
runShell = [
183-
''
184-
echo "Making request..." >&2
185-
''
218+
}
219+
```
220+
221+
```nix
222+
# in a home-manager module
223+
{ config, lib, ... }: {
224+
imports = [
225+
(inputs.wrappers.lib.mkInstallModule {
226+
loc = [ "home" "packages" ];
227+
name = "neovim";
228+
value = inputs.wrappers.lib.wrapperModules.neovim;
229+
})
186230
];
187-
})
231+
config.wrappers.neovim = { pkgs, lib, ... }: {
232+
enable = true;
233+
settings.config_directory = ./nvim;
234+
specs.stylix = {
235+
data = pkgs.vimPlugins.mini-base16;
236+
before = [ "INIT_MAIN" ];
237+
info = lib.filterAttrs (
238+
k: v: builtins.match "base0[0-9A-F]" k != null
239+
) config.lib.stylix.colors.withHashtag;
240+
config = /* lua */ ''
241+
local info, pname, lazy = ...
242+
require("mini.base16").setup({ palette = info, })
243+
'';
244+
};
245+
};
246+
home.sessionVariables = let
247+
# You can still grab the value from config if desired!
248+
nvimpath = lib.getExe config.wrappers.neovim.wrapper;
249+
in {
250+
EDITOR = nvimpath;
251+
MANPAGER = "${nvimpath} +Man!";
252+
};
253+
}
188254
```
255+
256+
See the [`wlib.mkInstallModule`](./wlib.html#function-library-wlib.mkInstallModule) documentation for more info!
257+
258+
### `flake-parts`
259+
260+
This repository also offers a [`flake-parts`](https://github.com/hercules-ci/flake-parts) module!
261+
262+
It offers a template! `nix flake init -t github:BirdeeHub/nix-wrapper-modules`
263+
264+
```nix
265+
{
266+
description = ''
267+
Uses flake-parts to set up the flake outputs:
268+
269+
`wrappers`, `wrapperModules` and `packages.*.*`
270+
'';
271+
inputs.wrappers.url = "github:BirdeeHub/nix-wrapper-modules";
272+
inputs.wrappers.inputs.nixpkgs.follows = "nixpkgs";
273+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
274+
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
275+
inputs.flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
276+
outputs =
277+
{
278+
self,
279+
nixpkgs,
280+
wrappers,
281+
flake-parts,
282+
...
283+
}@inputs:
284+
flake-parts.lib.mkFlake { inherit inputs; } {
285+
systems = nixpkgs.lib.platforms.all;
286+
# Import the flake-parts module:
287+
imports = [ wrappers.flakeModules.wrappers ];
288+
289+
perSystem =
290+
{ pkgs, ... }:
291+
{
292+
# wrappers.pkgs = pkgs; # choose a different `pkgs`
293+
wrappers.control_type = "exclude"; # | "build" (default: "exclude")
294+
wrappers.packages = {
295+
alacritty = true; # <- set to true to exclude from being built into `packages.*.*` flake output
296+
};
297+
};
298+
flake.wrappers.alacritty = { pkgs, wlib, ... }: {
299+
imports = [ wlib.wrapperModules.alacritty ];
300+
settings.terminal.shell.program = "${pkgs.zsh}/bin/zsh";
301+
settings.terminal.shell.args = [ "-l" ];
302+
};
303+
flake.wrappers.tmux =
304+
{ wlib, pkgs, ... }:
305+
{
306+
imports = [ wlib.wrapperModules.tmux ];
307+
plugins = with pkgs.tmuxPlugins; [ onedark-theme ];
308+
};
309+
flake.wrappers.xplr = wrappers.lib.wrapperModules.xplr;
310+
};
311+
}
312+
```
313+
314+
The above flake will export the partially evaluated submodule from `outputs.wrappers` as it shows.
315+
316+
However, it also offers the values in importable form from `outputs.wrapperModules` for you!
317+
318+
In addition to that, it will build `packages.*.*` for each of the systems and wrappers for you.
319+
320+
`perSystem.wrappers` options control which packages get built, and with what `pkgs`.
321+
322+
`wrappers.control_type` controls how `wrappers.packages` is handled.
323+
324+
If `wrappers.control_type` is `"exclude"`, then including `true` for a value will exclude its `packages` output.
325+
326+
If you change it to `"build"`, then you must include `true` for all you want to be built.

docs/md/wrapper-modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ They include shortlist options for common configuration settings, and/or for pro
1010

1111
The flake also exports wrapper modules that have been partially evaluated for convenience.
1212

13-
This allows you to do something like `inputs.nix-wrapper-modules.wrappedModules.tmux.wrap { inherit pkgs; prefix = "C-Space"; }`, to build a package with a particular configuration quickly!
13+
This allows you to do something like `inputs.nix-wrapper-modules.wrappers.tmux.wrap { inherit pkgs; prefix = "C-Space"; }`, to build a package with a particular configuration quickly!
1414

1515
You can then export that package, and somebody else could call `.wrap` on it as well to change it again!

flake.nix

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,53 @@
1818
in
1919
{
2020
lib = import ./lib { inherit lib; };
21-
wrappedModules = lib.mapAttrs (_: v: (self.lib.evalModule v).config) self.lib.wrapperModules;
22-
wrapperModules = lib.mapAttrs (
21+
flakeModules = {
22+
wrappers = ./parts.nix;
23+
default = self.flakeModules.wrappers;
24+
};
25+
nixosModules = builtins.mapAttrs (name: value: {
26+
inherit name value;
27+
_file = value;
28+
key = value;
29+
__functor = self.lib.mkInstallModule;
30+
}) self.lib.wrapperModules;
31+
homeModules = builtins.mapAttrs (
2332
_: v:
33+
v
34+
// {
35+
loc = [
36+
"home"
37+
"packages"
38+
];
39+
}
40+
) self.nixosModules;
41+
wrappers = lib.mapAttrs (_: v: (self.lib.evalModule v).config) self.lib.wrapperModules;
42+
wrappedModules = lib.mapAttrs (
43+
_:
44+
lib.warn ''
45+
Attention: `inputs.nix-wrapper-modules.wrappedModules` is deprecated, use `inputs.nix-wrapper-modules.wrappers` instead
46+
47+
Apologies for any inconvenience this has caused, but they are only the config set of a module, not a module themselves.
48+
49+
In addition, it was very hard to tell the name apart from its actual module counterpart, and it was longer than convenient.
50+
51+
This will be the last time these output names are changing, as a flake-parts module has been added for users to import.
52+
53+
This output will be removed on August 31, 2026
54+
''
55+
) self.wrappers;
56+
wrapperModules = lib.mapAttrs (
57+
_:
2458
lib.warn ''
25-
Attention: `wrapperModules` is deprecated, use `wrappedModules` instead
59+
Attention: `inputs.nix-wrapper-modules.wrapperModules` is deprecated, use `inputs.nix-wrapper-modules.wrappers` instead
2660
2761
Apologies for any inconvenience this has caused. But the title `wrapperModules` should be specific to ones you can import.
2862
2963
In the future, rather than being removed, this will be replaced by the unevaluated wrapper modules from `wlib.wrapperModules`
30-
'' (self.lib.evalModule v).config
31-
) self.lib.wrapperModules;
64+
65+
This output will be replaced with module paths on April 30, 2026
66+
''
67+
) self.wrappers;
3268
formatter = forAllSystems (system: (fpkgs system).nixfmt-tree);
3369
templates = import ./templates;
3470
checks = forAllSystems (

0 commit comments

Comments
 (0)