Skip to content

Commit 31a6d86

Browse files
committed
wrapModule: output module instead of wrapper, move wrapper to module
1 parent 43957c3 commit 31a6d86

7 files changed

Lines changed: 57 additions & 44 deletions

File tree

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ This library provides two main components:
2323
```nix
2424
{
2525
inputs.wrappers.url = "github:lassulus/wrappers";
26-
26+
2727
outputs = { self, nixpkgs, wrappers }: {
28-
packages.x86_64-linux.default =
29-
wrappers.wrapperModules.mpv.apply {
28+
packages.x86_64-linux.default =
29+
(wrappers.wrapperModules.mpv.apply {
3030
pkgs = nixpkgs.legacyPackages.x86_64-linux;
3131
scripts = [ pkgs.mpvScripts.mpris ];
3232
"mpv.conf".content = ''
@@ -37,7 +37,7 @@ This library provides two main components:
3737
WHEEL_UP seek 10
3838
WHEEL_DOWN seek -10
3939
'';
40-
};
40+
}).wrapper;
4141
};
4242
}
4343
```
@@ -132,7 +132,8 @@ The function:
132132
Creates a reusable wrapper module with:
133133
- Type-safe configuration options via the module system
134134
- `options`: Exposed options for documentation generation
135-
- `apply`: Function to instantiate the wrapper with settings
135+
- `apply`: Function to instantiate the wrapper with settings, returning a config object
136+
- Access the wrapped package via the `wrapper` attribute of the returned config
136137

137138
Built-in options (always available):
138139
- `pkgs`: nixpkgs instance (required)
@@ -144,6 +145,8 @@ Built-in options (always available):
144145
- `env`: Environment variables
145146
- `passthru`: Additional passthru attributes
146147
- `filesToPatch`: List of file paths (glob patterns) to patch for self-references (default: `["share/applications/*.desktop"]`)
148+
- `filesToExclude`: List of file paths (glob patterns) to exclude from the wrapped package (default: `[]`)
149+
- `wrapper`: The resulting wrapped package (read-only, auto-generated from other options)
147150

148151
Custom types:
149152
- `wlib.types.file`: File type with `content` and `path` options
@@ -165,7 +168,7 @@ The wrapper module system integrates with NixOS module evaluation:
165168
Wraps mpv with configuration file support and script management:
166169

167170
```nix
168-
wrappers.wrapperModules.mpv.apply {
171+
(wrappers.wrapperModules.mpv.apply {
169172
pkgs = pkgs;
170173
scripts = [ pkgs.mpvScripts.mpris pkgs.mpvScripts.thumbnail ];
171174
"mpv.conf".content = ''
@@ -179,15 +182,15 @@ wrappers.wrapperModules.mpv.apply {
179182
extraFlags = {
180183
"--save-position-on-quit" = {};
181184
};
182-
}
185+
}).wrapper
183186
```
184187

185188
### notmuch Module
186189

187190
Wraps notmuch with INI-based configuration:
188191

189192
```nix
190-
wrappers.wrapperModules.notmuch.apply {
193+
(wrappers.wrapperModules.notmuch.apply {
191194
pkgs = pkgs;
192195
config = {
193196
database = {
@@ -199,7 +202,7 @@ wrappers.wrapperModules.notmuch.apply {
199202
primary_email = "john@example.com";
200203
};
201204
};
202-
}
205+
}).wrapper
203206
```
204207

205208
## Long-term Goals

checks/flags-module.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let
1515
}
1616
);
1717

18-
wrappedPackage = helloModule.apply { inherit pkgs; };
18+
wrappedPackage = (helloModule.apply { inherit pkgs; }).wrapper;
1919

2020
in
2121
pkgs.runCommand "module-flags-test" { } ''

checks/module-filesToExclude.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ let
5858
];
5959
};
6060

61-
wrappedPackage = testModule.apply { inherit pkgs; };
61+
wrappedPackage = (testModule.apply { inherit pkgs; }).wrapper;
6262

6363
in
6464
pkgs.runCommand "module-filesToExclude-test" { } ''

lib.nix

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let
5959
# This will return a derivation that wraps the hello package with the --greeting flag set to "hi".
6060
*/
6161
wrapModule =
62-
packageInterface:
62+
moduleInterface:
6363
let
6464
wrapperLib = {
6565
types = {
@@ -180,6 +180,27 @@ let
180180
Example: [ "bin/unwanted-tool" "share/applications/*.desktop" ]
181181
'';
182182
};
183+
wrapper = lib.mkOption {
184+
type = lib.types.package;
185+
readOnly = true;
186+
description = ''
187+
The wrapped package created by wrapPackage. This wraps the configured package
188+
with the specified flags, environment variables, runtime dependencies, and other
189+
options in a portable way.
190+
'';
191+
default = wrapPackage {
192+
pkgs = config.pkgs;
193+
package = config.package;
194+
runtimeInputs = config.extraPackages;
195+
flags = config.flags;
196+
flagSeparator = config.flagSeparator;
197+
args = config.args;
198+
env = config.env;
199+
filesToPatch = config.filesToPatch;
200+
filesToExclude = config.filesToExclude;
201+
passthru = config.passthru;
202+
};
203+
};
183204
};
184205
}
185206
)
@@ -193,7 +214,7 @@ let
193214
{
194215
options.interface = lib.mkOption {
195216
type = lib.types.deferredModule;
196-
default = packageInterface;
217+
default = moduleInterface;
197218
};
198219
options.settings = lib.mkOption {
199220
type = lib.types.deferredModule;
@@ -231,21 +252,7 @@ let
231252
configuration = eval settings;
232253
config = configuration.config.result.config;
233254
in
234-
wrapPackage {
235-
pkgs = config.pkgs;
236-
package = config.package;
237-
runtimeInputs = config.extraPackages;
238-
flags = config.flags;
239-
flagSeparator = config.flagSeparator;
240-
args = config.args;
241-
env = config.env;
242-
filesToPatch = config.filesToPatch;
243-
filesToExclude = config.filesToExclude;
244-
passthru = {
245-
inherit configuration settings;
246-
}
247-
// config.passthru;
248-
};
255+
config;
249256
};
250257

251258
/**

modules/helix/check.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
}:
55

66
let
7-
helixWrapped = self.wrapperModules.helix.apply {
8-
inherit pkgs;
9-
};
7+
helixWrapped =
8+
(self.wrapperModules.helix.apply {
9+
inherit pkgs;
10+
}).wrapper;
1011

1112
in
1213
pkgs.runCommand "helix-test" { } ''

modules/mpv/check.nix

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
}:
55

66
let
7-
mpvWrapped = self.wrapperModules.mpv.apply {
8-
inherit pkgs;
9-
"mpv.conf".content = ''
10-
ao=null
11-
vo=null
12-
'';
13-
};
7+
mpvWrapped =
8+
(self.wrapperModules.mpv.apply {
9+
inherit pkgs;
10+
"mpv.conf".content = ''
11+
ao=null
12+
vo=null
13+
'';
14+
}).wrapper;
1415

1516
in
1617
pkgs.runCommand "mpv-test" { } ''

modules/notmuch/check.nix

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
}:
55

66
let
7-
notmuchWrapped = self.wrapperModules.notmuch.apply {
8-
inherit pkgs;
9-
settings = {
10-
database.path = "/tmp/test-mail";
11-
};
12-
};
7+
notmuchWrapped =
8+
(self.wrapperModules.notmuch.apply {
9+
inherit pkgs;
10+
settings = {
11+
database.path = "/tmp/test-mail";
12+
};
13+
}).wrapper;
1314

1415
in
1516
pkgs.runCommand "notmuch-test" { } ''

0 commit comments

Comments
 (0)