@adrifer/winix 0.2.0-preview.1 → 0.2.0-preview.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -13
- package/dist/core/types.d.ts +17 -0
- package/dist/sdk/index.d.ts +4 -5
- package/dist/sdk/index.js +23 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
home,
|
|
20
20
|
host,
|
|
21
21
|
input,
|
|
22
|
-
nixos,
|
|
23
22
|
platforms,
|
|
24
23
|
workspace,
|
|
25
24
|
} from "@adrifer/winix";
|
|
@@ -34,13 +33,13 @@ const inputs = defineInputs({
|
|
|
34
33
|
}),
|
|
35
34
|
});
|
|
36
35
|
|
|
37
|
-
const wsl = feature("wsl", () =>
|
|
38
|
-
nixos.imports("inputs.nixos-wsl.nixosModules.wsl")
|
|
39
|
-
nixos({ wsl: { enable: true } })
|
|
40
|
-
nixos.program("nix-ld")
|
|
41
|
-
|
|
36
|
+
const wsl = feature("wsl", ({ nixos }) => {
|
|
37
|
+
nixos.imports("inputs.nixos-wsl.nixosModules.wsl");
|
|
38
|
+
nixos({ wsl: { enable: true } });
|
|
39
|
+
nixos.program("nix-ld");
|
|
40
|
+
});
|
|
42
41
|
|
|
43
|
-
const shell = feature("shell", () =>
|
|
42
|
+
const shell = feature("shell", ({ home, platforms }) =>
|
|
44
43
|
home.program("zsh", {
|
|
45
44
|
shellAliases: {
|
|
46
45
|
g: "lazygit",
|
|
@@ -72,6 +71,11 @@ export default workspace({
|
|
|
72
71
|
});
|
|
73
72
|
```
|
|
74
73
|
|
|
74
|
+
Feature and host callbacks receive an injected context
|
|
75
|
+
(`{ home, nixos, darwin, windows, platforms }`); declarations made through it
|
|
76
|
+
register automatically, so no `return` is needed. The older style still works:
|
|
77
|
+
import the helpers as globals and `return` the fragments you build.
|
|
78
|
+
|
|
75
79
|
## Why Winix?
|
|
76
80
|
|
|
77
81
|
- **Use TypeScript as the authoring language.** Compose functions, arrays, objects, conditionals, and package-specific helpers without inventing another DSL.
|
|
@@ -183,15 +187,16 @@ export default workspace({
|
|
|
183
187
|
|
|
184
188
|
### Features and profiles
|
|
185
189
|
|
|
186
|
-
Features
|
|
190
|
+
Features **declare** config and are the flexible building block. Profiles
|
|
191
|
+
**group** features and take an array of entries only (no callback).
|
|
187
192
|
|
|
188
193
|
```ts
|
|
189
|
-
const git = feature("git", () =>
|
|
194
|
+
const git = feature("git", ({ home }) => {
|
|
190
195
|
home.program("git", {
|
|
191
196
|
userName: "Adrian Fernandez",
|
|
192
197
|
userEmail: "me@example.com",
|
|
193
|
-
})
|
|
194
|
-
);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
195
200
|
|
|
196
201
|
const developer = profile("developer", [
|
|
197
202
|
git(),
|
|
@@ -199,7 +204,8 @@ const developer = profile("developer", [
|
|
|
199
204
|
]);
|
|
200
205
|
```
|
|
201
206
|
|
|
202
|
-
|
|
207
|
+
A feature can also return one fragment or an array of fragments (the older
|
|
208
|
+
style still works):
|
|
203
209
|
|
|
204
210
|
```ts
|
|
205
211
|
const neovim = feature("neovim", () => [
|
|
@@ -208,12 +214,15 @@ const neovim = feature("neovim", () => [
|
|
|
208
214
|
]);
|
|
209
215
|
```
|
|
210
216
|
|
|
217
|
+
When a feature body composes other features, return them: a `feature()`/
|
|
218
|
+
`profile()` call yields a lazy fragment that is not auto-collected.
|
|
219
|
+
|
|
211
220
|
### Platform-aware configuration
|
|
212
221
|
|
|
213
222
|
Fragments can ask whether another platform or feature is active.
|
|
214
223
|
|
|
215
224
|
```ts
|
|
216
|
-
const shell = feature("shell", () =>
|
|
225
|
+
const shell = feature("shell", ({ home, platforms }) =>
|
|
217
226
|
home.program("zsh", {
|
|
218
227
|
shellAliases: {
|
|
219
228
|
...(platforms.nixos.isActive && { rebuild: "sudo nixos-rebuild switch" }),
|
|
@@ -323,6 +332,30 @@ rawModule.homeManager("./legacy/home.nix")
|
|
|
323
332
|
rawModule.darwin("./legacy/darwin.nix")
|
|
324
333
|
```
|
|
325
334
|
|
|
335
|
+
### Windows (preview)
|
|
336
|
+
|
|
337
|
+
Winix has an early native Windows backend. Declare a `platforms.windows()` host
|
|
338
|
+
and install winget/msstore packages with `windows.package(...)`; use
|
|
339
|
+
`windows.raw(...)` for arbitrary commands. Both return a handle you can pass to
|
|
340
|
+
another resource's `dependsOn` to express ordering.
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
host("desktop", platforms.windows(), ({ windows }) => {
|
|
344
|
+
const node = windows.package("OpenJS.NodeJS");
|
|
345
|
+
windows.package({ source: "msstore", id: "9NKSQGP7F2NH" });
|
|
346
|
+
windows.raw({
|
|
347
|
+
executable: "npm",
|
|
348
|
+
arguments: ["install", "--global", "typescript"],
|
|
349
|
+
dependsOn: node,
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
This generates a DSC v3 document that `winget configure` applies. The backend is
|
|
355
|
+
an MVP: only `windows.package` and `windows.raw` exist today. See
|
|
356
|
+
[`examples/windows/`](examples/windows) and
|
|
357
|
+
[`spec/proposals/windows-backend.md`](spec/proposals/windows-backend.md).
|
|
358
|
+
|
|
326
359
|
## Generated Nix
|
|
327
360
|
|
|
328
361
|
Winix evaluates fragments in two passes:
|
package/dist/core/types.d.ts
CHANGED
|
@@ -65,6 +65,23 @@ export type FragmentEntry = LazyFragment | Fragment | readonly FragmentEntry[];
|
|
|
65
65
|
* What a lazy fragment can resolve into.
|
|
66
66
|
*/
|
|
67
67
|
export type FragmentResult = FragmentEntry;
|
|
68
|
+
/**
|
|
69
|
+
* The return type allowed for *authoring callbacks* (`feature`/`profile`/`host`
|
|
70
|
+
* bodies). It is a `FragmentResult` OR nothing (`void`/`undefined`), because a
|
|
71
|
+
* callback may declare purely by effect through the injected namespaces and
|
|
72
|
+
* return nothing at all:
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* feature("dev", ({ home }) => { home.program("git"); }); // returns void
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* The runtime already treats a `undefined`/`null` return as "no returned
|
|
79
|
+
* content" and falls back to the collected effects (see
|
|
80
|
+
* `mergeEffectsAndReturn`); this type makes the public signatures match that
|
|
81
|
+
* behavior. `FragmentResult` itself stays strict for internal use where a
|
|
82
|
+
* concrete result is always present.
|
|
83
|
+
*/
|
|
84
|
+
export type AuthoringResult = FragmentResult | void;
|
|
68
85
|
/**
|
|
69
86
|
* A lazy fragment descriptor: holds the factory + args for deferred evaluation.
|
|
70
87
|
*/
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { type WinixContext } from "./context.js";
|
|
2
|
-
import type { Fragment, FragmentFactory, PlatformFactory, ProfileFactory, PlatformLazyFragment, FragmentEntry,
|
|
2
|
+
import type { Fragment, FragmentFactory, PlatformFactory, ProfileFactory, PlatformLazyFragment, FragmentEntry, AuthoringResult, InputDef, InputWithOptions, WorkspaceDef, HostDef, EvalContext, NixExpr } from "../core/types.js";
|
|
3
3
|
export declare function setEvalContext(ctx: EvalContext): EvalContext | null;
|
|
4
4
|
export declare function restoreEvalContext(ctx: EvalContext | null): void;
|
|
5
5
|
export declare function clearEvalContext(): void;
|
|
6
6
|
export declare function getEvalContext(): EvalContext;
|
|
7
7
|
export declare function getOptionalEvalContext(): EvalContext | null;
|
|
8
8
|
export declare function platform<T extends unknown[]>(id: string, factory: (...args: T) => Fragment): PlatformFactory<T>;
|
|
9
|
-
export declare function feature<T extends unknown[]>(id: string, factory: (ctx: WinixContext, ...args: T) =>
|
|
10
|
-
export declare function profile
|
|
11
|
-
export declare function profile(id: string, entries: FragmentEntry | readonly FragmentEntry[]): ProfileFactory<[]>;
|
|
9
|
+
export declare function feature<T extends unknown[]>(id: string, factory: (ctx: WinixContext, ...args: T) => AuthoringResult): FragmentFactory<T>;
|
|
10
|
+
export declare function profile(id: string, entries: readonly FragmentEntry[]): ProfileFactory<[]>;
|
|
12
11
|
export declare function host(name: string, platform: PlatformLazyFragment, fragments: readonly FragmentEntry[]): HostDef;
|
|
13
|
-
export declare function host(name: string, platform: PlatformLazyFragment, body: (ctx: WinixContext) =>
|
|
12
|
+
export declare function host(name: string, platform: PlatformLazyFragment, body: (ctx: WinixContext) => AuthoringResult): HostDef;
|
|
14
13
|
export declare function workspace(def: WorkspaceDef): WorkspaceDef;
|
|
15
14
|
export declare function input(url: string, opts?: Omit<InputWithOptions, "url">): InputWithOptions;
|
|
16
15
|
export declare function defineInputs<T extends Record<string, InputDef>>(inputs: T): T;
|
package/dist/sdk/index.js
CHANGED
|
@@ -58,7 +58,7 @@ export function feature(id, factory) {
|
|
|
58
58
|
__id: id,
|
|
59
59
|
__resolve: () => {
|
|
60
60
|
const ctx = createWinixContext();
|
|
61
|
-
let returned;
|
|
61
|
+
let returned = undefined;
|
|
62
62
|
const effects = withCollector(() => {
|
|
63
63
|
returned = factory(ctx, ...args);
|
|
64
64
|
});
|
|
@@ -75,11 +75,27 @@ export function feature(id, factory) {
|
|
|
75
75
|
Object.defineProperty(fn, "id", { value: id, configurable: true, enumerable: false });
|
|
76
76
|
return fn;
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
// --- profile() ---
|
|
79
|
+
//
|
|
80
|
+
// Unlike feature(), a profile is intentionally restricted: it only accepts an
|
|
81
|
+
// array of entries (instantiated features/profiles and bare fragments such as
|
|
82
|
+
// overlay.stable(...) or nixos.boot(...)). It does NOT accept an authoring
|
|
83
|
+
// callback, so a profile cannot declare by effect or take injected context.
|
|
84
|
+
// The model is: features declare (effects/return), profiles group features.
|
|
85
|
+
// If a grouping needs logic or injected namespaces, put that logic in a
|
|
86
|
+
// feature() and add that feature to the profile's array.
|
|
87
|
+
export function profile(id, entries) {
|
|
88
|
+
if (typeof entries === "function") {
|
|
89
|
+
throw new TypeError(`profile("${id}", ...) only accepts an array of entries, not a callback. ` +
|
|
90
|
+
`Profiles group features; they cannot declare by effect or take injected ` +
|
|
91
|
+
`context. Move that logic into a feature() and add it to the array: ` +
|
|
92
|
+
`profile("${id}", [myFeature(), ...]).`);
|
|
93
|
+
}
|
|
94
|
+
if (!Array.isArray(entries)) {
|
|
95
|
+
throw new TypeError(`profile("${id}", ...) expects an array of entries, e.g. ` +
|
|
96
|
+
`profile("${id}", [featureA(), featureB()]).`);
|
|
97
|
+
}
|
|
98
|
+
return feature(id, () => entries);
|
|
83
99
|
}
|
|
84
100
|
export function host(name, platform, fragmentsOrBody) {
|
|
85
101
|
if (typeof fragmentsOrBody === "function") {
|
|
@@ -93,7 +109,7 @@ export function host(name, platform, fragmentsOrBody) {
|
|
|
93
109
|
__id: `${name}:inline`,
|
|
94
110
|
__resolve: () => {
|
|
95
111
|
const ctx = createWinixContext();
|
|
96
|
-
let returned;
|
|
112
|
+
let returned = undefined;
|
|
97
113
|
const effects = withCollector(() => {
|
|
98
114
|
returned = body(ctx);
|
|
99
115
|
});
|
package/package.json
CHANGED