@adrifer/winix 0.2.0-preview.2 → 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 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 are reusable lazy fragments. Profiles are reusable bundles.
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
- Fragments can return one fragment or an array of fragments:
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:
@@ -7,8 +7,7 @@ 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
9
  export declare function feature<T extends unknown[]>(id: string, factory: (ctx: WinixContext, ...args: T) => AuthoringResult): FragmentFactory<T>;
10
- export declare function profile<T extends unknown[]>(id: string, factory: (ctx: WinixContext, ...args: T) => AuthoringResult): ProfileFactory<T>;
11
- export declare function profile(id: string, entries: FragmentEntry | readonly FragmentEntry[]): ProfileFactory<[]>;
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
12
  export declare function host(name: string, platform: PlatformLazyFragment, body: (ctx: WinixContext) => AuthoringResult): HostDef;
14
13
  export declare function workspace(def: WorkspaceDef): WorkspaceDef;
package/dist/sdk/index.js CHANGED
@@ -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
- export function profile(id, entriesOrFactory) {
79
- const factory = typeof entriesOrFactory === "function"
80
- ? entriesOrFactory
81
- : ((_ctx, ..._args) => entriesOrFactory);
82
- return feature(id, factory);
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") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adrifer/winix",
3
- "version": "0.2.0-preview.2",
3
+ "version": "0.2.0-preview.3",
4
4
  "description": "TypeScript-first system configuration for NixOS, nix-darwin, and Home Manager",
5
5
  "license": "MIT",
6
6
  "author": "Adrian Fernandez",