@adrifer/winix 0.2.3 → 0.2.4-preview.1

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 (39) hide show
  1. package/README.md +423 -3
  2. package/dist/backends/windows/index.d.ts +3 -1
  3. package/dist/backends/windows/index.js +99 -7
  4. package/dist/backends/windows/lockfile.d.ts +36 -1
  5. package/dist/backends/windows/lockfile.js +168 -0
  6. package/dist/backends/windows/paths.d.ts +2 -0
  7. package/dist/backends/windows/paths.js +17 -0
  8. package/dist/backends/windows/powershell.d.ts +6 -0
  9. package/dist/backends/windows/powershell.js +51 -0
  10. package/dist/backends/windows/wsl-setup-runtime.d.ts +35 -0
  11. package/dist/backends/windows/wsl-setup-runtime.js +401 -0
  12. package/dist/backends/windows/wsl-setup.d.ts +12 -0
  13. package/dist/backends/windows/wsl-setup.js +150 -0
  14. package/dist/backends/windows/wsl.d.ts +9 -0
  15. package/dist/backends/windows/wsl.js +194 -0
  16. package/dist/cli/commands/apply.d.ts +7 -1
  17. package/dist/cli/commands/apply.js +39 -15
  18. package/dist/cli/commands/check.js +3 -0
  19. package/dist/cli/commands/init.js +5 -1
  20. package/dist/cli/commands/switch.d.ts +6 -0
  21. package/dist/cli/commands/switch.js +53 -13
  22. package/dist/cli/commands/update.d.ts +6 -1
  23. package/dist/cli/commands/update.js +41 -10
  24. package/dist/cli/index.js +40 -3
  25. package/dist/cli/windows-state.d.ts +56 -0
  26. package/dist/cli/windows-state.js +341 -0
  27. package/dist/helpers/index.d.ts +1 -1
  28. package/dist/helpers/utils.d.ts +1 -0
  29. package/dist/helpers/utils.js +8 -0
  30. package/dist/helpers/windows.d.ts +53 -7
  31. package/dist/helpers/windows.js +351 -28
  32. package/dist/index.d.ts +4 -2
  33. package/dist/runtime.d.ts +10 -0
  34. package/dist/runtime.js +9 -0
  35. package/dist/skill.js +126 -5
  36. package/dist/types/windows.d.ts +82 -1
  37. package/package.json +4 -1
  38. package/scripts/bootstrap-nixos.sh +51 -0
  39. package/scripts/bootstrap-windows.ps1 +225 -0
package/dist/skill.js CHANGED
@@ -266,12 +266,130 @@ Resources return handles that can be passed through \`dependsOn\`.
266
266
  - \`windows.path.add()\` and \`windows.path.remove()\` manage PATH entries.
267
267
  - \`windows.file.text()\`, \`windows.file.symlink()\`,
268
268
  \`windows.file.copy()\`, and \`windows.file.remove()\` manage files.
269
+ - \`windows.startup.command(name, spec)\` manages a named current-user Startup
270
+ shortcut, without running it during apply. Supply executable and optional argv
271
+ arguments, workingDirectory, windowStyle (normal/minimized/maximized),
272
+ dependsOn, backup, and force. Executables may be application names on PATH or
273
+ absolute/environment/known-folder paths. Arguments are literal strings or
274
+ known-folder paths; the default working directory is the user profile.
275
+ Executable and working directory must exist during activation. Replacement
276
+ requires backup or force; backup collisions fail. This is sign-in startup,
277
+ not a service, scheduled task, elevated launch, or all-users startup.
278
+ Native Windows switch tracks created/replaced shortcut ownership and removes
279
+ unchanged owned entries when declarations disappear. Matching pre-existing
280
+ shortcuts remain externally owned.
281
+ - \`windows.knownFolder.documents()\`, \`windows.knownFolder.desktop()\`,
282
+ \`windows.knownFolder.localAppData()\`, \`windows.knownFolder.appData()\`, and
283
+ \`windows.knownFolder.userProfile()\` build typed file targets resolved during
284
+ activation. Each accepts an optional relative child path. File copy/symlink
285
+ sources resolve relative to the directory containing winix.config.ts;
286
+ absolute paths, environment-variable paths, and file URLs are also supported.
287
+ - \`windows.powershell.module()\` declares a current-user PowerShell 7 module
288
+ by name, with optional repository (default PSGallery) and dependsOn.
289
+ Versions are recorded in the modules section of winix-windows.lock, not
290
+ handwritten declarations. PowerShell 7 with PSResourceGet is required for
291
+ resolution and installation.
269
292
  - \`windows.dsc()\` declares an arbitrary DSC resource.
293
+ - \`windows.optionalFeature()\` enables/disables a named Windows optional feature;
294
+ enabled defaults to true. Changes require elevation, never reboot automatically.
295
+ - \`windows.wsl()\` enables the WSL and Virtual Machine Platform features.
296
+ Options are config, backup, force, and dependsOn. The optional config manages
297
+ the full current-user .wslconfig with file overwrite protections; omitting it
298
+ leaves the file untouched. The returned handle covers the complete setup.
299
+ If a reboot is needed, restart Windows manually and rerun switch.
300
+ It never shuts down WSL; restart WSL manually when configuration changes.
301
+ - \`windows.wsl.distro()\` registers a named distro with source "nixos-wsl",
302
+ installLocation, optional default and dependsOn. Declare windows.wsl() and the
303
+ Microsoft.WSL package in the same host; features, config, and runtime become
304
+ automatic dependencies.
305
+ Images for x64/ARM64 are verified against winix-windows.lock wslImages pins.
306
+ Update with winix update --windows nixos-wsl. Updates never reinstall an
307
+ existing distro. Conflicting/unrecorded distros are refused, not adopted.
308
+ Removing a declaration never unregisters a distro or deletes its data.
309
+ Optional setup opts into trusted first-run Linux provisioning:
310
+ { repository: "https://github.com/example/dotfiles.git", ref: "main",
311
+ configDirectory: "winix", host: "wsl-work", user: "alice",
312
+ checkout: "/home/alice/dotfiles" }.
313
+ Repository URLs must be HTTPS without credentials; authentication must already
314
+ work inside Linux. Commit flake.lock in configDirectory; npm-based Winix also
315
+ requires package.json/package-lock.json and a released SDK supporting setup.
316
+ Official standalone Windows binaries use a matching, checksum-verified Linux
317
+ binary and pinned Nix runtime libraries instead of Node/npm. The Linux host must
318
+ explicitly enable/import NixOS-WSL, declare system.stateVersion, and match the
319
+ distro architecture. user selects a declared normal account (inferred from
320
+ Home Manager or the sole normal account when omitted); checkout defaults to
321
+ its home/dotfiles and must remain inside that home. Home Manager identity/home
322
+ must agree. Git/config evaluation (and npm when used) run unprivileged; root activates the
323
+ account-only bootstrap, assigns checkout ownership, then activates the full
324
+ Linux host, which must set wsl.defaultUser to that account. No password or
325
+ sudo policy is supplied. Missing external account secrets fail explicitly.
326
+ wslRepositories locks repository commits; refresh with
327
+ winix update --windows wsl-setup. Completed setup is never reapplied or updated;
328
+ in-progress setup retains its original commit. Failures are resumable; dirty
329
+ or occupied checkouts/changed settings are refused, never reset or adopted.
330
+ State lives at /var/lib/winix/wsl-setup. Inspect stale run.lock and its PID
331
+ before manual recovery; never remove a live coordinator's lock.
332
+ No shutdown/reboot is automatic. Fresh-image activation remains unverified.
333
+ Omit setup to retain separate manual Linux activation.
270
334
  - \`windows.raw()\` runs a command on every apply. It is not idempotent, so use
271
- a typed helper or \`windows.dsc()\` when possible.
272
-
273
- Floating Windows packages are resolved into \`winix-windows.lock\`. Keep that
274
- file in version control for deterministic, offline applies.
335
+ a typed helper or \`windows.dsc()\` when possible. String commands default to
336
+ PowerShell 7 (\`pwsh\`); explicit executables are preserved.
337
+
338
+ File, PATH, startup, and module scripts use Microsoft.DSC.Transitional/PowerShellScript,
339
+ not Windows PowerShell 5.1. Install PowerShell 7 and put pwsh on PATH before DSC
340
+ resource discovery; declaring its package dependency is not sufficient for
341
+ bootstrap. Set scripts guard their own changes independently of test scripts.
342
+
343
+ Floating Windows packages, PowerShell modules, NixOS-WSL images and setup commits are resolved into
344
+ \`winix-windows.lock\` on first apply; existing pins are reused without a
345
+ resolution query. \`winix update --windows [names...]\` refreshes selected
346
+ package/module/image/repository pins (all when omitted, nixos-wsl for images,
347
+ wsl-setup for setup commits); --dry reports without writing.
348
+ Keep the lock in version control. Installation still requires network access
349
+ when the locked package/module is not installed.
350
+
351
+ Native Windows \`winix switch\` keeps a separate per-user/machine applied-state
352
+ inventory in LocalAppData/Winix, shared across recorded workspace/host activations.
353
+ Only packages absent before a successful activation become uninstall-owned.
354
+ Pre-existing packages are never automatically adopted. Unused owned packages
355
+ are automatically uninstalled after successful activation; always preview
356
+ with \`winix switch --dry\`. Other recorded owners prevent removal.
357
+ Switches with package/startup removals prompt before activation; declining cancels
358
+ the entire switch. Use \`--yes\`/\`-y\` for automation; noninteractive runs with
359
+ removals require it. Dry runs and switches without removals do not prompt.
360
+ External shortcut edits/package-version drift block reconciliation.
361
+ \`winix state forget startup <name>\` or
362
+ \`winix state forget package <winget|msstore> <id>\` releases removal ownership
363
+ without deleting the resource; --dry previews. Do not copy applied state to a
364
+ new machine or infer ownership from version locks. Direct DSC/script activation
365
+ bypasses this tracking. Files, modules, env and PATH cleanup are not tracked.
366
+
367
+ For fresh Windows prerequisites, \`scripts/bootstrap-windows.ps1\` runs in built-in
368
+ Windows PowerShell 5.1 or PowerShell 7. App Installer/WinGet is the initial
369
+ prerequisite. \`-Check\` is read-only; install mode confirms missing/outdated
370
+ Git/Node/PowerShell/DSC installation and enables WinGet configuration support.
371
+ \`-Standalone\` skips all Node/npm checks and installations for executable users;
372
+ it cannot be combined with \`-UseNvm\`. Release executables embed the SDK/runtime,
373
+ load local TS/JS imports and Node builtins without node_modules, and never
374
+ automatically download third-party npm imports. The executable version determines
375
+ the SDK, not package-lock.json; editor TypeScript dependencies remain optional.
376
+ Choose versioned GitHub release assets, verify SHA256SUMS, and respect execution
377
+ policies (binaries are not code-signed). Windows WSL setup embeds matching Linux
378
+ hashes; custom single-target builds cannot provision WSL. Linux assets use glibc;
379
+ automatic WSL setup prepares NixOS's linker explicitly. No ARM64 execution or
380
+ fresh-image activation is claimed.
381
+ \`-UseNvm\` chooses NVM for Windows instead of standalone Node; \`-Yes\` accepts
382
+ bootstrap changes. It never installs Winix globally, activates a host, provisions
383
+ WSL, reboots, or changes execution policy persistently. Prepare the config and
384
+ compatible SDK separately, then review \`switch --dry\` before activation.
385
+
386
+ On existing NixOS/NixOS-WSL, \`bash bootstrap-nixos.sh\` (from
387
+ \`scripts/bootstrap-nixos.sh\` or a reviewed release asset) opens a temporary
388
+ Git/Node.js 24/npm/Bash environment using pinned nixpkgs. Nix must already be
389
+ available. Flakes are enabled only in the child session; the script never edits
390
+ profiles/system configuration, clones repos, installs npm dependencies/Winix,
391
+ or activates hosts. Nix may download store paths. Users handle their configs
392
+ and declare permanent tools/settings themselves; \`exit\` leaves the environment.
275
393
 
276
394
  ## Nix values and escape hatches
277
395
 
@@ -334,7 +452,10 @@ callers may need arguments or \`.isActive\`.
334
452
  effects.
335
453
  - \`winix check [--strict] [--escape-report]\` validates the project.
336
454
  - \`winix apply [--host NAME] [--dry] [--diff]\` generates backend output.
337
- - \`winix switch [--host NAME] [--dry]\` generates and activates one host.
455
+ - \`winix switch [--host NAME] [--dry] [--yes]\` generates and activates one host, automatically cleaning up unused owned Windows packages and startup commands.
456
+ Prune is Windows-only and uninstalls unused Winix-owned packages.
457
+ - \`winix state forget startup <name>\` / \`winix state forget package <source> <id>\`
458
+ releases Windows removal ownership without deleting anything; accepts --dry.
338
459
  - \`winix update [INPUTS...] [--dry] [--windows]\` updates Nix inputs or
339
460
  Windows package locks.
340
461
  - \`winix inspect\` prints host composition and fragment information.
@@ -1,4 +1,61 @@
1
1
  import type { ResourceRef } from "../core/types.js";
2
+ export type WinKnownFolderName = "documents" | "desktop" | "localAppData" | "appData" | "userProfile";
3
+ export interface WinKnownFolder {
4
+ kind: "knownFolder";
5
+ folder: WinKnownFolderName;
6
+ path: string;
7
+ }
8
+ export type WinFilePath = string | WinKnownFolder;
9
+ export type WinStartupWindowStyle = "normal" | "minimized" | "maximized";
10
+ export interface WinStartupCommand {
11
+ /** Absolute/environment-variable path, known-folder path, or application name on PATH. */
12
+ executable: WinFilePath;
13
+ /** Literal arguments; known-folder arguments are resolved during activation. */
14
+ arguments?: WinFilePath[];
15
+ /** Defaults to the current user's home directory. Must exist during activation. */
16
+ workingDirectory?: WinFilePath;
17
+ windowStyle?: WinStartupWindowStyle;
18
+ }
19
+ export interface WinPowerShellModule {
20
+ name: string;
21
+ repository: string;
22
+ }
23
+ export interface WinWslDistro {
24
+ name: string;
25
+ source: "nixos-wsl";
26
+ installLocation: WinFilePath;
27
+ default: boolean;
28
+ setup?: WinWslSetup;
29
+ }
30
+ export interface WinWslSetup {
31
+ /** Opts into executing trusted repository/npm code inside the distro. HTTPS only; never embed credentials. */
32
+ repository: string;
33
+ /** Branch, tag, full ref, or immutable commit; resolved into winix-windows.lock. Defaults to HEAD. */
34
+ ref?: string;
35
+ configDirectory: string;
36
+ host: string;
37
+ /** Absolute path inside the selected account's home. Defaults to <home>/dotfiles. */
38
+ checkout?: string;
39
+ /** Selects a normal account declared by the Linux host; inferred when unambiguous. */
40
+ user?: string;
41
+ }
42
+ export interface WinWslConfig {
43
+ wsl2?: {
44
+ memory?: string;
45
+ processors?: number;
46
+ swap?: string;
47
+ localhostForwarding?: boolean;
48
+ networkingMode?: "nat" | "mirrored" | "none" | "virtioproxy";
49
+ dnsTunneling?: boolean;
50
+ firewall?: boolean;
51
+ autoProxy?: boolean;
52
+ guiApplications?: boolean;
53
+ };
54
+ experimental?: {
55
+ autoMemoryReclaim?: "disabled" | "gradual" | "dropCache";
56
+ sparseVhd?: boolean;
57
+ };
58
+ }
2
59
  /**
3
60
  * A winget package source. MVP supports the two first-party catalogues.
4
61
  * Additional sources (chocolatey, scoop) can plug in later without changing
@@ -68,7 +125,7 @@ export interface WinRawCommand {
68
125
  *
69
126
  * Typed helpers (env/path) construct native DSC resources internally:
70
127
  * `Microsoft.Windows/Registry` for env and
71
- * `Microsoft.DSC.Transitional/WindowsPowerShellScript` for PATH/files.
128
+ * `Microsoft.DSC.Transitional/PowerShellScript` for PATH/files/modules.
72
129
  */
73
130
  export interface WinDscResource {
74
131
  /**
@@ -112,6 +169,16 @@ export interface WinDscResource {
112
169
  dependsOn?: ResourceRef[];
113
170
  }
114
171
  export type WinDscMetadata = {
172
+ kind: "optional-features";
173
+ names: string[];
174
+ enabled: boolean;
175
+ } | {
176
+ kind: "wsl-distro";
177
+ distro: WinWslDistro;
178
+ } | {
179
+ kind: "startup";
180
+ name: string;
181
+ } | {
115
182
  kind: "env";
116
183
  action: "set" | "remove";
117
184
  name: string;
@@ -124,6 +191,20 @@ export type WinDscMetadata = {
124
191
  scope: "user" | "machine";
125
192
  } | {
126
193
  kind: "setting";
194
+ } | {
195
+ kind: "powershell-module";
196
+ module: WinPowerShellModule;
197
+ } | {
198
+ kind: "file";
199
+ action: "text" | "symlink" | "copy" | "remove";
200
+ target: WinFilePath;
201
+ source?: string;
202
+ content?: string;
203
+ encoding: "utf8" | "utf8bom" | "ascii";
204
+ force: boolean;
205
+ backup: boolean;
206
+ recursive: boolean;
207
+ wslConfig?: boolean;
127
208
  };
128
209
  export type WinColorMode = "Light" | "Dark";
129
210
  export type WinTaskbarAlignment = "Left" | "Center";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adrifer/winix",
3
- "version": "0.2.3",
3
+ "version": "0.2.4-preview.1",
4
4
  "description": "TypeScript-first system configuration for NixOS, nix-darwin, and Home Manager",
5
5
  "license": "MIT",
6
6
  "author": "Adrian Fernandez",
@@ -43,6 +43,8 @@
43
43
  "winix": "dist/cli/index.js"
44
44
  },
45
45
  "files": [
46
+ "scripts/bootstrap-windows.ps1",
47
+ "scripts/bootstrap-nixos.sh",
46
48
  "dist",
47
49
  "types",
48
50
  "index.d.ts",
@@ -52,6 +54,7 @@
52
54
  "scripts": {
53
55
  "clean": "node scripts/clean-dist.mjs",
54
56
  "build": "npm run clean && tsc -p tsconfig.build.json && node scripts/fix-dts-imports.mjs",
57
+ "build:standalone": "node scripts/build-standalone.mjs",
55
58
  "dev": "tsc --watch",
56
59
  "test": "vitest",
57
60
  "lint": "eslint src/",
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ winix_require_nixos() {
5
+ if [[ ! -r /etc/os-release ]] || ! (source /etc/os-release; [[ "${ID:-}" == nixos ]]); then
6
+ printf '%s\n' 'Winix bootstrap requires an existing NixOS installation (including NixOS-WSL).' >&2
7
+ return 1
8
+ fi
9
+ }
10
+
11
+ winix_bootstrap_nixos() {
12
+ if [[ $# -gt 0 ]]; then
13
+ if [[ $# -eq 1 && ( "$1" == --help || "$1" == -h ) ]]; then
14
+ printf '%s\n' \
15
+ 'Usage: bash bootstrap-nixos.sh' \
16
+ 'Open a temporary Git, Node.js 24/npm, and Bash environment on NixOS.' \
17
+ 'Nix downloads may populate the store; no profile or system configuration is changed.' \
18
+ 'Clone your configuration, install its npm dependencies, and run Winix yourself.' \
19
+ 'Type exit to leave the environment. No Winix installation or activation is performed.'
20
+ return
21
+ fi
22
+ printf '%s\n' 'Usage: bash bootstrap-nixos.sh [--help]' >&2
23
+ return 2
24
+ fi
25
+
26
+ winix_require_nixos || return
27
+ if ! command -v nix >/dev/null 2>&1; then
28
+ printf '%s\n' 'Nix is unavailable. Restore the NixOS Nix installation/PATH before running this bootstrap.' >&2
29
+ return 1
30
+ fi
31
+
32
+ # Keep the bootstrap independent of mutable registries and user channels.
33
+ local nixpkgs='github:NixOS/nixpkgs/0bb2eedc20e4739f29e8045034f2828ad7054f8f'
34
+ export NIX_CONFIG="${NIX_CONFIG:+$NIX_CONFIG$'\n'}extra-experimental-features = nix-command flakes"
35
+ printf '%s\n' \
36
+ 'Opening the Winix prerequisite shell (Git, Node.js 24/npm, Bash).' \
37
+ 'The first run may download packages to the Nix store.' \
38
+ 'No repositories are cloned, npm dependencies installed, or hosts activated.' \
39
+ 'Clone your config into a permanent location and run npm install and Winix yourself.' \
40
+ 'Type exit to leave. Declare permanent tools/Nix settings in your own configuration.'
41
+
42
+ exec nix shell --no-write-lock-file \
43
+ "$nixpkgs#git" \
44
+ "$nixpkgs#nodejs_24" \
45
+ "$nixpkgs#bashInteractive" \
46
+ --command bash --noprofile --norc -i
47
+ }
48
+
49
+ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
50
+ winix_bootstrap_nixos "$@"
51
+ fi
@@ -0,0 +1,225 @@
1
+ #Requires -Version 5.1
2
+ <#
3
+ .SYNOPSIS
4
+ Checks or installs the Windows prerequisites for Winix, without activating a host.
5
+ .PARAMETER Check
6
+ Only inspect prerequisites. No installation or configuration enablement is performed.
7
+ .PARAMETER Yes
8
+ Accept prerequisite installation and WinGet configuration enablement without prompting.
9
+ .PARAMETER UseNvm
10
+ Install/select Node LTS through NVM for Windows instead of standalone Node.js.
11
+ .PARAMETER Standalone
12
+ Check/install only native prerequisites for the Winix executable; Node.js/npm are not needed.
13
+ #>
14
+ [CmdletBinding()]
15
+ param(
16
+ [switch]$Check,
17
+ [switch]$Yes,
18
+ [switch]$UseNvm,
19
+ [switch]$Standalone
20
+ )
21
+
22
+ function Get-WinixBootstrapApplication {
23
+ param([string]$Name)
24
+ $application = Get-Command $Name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
25
+ if ($application) { return $application.Source }
26
+ return $null
27
+ }
28
+
29
+ function Invoke-WinixBootstrapNative {
30
+ param([string]$FilePath, [string[]]$Arguments)
31
+ $output = @(& $FilePath @Arguments)
32
+ $code = $LASTEXITCODE
33
+ if ($code -ne 0) {
34
+ if ($code -eq 3010 -or $code -eq 1641) {
35
+ throw 'An installer requires a restart. Restart Windows yourself, then rerun the bootstrap.'
36
+ }
37
+ throw ("Command failed ({0}, exit {1}): {2}`n{3}" -f $FilePath, $code, ($Arguments -join ' '), ($output -join "`n"))
38
+ }
39
+ return $output
40
+ }
41
+
42
+ function Update-WinixBootstrapPath {
43
+ foreach ($name in @('NVM_HOME', 'NVM_SYMLINK')) {
44
+ $value = [Environment]::GetEnvironmentVariable($name, 'User')
45
+ if (-not $value) { $value = [Environment]::GetEnvironmentVariable($name, 'Machine') }
46
+ if ($value) { [Environment]::SetEnvironmentVariable($name, $value, 'Process') }
47
+ }
48
+ $paths = @(
49
+ $env:Path
50
+ [Environment]::GetEnvironmentVariable('Path', 'Machine')
51
+ [Environment]::GetEnvironmentVariable('Path', 'User')
52
+ (Join-Path ([Environment]::GetFolderPath('LocalApplicationData')) 'Microsoft\WindowsApps')
53
+ )
54
+ $env:Path = (($paths -join ';').Split(';') |
55
+ Where-Object { $_ } |
56
+ ForEach-Object { [Environment]::ExpandEnvironmentVariables($_.Trim().Trim('"')) } |
57
+ Select-Object -Unique) -join ';'
58
+ }
59
+
60
+ function Get-WinixBootstrapTools {
61
+ param([switch]$Standalone)
62
+ $tools = @(
63
+ @{ Id = 'Git.Git'; Command = 'git.exe'; Minimum = '2.0.0' }
64
+ @{ Id = 'OpenJS.NodeJS.LTS'; Command = 'node.exe'; Minimum = '22.13.0' }
65
+ @{ Id = 'Microsoft.PowerShell'; Command = 'pwsh.exe'; Minimum = '7.4.0' }
66
+ @{ Id = 'Microsoft.DSC'; Command = 'dsc.exe'; Minimum = '3.2.0' }
67
+ )
68
+ foreach ($tool in $tools) {
69
+ if ($Standalone -and $tool.Command -eq 'node.exe') { continue }
70
+ $path = Get-WinixBootstrapApplication $tool.Command
71
+ $version = $null
72
+ if ($path) {
73
+ $text = (Invoke-WinixBootstrapNative $path @('--version')) -join "`n"
74
+ if ($text -notmatch '(\d+\.\d+\.\d+)') {
75
+ throw "Cannot parse $($tool.Command) version: $text"
76
+ }
77
+ $version = [version]$Matches[1]
78
+ if ($text -match '(?i)-(preview|rc|alpha|beta)') {
79
+ throw "Prerelease $($tool.Command) is not supported by this bootstrap. Install a stable release."
80
+ }
81
+ }
82
+ [pscustomobject]@{
83
+ Id = $tool.Id
84
+ Command = $tool.Command
85
+ Path = $path
86
+ Version = $version
87
+ Ready = $null -ne $version -and $version -ge [version]$tool.Minimum
88
+ Minimum = $tool.Minimum
89
+ }
90
+ }
91
+ }
92
+
93
+ function Test-WinixBootstrapCapabilities {
94
+ param([string]$WinGet, [switch]$Standalone)
95
+ $help = (Invoke-WinixBootstrapNative $WinGet @('configure', '--help')) -join "`n"
96
+ if ($help -notmatch '--enable\b') {
97
+ throw 'Update App Installer from Microsoft Store: this WinGet lacks configuration enablement support.'
98
+ }
99
+ if (-not $Standalone) {
100
+ $npm = Get-WinixBootstrapApplication 'npm.cmd'
101
+ if (-not $npm) { throw 'npm.cmd is unavailable. Repair the Node.js installation or open a new terminal, then rerun.' }
102
+ Invoke-WinixBootstrapNative $npm @('--version') | Out-Null
103
+ $node = Get-WinixBootstrapApplication 'node.exe'
104
+ Invoke-WinixBootstrapNative $node @(
105
+ '--experimental-transform-types', '--no-warnings', '--input-type=module', '--eval',
106
+ "import { stripTypeScriptTypes } from 'node:module'; stripTypeScriptTypes('const x: number = 1');"
107
+ ) | Out-Null
108
+ }
109
+ $pwsh = Get-WinixBootstrapApplication 'pwsh.exe'
110
+ $script = @'
111
+ $ErrorActionPreference = 'Stop'
112
+ Get-Command Find-PSResource, Install-PSResource -ErrorAction Stop | Out-Null
113
+ Get-PSResourceRepository -Name PSGallery -ErrorAction Stop | Out-Null
114
+ '@
115
+ $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script))
116
+ Invoke-WinixBootstrapNative $pwsh @('-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', $encoded) | Out-Null
117
+ $dsc = Get-WinixBootstrapApplication 'dsc.exe'
118
+ foreach ($name in @(
119
+ 'Microsoft.WinGet/Package',
120
+ 'Microsoft.DSC.Transitional/PowerShellScript',
121
+ 'Microsoft.DSC.Transitional/RunCommandOnSet',
122
+ 'Microsoft.Windows/Registry'
123
+ )) {
124
+ $lines = @(Invoke-WinixBootstrapNative $dsc @('resource', 'list', $name, '--output-format', 'json'))
125
+ $found = @($lines | Where-Object { $_.Trim() } | ForEach-Object { $_ | ConvertFrom-Json })
126
+ if ($found.Count -ne 1 -or $found[0].type -ne $name) {
127
+ throw "Required DSC resource is unavailable: $name. Update App Installer/DSC, open a new terminal, and rerun."
128
+ }
129
+ }
130
+ if (-not $Standalone) { Write-Host 'OK: npm and Node TypeScript support.' }
131
+ Write-Host 'OK: PSResourceGet/PSGallery and required DSC resources.'
132
+ }
133
+
134
+ function Invoke-WinixWindowsBootstrap {
135
+ param([switch]$Check, [switch]$Yes, [switch]$UseNvm, [switch]$Standalone)
136
+ $ErrorActionPreference = 'Stop'
137
+ if ($Standalone -and $UseNvm) { throw '-Standalone and -UseNvm cannot be combined.' }
138
+ if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) {
139
+ throw 'This bootstrap is for native Windows, not WSL. Run it from Windows PowerShell or PowerShell 7.'
140
+ }
141
+ Update-WinixBootstrapPath
142
+ $winget = Get-WinixBootstrapApplication 'winget.exe'
143
+ if (-not $winget) {
144
+ throw @'
145
+ WinGet is unavailable. Install/update App Installer from https://apps.microsoft.com/detail/9nblggh4nns1 and open a new terminal.
146
+ If App Installer is already installed but not registered after first sign-in, run:
147
+ Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
148
+ Then rerun this bootstrap. No prerequisites have been installed.
149
+ '@
150
+ }
151
+ Write-Host ("WinGet: " + ((Invoke-WinixBootstrapNative $winget @('--version')) -join ' '))
152
+ $tools = @(Get-WinixBootstrapTools -Standalone:$Standalone)
153
+ foreach ($tool in $tools) {
154
+ $installed = if ($tool.Version) { $tool.Version.ToString() } else { 'missing' }
155
+ $status = if ($tool.Ready) { 'OK' } else { 'NEEDED' }
156
+ Write-Host ("{0}: {1} {2} (minimum {3})" -f $status, $tool.Command, $installed, $tool.Minimum)
157
+ }
158
+ $pending = @($tools | Where-Object { -not $_.Ready })
159
+ if ($Check) {
160
+ if ($pending.Count -gt 0) {
161
+ throw 'Prerequisites are missing or too old. Rerun without -Check to install/upgrade the listed packages.'
162
+ }
163
+ } else {
164
+ $node = $pending | Where-Object { $_.Command -eq 'node.exe' }
165
+ $nvm = Get-WinixBootstrapApplication 'nvm.exe'
166
+ if ($node -and $nvm -and -not $UseNvm) {
167
+ throw 'NVM for Windows is already installed. Rerun with -UseNvm; standalone Node would conflict with its symlink.'
168
+ }
169
+ if ($node -and $UseNvm -and $node.Path -and -not $nvm) {
170
+ throw 'Existing Node.js needs upgrading but NVM is absent. Repair/upgrade the existing Node installation or deliberately remove it before choosing -UseNvm.'
171
+ }
172
+ Write-Host 'This will install/upgrade only NEEDED packages and enable WinGet configuration support (requires Store access).'
173
+ if ($node -and $UseNvm) {
174
+ Write-Host 'Node.js will use CoreyButler.NVMforWindows plus nvm install lts / nvm use lts; selecting Node may require elevation.'
175
+ }
176
+ Write-Host 'Installers may request UAC elevation. No host configuration, WSL setup, or reboot is performed.'
177
+ if (-not $Yes) {
178
+ if ([Console]::IsInputRedirected) { throw 'Noninteractive bootstrap requires -Yes; use -Check for inspection only.' }
179
+ $answer = Read-Host 'Continue with bootstrap? [y/N]'
180
+ if ($answer.Trim() -notmatch '^(?i:y|yes)$') { throw 'Bootstrap cancelled. No installation or enablement was performed.' }
181
+ }
182
+ foreach ($tool in $pending) {
183
+ if ($tool.Command -eq 'node.exe' -and $UseNvm) {
184
+ if (-not $nvm) {
185
+ Invoke-WinixBootstrapNative $winget @(
186
+ 'install', '--id', 'CoreyButler.NVMforWindows', '--exact', '--source', 'winget',
187
+ '--silent', '--accept-package-agreements', '--accept-source-agreements', '--disable-interactivity'
188
+ ) | ForEach-Object { Write-Host $_ }
189
+ Update-WinixBootstrapPath
190
+ $nvm = Get-WinixBootstrapApplication 'nvm.exe'
191
+ if (-not $nvm) { throw 'NVM is not on PATH yet. Open a new terminal and rerun with -UseNvm.' }
192
+ }
193
+ Invoke-WinixBootstrapNative $nvm @('install', 'lts') | ForEach-Object { Write-Host $_ }
194
+ Invoke-WinixBootstrapNative $nvm @('use', 'lts') | ForEach-Object { Write-Host $_ }
195
+ } else {
196
+ $operation = if ($tool.Path) { 'upgrade' } else { 'install' }
197
+ Write-Host "$operation $($tool.Id)"
198
+ Invoke-WinixBootstrapNative $winget @(
199
+ $operation, '--id', $tool.Id, '--exact', '--source', 'winget',
200
+ '--silent', '--accept-package-agreements', '--accept-source-agreements', '--disable-interactivity'
201
+ ) | ForEach-Object { Write-Host $_ }
202
+ }
203
+ Update-WinixBootstrapPath
204
+ $updated = @(Get-WinixBootstrapTools -Standalone:$Standalone | Where-Object { $_.Id -eq $tool.Id })
205
+ if ($updated.Count -ne 1 -or -not $updated[0].Ready) {
206
+ throw "Installation did not make $($tool.Command) ready. Open a new terminal or restart if requested, then rerun."
207
+ }
208
+ }
209
+ Invoke-WinixBootstrapNative $winget @('configure', '--enable') |
210
+ ForEach-Object { Write-Host $_ }
211
+ Update-WinixBootstrapPath
212
+ }
213
+ Test-WinixBootstrapCapabilities $winget -Standalone:$Standalone
214
+ Write-Host 'Prerequisite checks passed. No Winix host was activated.'
215
+ Write-Host 'Open a new PowerShell 7 terminal before preparing the Winix/config checkout and running winix check or switch --dry.'
216
+ }
217
+
218
+ if ($MyInvocation.InvocationName -ne '.') {
219
+ try {
220
+ Invoke-WinixWindowsBootstrap -Check:$Check -Yes:$Yes -UseNvm:$UseNvm -Standalone:$Standalone
221
+ } catch {
222
+ Write-Error $_ -ErrorAction Continue
223
+ exit 1
224
+ }
225
+ }