@adrifer/winix 0.1.0

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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +291 -0
  3. package/dist/backends/nix/index.d.ts +18 -0
  4. package/dist/backends/nix/index.js +442 -0
  5. package/dist/cli/activation.d.ts +6 -0
  6. package/dist/cli/activation.js +19 -0
  7. package/dist/cli/analysis.d.ts +30 -0
  8. package/dist/cli/analysis.js +170 -0
  9. package/dist/cli/commands/apply.d.ts +14 -0
  10. package/dist/cli/commands/apply.js +180 -0
  11. package/dist/cli/commands/check.d.ts +6 -0
  12. package/dist/cli/commands/check.js +46 -0
  13. package/dist/cli/commands/init.d.ts +5 -0
  14. package/dist/cli/commands/init.js +69 -0
  15. package/dist/cli/commands/inspect.d.ts +1 -0
  16. package/dist/cli/commands/inspect.js +24 -0
  17. package/dist/cli/commands/switch.d.ts +7 -0
  18. package/dist/cli/commands/switch.js +40 -0
  19. package/dist/cli/commands/update.d.ts +6 -0
  20. package/dist/cli/commands/update.js +33 -0
  21. package/dist/cli/index.d.ts +2 -0
  22. package/dist/cli/index.js +122 -0
  23. package/dist/cli/loader.d.ts +11 -0
  24. package/dist/cli/loader.js +49 -0
  25. package/dist/cli/run.d.ts +4 -0
  26. package/dist/cli/run.js +26 -0
  27. package/dist/cli/types-gen/parser.d.ts +14 -0
  28. package/dist/cli/types-gen/parser.js +275 -0
  29. package/dist/core/index.d.ts +1 -0
  30. package/dist/core/index.js +1 -0
  31. package/dist/core/types.d.ts +106 -0
  32. package/dist/core/types.js +2 -0
  33. package/dist/evaluator/index.d.ts +20 -0
  34. package/dist/evaluator/index.js +184 -0
  35. package/dist/helpers/account.d.ts +46 -0
  36. package/dist/helpers/account.js +165 -0
  37. package/dist/helpers/darwin.d.ts +36 -0
  38. package/dist/helpers/darwin.js +38 -0
  39. package/dist/helpers/home.d.ts +40 -0
  40. package/dist/helpers/home.js +63 -0
  41. package/dist/helpers/index.d.ts +14 -0
  42. package/dist/helpers/index.js +7 -0
  43. package/dist/helpers/nix.d.ts +36 -0
  44. package/dist/helpers/nix.js +157 -0
  45. package/dist/helpers/nixos.d.ts +53 -0
  46. package/dist/helpers/nixos.js +86 -0
  47. package/dist/helpers/options.d.ts +10 -0
  48. package/dist/helpers/options.js +1 -0
  49. package/dist/helpers/overlay.d.ts +13 -0
  50. package/dist/helpers/overlay.js +29 -0
  51. package/dist/helpers/platforms.d.ts +21 -0
  52. package/dist/helpers/platforms.js +62 -0
  53. package/dist/helpers/utils.d.ts +6 -0
  54. package/dist/helpers/utils.js +8 -0
  55. package/dist/index.d.ts +9 -0
  56. package/dist/index.js +5 -0
  57. package/dist/sdk/index.d.ts +26 -0
  58. package/dist/sdk/index.js +183 -0
  59. package/dist/types/common.d.ts +10 -0
  60. package/dist/types/common.js +1 -0
  61. package/dist/types/darwin.d.ts +86 -0
  62. package/dist/types/darwin.js +1 -0
  63. package/dist/types/home.d.ts +45 -0
  64. package/dist/types/home.js +1 -0
  65. package/dist/types/index.d.ts +5 -0
  66. package/dist/types/index.js +5 -0
  67. package/dist/types/nixos.d.ts +225 -0
  68. package/dist/types/nixos.js +1 -0
  69. package/dist/types/programs.d.ts +67 -0
  70. package/dist/types/programs.js +1 -0
  71. package/index.d.ts +5 -0
  72. package/package.json +69 -0
  73. package/types/bundled/darwin.d.ts +476 -0
  74. package/types/bundled/home-manager.d.ts +4674 -0
  75. package/types/bundled/nixos.d.ts +19991 -0
  76. package/types/index.d.ts +8 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Adrian Fernandez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # Winix
2
+
3
+ **TypeScript-first system configuration for NixOS, nix-darwin, and Home Manager.**
4
+
5
+ Winix lets you write system configuration as typed, composable TypeScript fragments and generates a normal Nix flake that `nixos-rebuild`, `darwin-rebuild`, and Home Manager can consume.
6
+
7
+ ```ts
8
+ // winix.config.ts
9
+ import {
10
+ account,
11
+ defineInputs,
12
+ feature,
13
+ home,
14
+ host,
15
+ input,
16
+ nixos,
17
+ platforms,
18
+ workspace,
19
+ } from "@adrifer/winix";
20
+
21
+ const inputs = defineInputs({
22
+ nixpkgs: "nixos-unstable",
23
+ homeManager: input("github:nix-community/home-manager", {
24
+ follows: { nixpkgs: "nixpkgs" },
25
+ }),
26
+ nixosWsl: input("github:nix-community/NixOS-WSL", {
27
+ follows: { nixpkgs: "nixpkgs" },
28
+ }),
29
+ });
30
+
31
+ const wsl = feature("wsl", () => [
32
+ nixos.imports("nixos-wsl"),
33
+ nixos({ wsl: { enable: true } }),
34
+ nixos.program("nix-ld"),
35
+ ]);
36
+
37
+ const shell = feature("shell", () =>
38
+ home.program("zsh", {
39
+ shellAliases: {
40
+ g: "lazygit",
41
+ ...(platforms.nixos.isActive && {
42
+ i: "sudo nixos-rebuild switch --flake path:$PWD/.winix/out",
43
+ }),
44
+ ...(platforms.darwin.isActive && {
45
+ i: "sudo darwin-rebuild switch --flake path:$PWD/.winix/out",
46
+ }),
47
+ },
48
+ })
49
+ );
50
+
51
+ export default workspace({
52
+ inputs,
53
+ hosts: [
54
+ host("wsl-work", platforms.nixos({ stateVersion: "25.05" }), [
55
+ account.user("adrifer", () => ({
56
+ admin: true,
57
+ shell: "zsh",
58
+ stateVersion: "25.05",
59
+ wslDefault: true,
60
+ }))(),
61
+ wsl(),
62
+ shell(),
63
+ home.packages("neovim", "ripgrep", "fd"),
64
+ ]),
65
+ ],
66
+ });
67
+ ```
68
+
69
+ ## Why Winix?
70
+
71
+ - **Use TypeScript as the authoring language.** Compose functions, arrays, objects, conditionals, and package-specific helpers without inventing another DSL.
72
+ - **Keep Nix as the output.** Winix writes `.winix/out/flake.nix` and host modules; the final build still runs through Nix.
73
+ - **One model for NixOS, nix-darwin, and Home Manager.** Share features across Linux, macOS, WSL, servers, and profiles.
74
+ - **Typed helpers for common config.** Use `nixos.networking()`, `home.program()`, `darwin.homebrew()`, `account.user()`, and more.
75
+ - **Escape hatches when needed.** Drop to `nix.expr()`, `nixos.raw()`, or `rawModule()` without leaving the system.
76
+
77
+ > Winix is early software. The core pipeline works end-to-end, but the public API is still evolving.
78
+
79
+ ## Install
80
+
81
+ ```bash
82
+ npm install @adrifer/winix
83
+ ```
84
+
85
+ Winix expects Node.js with native TypeScript stripping support for `winix.config.ts` files. Node 22+ is recommended.
86
+
87
+ To create a new project:
88
+
89
+ ```bash
90
+ npx @adrifer/winix init
91
+ npm install
92
+ ```
93
+
94
+ ## CLI
95
+
96
+ ```bash
97
+ winix check # validate winix.config.ts
98
+ winix apply # generate .winix/out/
99
+ winix apply --dry # print generated Nix without writing files
100
+ winix apply --diff # show changes against current .winix/out/
101
+ winix switch --host my-host # generate and run nixos-rebuild/darwin-rebuild
102
+ winix update # update generated flake.lock and copy it back
103
+ winix inspect # inspect host composition and fragments
104
+ ```
105
+
106
+ Generated output lives under:
107
+
108
+ ```text
109
+ .winix/out/
110
+ flake.nix
111
+ hosts/
112
+ <host>.nix
113
+ ```
114
+
115
+ You can also run the generated flake manually:
116
+
117
+ ```bash
118
+ sudo nixos-rebuild switch --flake path:$(pwd)/.winix/out#my-host
119
+ sudo darwin-rebuild switch --flake path:$(pwd)/.winix/out#macbook
120
+ ```
121
+
122
+ ## Core concepts
123
+
124
+ ### Workspaces and hosts
125
+
126
+ A workspace declares inputs and hosts. Each host has exactly one platform and a list of fragments.
127
+
128
+ ```ts
129
+ export default workspace({
130
+ inputs: {
131
+ nixpkgs: "nixos-unstable",
132
+ homeManager: input("github:nix-community/home-manager", {
133
+ follows: { nixpkgs: "nixpkgs" },
134
+ }),
135
+ },
136
+ hosts: [
137
+ host("server", platforms.nixos({ stateVersion: "25.05" }), [
138
+ serverProfile(),
139
+ ]),
140
+ host("macbook", platforms.darwin({ stateVersion: 6, homebrew: true }), [
141
+ macProfile(),
142
+ ]),
143
+ ],
144
+ });
145
+ ```
146
+
147
+ ### Features and profiles
148
+
149
+ Features are reusable lazy fragments. Profiles are reusable bundles.
150
+
151
+ ```ts
152
+ const git = feature("git", () =>
153
+ home.program("git", {
154
+ userName: "Adrian Fernandez",
155
+ userEmail: "me@example.com",
156
+ })
157
+ );
158
+
159
+ const developer = profile("developer", [
160
+ git(),
161
+ home.packages("neovim", "lazygit", "ripgrep"),
162
+ ]);
163
+ ```
164
+
165
+ Fragments can return one fragment or an array of fragments:
166
+
167
+ ```ts
168
+ const neovim = feature("neovim", () => [
169
+ home.packages("neovim"),
170
+ home.env({ EDITOR: "nvim" }),
171
+ ]);
172
+ ```
173
+
174
+ ### Platform-aware configuration
175
+
176
+ Fragments can ask whether another platform or feature is active.
177
+
178
+ ```ts
179
+ const shell = feature("shell", () =>
180
+ home.program("zsh", {
181
+ shellAliases: {
182
+ ...(platforms.nixos.isActive && { rebuild: "sudo nixos-rebuild switch" }),
183
+ ...(platforms.darwin.isActive && { rebuild: "sudo darwin-rebuild switch" }),
184
+ },
185
+ })
186
+ );
187
+ ```
188
+
189
+ ### Account helpers
190
+
191
+ `account.user()` wires together platform users and Home Manager users.
192
+
193
+ ```ts
194
+ const adrifer = account.user("adrifer", () => ({
195
+ admin: true,
196
+ shell: "zsh",
197
+ stateVersion: "25.05",
198
+ wslDefault: true,
199
+ }));
200
+
201
+ host("wsl", platforms.nixos({ stateVersion: "25.05" }), [
202
+ adrifer(),
203
+ ]);
204
+ ```
205
+
206
+ ### Curated helpers
207
+
208
+ Winix includes helpers for common Nix namespaces:
209
+
210
+ ```ts
211
+ nixos.imports("nixos-wsl")
212
+ nixos.networking({ hostName: "server", firewall: { allowedTCPPorts: [22, 443] } })
213
+ nixos.service("openssh", { settings: { PermitRootLogin: "no" } })
214
+ nixos.systemd.service("backup", { script: "echo backup" })
215
+ nixos.users({ users: { root: { shell: nix.pkg("bash") } } })
216
+ nixos.system({ stateVersion: "25.05" })
217
+
218
+ home.program("zsh", { enableCompletion: true })
219
+ home.configFiles({ nvim: home.symlink("~/dotfiles/nvim/.config/nvim") })
220
+ home.activation("ensureNpmrc", { script: "mkdir -p \"$HOME/.config/npm\"" })
221
+
222
+ darwin.defaults({ dock: { autohide: true } })
223
+ darwin.homebrew({ enable: true, casks: ["visual-studio-code"] })
224
+ darwin.launchd.agent("emacs", {
225
+ serviceConfig: { ProgramArguments: ["emacs", "--fg-daemon"] },
226
+ })
227
+ ```
228
+
229
+ Plain object fragments are still supported for options that do not have helpers yet.
230
+
231
+ ### Nix escape hatches
232
+
233
+ Use `nix.*` when a value needs to be a Nix expression:
234
+
235
+ ```ts
236
+ nix.pkg("zsh")
237
+ nix.bin("git", "git")
238
+ nix.str`${nix.pkg("neovim")}/bin/nvim`
239
+ nix.script`
240
+ echo "hello from activation"
241
+ `
242
+ nix.lib.mkForce(["https://cache.nixos.org/"])
243
+ ```
244
+
245
+ For bigger migrations, import existing Nix modules:
246
+
247
+ ```ts
248
+ rawModule("./legacy/system.nix")
249
+ rawModule.homeManager("./legacy/home.nix")
250
+ rawModule.darwin("./legacy/darwin.nix")
251
+ ```
252
+
253
+ ## Generated Nix
254
+
255
+ Winix evaluates fragments in two passes:
256
+
257
+ 1. Collect active fragment IDs so `.isActive` works.
258
+ 2. Resolve lazy fragments and deep-merge the results.
259
+ 3. Generate a flake and one host module per host.
260
+
261
+ Objects merge recursively, arrays append, and scalar values use last-wins semantics.
262
+
263
+ ## Type generation
264
+
265
+ Winix ships bundled option augmentations and can generate/update local option types:
266
+
267
+ ```bash
268
+ winix types generate
269
+ winix types generate nixos
270
+ winix types generate home-manager
271
+ winix types generate darwin
272
+ ```
273
+
274
+ ## Project status
275
+
276
+ Winix is currently best suited for personal configurations and experimentation. The core workflow is functional, but expect API refinements before a stable `1.0`.
277
+
278
+ ## Development
279
+
280
+ ```bash
281
+ git clone https://github.com/adrifer/winix.git
282
+ cd winix
283
+ npm install
284
+ npm run check
285
+ npm test -- --run
286
+ npm run build
287
+ ```
288
+
289
+ ## License
290
+
291
+ MIT
@@ -0,0 +1,18 @@
1
+ import type { EvaluatedHost } from "../../evaluator/index.js";
2
+ import type { WorkspaceDef } from "../../core/types.js";
3
+ /**
4
+ * Generated output for a workspace.
5
+ */
6
+ export interface NixOutput {
7
+ "flake.nix": string;
8
+ hosts: Record<string, string>;
9
+ rawModules: RawModuleCopy[];
10
+ warnings: string[];
11
+ }
12
+ export interface RawModuleCopy {
13
+ path: string;
14
+ }
15
+ /**
16
+ * Generate Nix files from an evaluated workspace.
17
+ */
18
+ export declare function generateNix(workspace: WorkspaceDef, evaluatedHosts: EvaluatedHost[]): NixOutput;