@adrifer/winix 0.3.0-preview.3 → 0.3.0-preview.5
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 +64 -6
- package/dist/backends/windows/index.js +2 -2
- package/dist/backends/windows/wsl-setup.d.ts +1 -0
- package/dist/backends/windows/wsl-setup.js +8 -4
- package/dist/backends/windows/wsl.d.ts +1 -0
- package/dist/backends/windows/wsl.js +95 -14
- package/dist/cli/commands/apply.d.ts +3 -0
- package/dist/cli/commands/apply.js +7 -1
- package/dist/cli/commands/switch.js +81 -2
- package/dist/cli/windows-package-versions.d.ts +8 -0
- package/dist/cli/windows-package-versions.js +43 -0
- package/dist/cli/windows-state.d.ts +3 -0
- package/dist/cli/windows-state.js +41 -2
- package/dist/helpers/windows.d.ts +1 -0
- package/dist/helpers/windows.js +5 -0
- package/dist/skill.js +26 -5
- package/dist/types/windows.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -749,8 +749,9 @@ import. Image updates affect **new registrations only**, never existing Linux
|
|
|
749
749
|
filesystems. Dry generation can resolve missing pins but neither writes the lock
|
|
750
750
|
nor downloads images.
|
|
751
751
|
|
|
752
|
-
Winix
|
|
753
|
-
|
|
752
|
+
Winix creates the declared distro only when its registration is absent. It never
|
|
753
|
+
replaces, moves, converts, or unregisters a conflicting existing distro.
|
|
754
|
+
Successful imports create
|
|
754
755
|
`.winix-wsl.json` in the installation directory to identify that registration.
|
|
755
756
|
If import is interrupted before recording completes, inspect the existing
|
|
756
757
|
registration and disk manually; Winix will not unregister it as rollback.
|
|
@@ -759,7 +760,43 @@ Only explicit `enabled: false` disables a feature. The separately declared
|
|
|
759
760
|
WSL package follows normal package ownership/removal rules.
|
|
760
761
|
|
|
761
762
|
The Windows registration name (`NixOS`) and Linux Winix host name (`wsl-work`,
|
|
762
|
-
for example) are independent.
|
|
763
|
+
for example) are independent. The **same declaration** can create a distro on a
|
|
764
|
+
new machine or adopt a matching existing one:
|
|
765
|
+
|
|
766
|
+
```ts
|
|
767
|
+
windows.wsl();
|
|
768
|
+
windows.wsl.distro("NixOS", {
|
|
769
|
+
source: "nixos-wsl",
|
|
770
|
+
host: "wsl-work",
|
|
771
|
+
installLocation: windows.knownFolder.localAppData("Winix\\WSL\\NixOS"),
|
|
772
|
+
});
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
During Windows activation, an untracked registration must be WSL 2, run NixOS,
|
|
776
|
+
and report the expected Linux hostname. `host` supplies that hostname and defaults
|
|
777
|
+
to `setup.host` when omitted. Winix normally sets Linux's hostname to its host ID;
|
|
778
|
+
if yours is overridden, set `host` to the actual expected hostname. Without
|
|
779
|
+
either hostname declaration, existing untracked distros are refused.
|
|
780
|
+
|
|
781
|
+
Matching distros are automatically recorded under the current Windows user's
|
|
782
|
+
Local AppData `Winix\wsl-registrations\registration-<name>.json`. Records bind the
|
|
783
|
+
registration GUID, actual location, and adopted hostname. An adopted distro keeps
|
|
784
|
+
its actual location; `installLocation` is only the creation destination. Later
|
|
785
|
+
runs revalidate identity and refuse changed/missing registrations, hostname
|
|
786
|
+
changes, or invalid tracking records. Inspect these records before manual
|
|
787
|
+
recovery; never remove one while activation is running. Existing Winix import
|
|
788
|
+
markers remain supported and retain their provisioning behavior.
|
|
789
|
+
|
|
790
|
+
Adoption checks no Git origin, user, checkout, or config files and executes no
|
|
791
|
+
repository code. It may start a stopped distro but never writes Linux setup
|
|
792
|
+
state, clones repositories, installs dependencies, changes defaults, or activates
|
|
793
|
+
Linux. `setup` and `default` are not applied to adopted distros, even on later
|
|
794
|
+
runs. Activate Linux manually. `winix check` and dry generation perform static
|
|
795
|
+
checks only; creation pins may still be resolved, but no distro is inspected or
|
|
796
|
+
adopted. Removing the declaration leaves the distro, its data, and tracking alone.
|
|
797
|
+
Automatic adoption is not available in preview.3.
|
|
798
|
+
|
|
799
|
+
For a **new distro**, automate its first-run link by opting into `setup`:
|
|
763
800
|
|
|
764
801
|
```ts
|
|
765
802
|
windows.wsl.distro("NixOS", {
|
|
@@ -968,9 +1005,30 @@ cancels the whole switch without activation or cleanup. Switches without removal
|
|
|
968
1005
|
and `--dry` do not prompt. Use `winix switch --yes` (or `-y`) to accept removals
|
|
969
1006
|
for automation; noninteractive switches with removals require this flag.
|
|
970
1007
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1008
|
+
During native Windows `switch`, a package without an inline `version` uses its
|
|
1009
|
+
lock as a minimum version and fresh-install target. An absent package installs
|
|
1010
|
+
the lock; an older installed version upgrades; a newer installed version is kept
|
|
1011
|
+
and reported. The generated activation document targets that installed version,
|
|
1012
|
+
not the older lock. External upgrades of owned packages retain ownership and
|
|
1013
|
+
refresh the observed snapshot after successful activation. Pre-installed packages
|
|
1014
|
+
remain unowned even when upgraded by Winix.
|
|
1015
|
+
|
|
1016
|
+
An inline declaration such as `windows.package({ id: "Git.Git", version: "2.44.0" })`
|
|
1017
|
+
is exact. Installed version mismatches stop before activation, without an
|
|
1018
|
+
automatic downgrade. Unequal versions that are not dotted numeric values cannot
|
|
1019
|
+
be reliably ordered and fail with instructions to resolve them explicitly.
|
|
1020
|
+
|
|
1021
|
+
After a successful interactive switch that kept a newer floating package,
|
|
1022
|
+
Winix asks `Update winix-windows.lock to <version>? [y/N]`. Declining keeps the
|
|
1023
|
+
lock and still completes the switch. Dry/noninteractive runs never ask or
|
|
1024
|
+
update observed-version pins; `--yes` confirms removals, not lock updates.
|
|
1025
|
+
Normal missing-pin resolution remains unchanged. These defaults apply to
|
|
1026
|
+
`winix switch`, not direct generated-script/DSC activation or plain `apply`.
|
|
1027
|
+
|
|
1028
|
+
Startup file hashes and installed package versions still protect removals.
|
|
1029
|
+
External shortcut edits, package downgrades, and exact-pin drift block
|
|
1030
|
+
reconciliation rather than silently deleting or overwriting managed resources.
|
|
1031
|
+
Restore the recorded resource, or explicitly
|
|
974
1032
|
release Winix's removal rights without deleting anything:
|
|
975
1033
|
|
|
976
1034
|
```powershell
|
|
@@ -203,10 +203,10 @@ export function validateWindowsWslResources(win) {
|
|
|
203
203
|
if (configs > 1)
|
|
204
204
|
throw new Error("Declare only one windows.wsl({ config }) per Windows host");
|
|
205
205
|
if (distros && !WSL_FEATURES.every((name) => features.get(name) === true)) {
|
|
206
|
-
throw new Error("WSL distro
|
|
206
|
+
throw new Error("WSL distro declarations require windows.wsl() or both required optional features enabled");
|
|
207
207
|
}
|
|
208
208
|
if (distros && !Object.values(win.packages ?? {}).some((pkg) => pkg.id.toLowerCase() === "microsoft.wsl")) {
|
|
209
|
-
throw new Error('WSL distro
|
|
209
|
+
throw new Error('WSL distro declarations require windows.package("Microsoft.WSL")');
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
function prepareWindowsDscResources(commands, resources, settingsModule, lock, repositoryDependencies) {
|
|
@@ -10,3 +10,4 @@ export declare function wslRepositoryKey(setup: WinWslSetup): string;
|
|
|
10
10
|
export declare function validWslRepository(value: unknown): value is WindowsLockWslRepository;
|
|
11
11
|
export declare const resolveWslRepository: WindowsWslRepositoryResolver;
|
|
12
12
|
export declare function wslSetupPrelude(setup: WinWslSetup, pin: WindowsLockWslRepository): string[];
|
|
13
|
+
export declare function wslScriptInvocation(name: string, probe: string, activate: string, operation?: string): string[];
|
|
@@ -125,24 +125,28 @@ export function wslSetupPrelude(setup, pin) {
|
|
|
125
125
|
'export NIX_CONFIG="${NIX_CONFIG:+$NIX_CONFIG$\'\\n\'}extra-experimental-features = nix-command flakes"',
|
|
126
126
|
...launch,
|
|
127
127
|
].join("\n");
|
|
128
|
+
return wslScriptInvocation("Invoke-WinixWslSetup", probe, activate);
|
|
129
|
+
}
|
|
130
|
+
export function wslScriptInvocation(name, probe, activate, operation = "WSL setup") {
|
|
128
131
|
return [
|
|
129
|
-
|
|
132
|
+
`function ${name}([bool]$TestOnly) {`,
|
|
133
|
+
` $operation = ${ps(operation)}`,
|
|
130
134
|
` $script = if ($TestOnly) { ${ps(probe + "\n")} } else { ${ps(activate + "\n")} }`,
|
|
131
135
|
" $start = [Diagnostics.ProcessStartInfo]::new('wsl.exe')",
|
|
132
136
|
" $start.UseShellExecute = $false",
|
|
133
137
|
" $start.RedirectStandardInput = $true; $start.RedirectStandardOutput = $true; $start.RedirectStandardError = $true",
|
|
134
138
|
" $start.StandardInputEncoding = [Text.UTF8Encoding]::new($false)",
|
|
135
139
|
" $start.StandardOutputEncoding = $start.StandardInputEncoding; $start.StandardErrorEncoding = $start.StandardInputEncoding",
|
|
136
|
-
" foreach ($argument in @('--distribution', $name, '--user', 'root', '--exec', 'bash', '-s')) { $start.ArgumentList.Add($argument) }",
|
|
140
|
+
" foreach ($argument in @('--distribution', $name, '--user', 'root', '--exec', 'bash', '--noprofile', '--norc', '-s')) { $start.ArgumentList.Add($argument) }",
|
|
137
141
|
" $process = [Diagnostics.Process]::new(); $process.StartInfo = $start",
|
|
138
142
|
" try {",
|
|
139
|
-
" if (-not $process.Start()) { throw
|
|
143
|
+
" if (-not $process.Start()) { throw \"Could not start $operation\" }",
|
|
140
144
|
" $stdout = $process.StandardOutput.ReadToEndAsync(); $stderr = $process.StandardError.ReadToEndAsync()",
|
|
141
145
|
" $process.StandardInput.Write($script); $process.StandardInput.Close()",
|
|
142
146
|
" $process.WaitForExit()",
|
|
143
147
|
" $output = $stdout.GetAwaiter().GetResult(); $errors = $stderr.GetAwaiter().GetResult()",
|
|
144
148
|
" if ($TestOnly -and $process.ExitCode -eq 3) { return $false }",
|
|
145
|
-
" if ($process.ExitCode -ne 0) { throw \"
|
|
149
|
+
" if ($process.ExitCode -ne 0) { throw \"$operation failed ($($process.ExitCode)): $output $errors\" }",
|
|
146
150
|
" if (-not $TestOnly) { if ($output) { Write-Host $output }; if ($errors) { Write-Host $errors } }",
|
|
147
151
|
" return $true",
|
|
148
152
|
" } finally { $process.Dispose() }",
|
|
@@ -6,4 +6,5 @@ export type WindowsWslImageResolver = (architecture: WslArchitecture) => Omit<Wi
|
|
|
6
6
|
export declare function validWslImage(value: unknown): value is WindowsLockWslImage;
|
|
7
7
|
export declare const resolveNixosWslImage: WindowsWslImageResolver;
|
|
8
8
|
export declare function optionalFeatureProperties(names: string[], enabled: boolean): WinDscProperties;
|
|
9
|
+
export declare function wslIdentityProbe(host: string): string;
|
|
9
10
|
export declare function wslDistroProperties(distro: WinWslDistro, pins: Record<string, WindowsLockWslImage>, repositories?: Record<string, WindowsLockWslRepository>): WinDscProperties;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { filePathExpression, filePathPrelude } from "../../helpers/windows.js";
|
|
2
2
|
import { powerShellLiteral as ps } from "../../helpers/utils.js";
|
|
3
|
-
import { wslRepositoryKey, wslSetupPrelude } from "./wsl-setup.js";
|
|
3
|
+
import { wslRepositoryKey, wslSetupPrelude, wslScriptInvocation } from "./wsl-setup.js";
|
|
4
4
|
export function validWslImage(value) {
|
|
5
5
|
if (!value || typeof value !== "object")
|
|
6
6
|
return false;
|
|
@@ -83,6 +83,16 @@ export function optionalFeatureProperties(names, enabled) {
|
|
|
83
83
|
].join("\n"),
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
+
export function wslIdentityProbe(host) {
|
|
87
|
+
return [
|
|
88
|
+
"set -euo pipefail",
|
|
89
|
+
'export PATH="/run/current-system/sw/bin:/run/wrappers/bin${PATH:+:$PATH}"',
|
|
90
|
+
"grep -Eq '^ID=\"?nixos\"?$' /etc/os-release || { echo 'Existing WSL distro must run NixOS' >&2; exit 2; }",
|
|
91
|
+
'actual=$(cat /proc/sys/kernel/hostname)',
|
|
92
|
+
`expected='${host.replaceAll("'", "'\\''")}'`,
|
|
93
|
+
'[[ "$actual" == "$expected" ]] || { printf \'Existing NixOS WSL hostname mismatch: expected %s, found %s\\n\' "$expected" "$actual" >&2; exit 2; }',
|
|
94
|
+
].join("\n");
|
|
95
|
+
}
|
|
86
96
|
export function wslDistroProperties(distro, pins, repositories = {}) {
|
|
87
97
|
const images = [];
|
|
88
98
|
for (const architecture of ["x64", "arm64"]) {
|
|
@@ -97,6 +107,7 @@ export function wslDistroProperties(distro, pins, repositories = {}) {
|
|
|
97
107
|
...filePathPrelude(),
|
|
98
108
|
"if ([Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) { throw 'WSL provisioning must run as the intended Windows user, not SYSTEM' }",
|
|
99
109
|
`$name = ${ps(distro.name)}`,
|
|
110
|
+
`$expectedHostname = ${ps(distro.host ?? distro.setup?.host ?? "")}`,
|
|
100
111
|
`$location = ${filePathExpression(distro.installLocation)}`,
|
|
101
112
|
"if (-not [IO.Path]::IsPathFullyQualified($location)) { throw 'WSL installLocation must resolve to an absolute path' }",
|
|
102
113
|
"$location = [IO.Path]::GetFullPath($location)",
|
|
@@ -104,12 +115,16 @@ export function wslDistroProperties(distro, pins, repositories = {}) {
|
|
|
104
115
|
" throw 'WSL installLocation must be an absolute local-drive directory, not a drive root or UNC path'",
|
|
105
116
|
"}",
|
|
106
117
|
"$marker = Join-Path $location '.winix-wsl.json'",
|
|
118
|
+
"$localAppData = [Environment]::GetFolderPath('LocalApplicationData')",
|
|
119
|
+
"if (-not $localAppData -or -not [IO.Path]::IsPathFullyQualified($localAppData)) { throw 'Cannot determine WSL tracking location' }",
|
|
120
|
+
"$trackingDirectory = Join-Path $localAppData 'Winix\\wsl-registrations'",
|
|
121
|
+
`$tracking = Join-Path $trackingDirectory ${ps(`registration-${distro.name.toLowerCase()}.json`)}`,
|
|
107
122
|
"$lxss = 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Lxss'",
|
|
108
123
|
` $makeDefault = ${distro.default ? "$true" : "$false"}`,
|
|
109
124
|
` $images = @{ ${images.join("; ")} }`,
|
|
110
125
|
"function Normalize-WinixWslPath([string]$Path) {",
|
|
111
126
|
" if ($Path.StartsWith('\\\\?\\')) { $Path = $Path.Substring(4) }",
|
|
112
|
-
" [IO.Path]::GetFullPath($Path)
|
|
127
|
+
" [IO.Path]::TrimEndingDirectorySeparator([IO.Path]::GetFullPath($Path))",
|
|
113
128
|
"}",
|
|
114
129
|
"function Get-WinixWslRegistration {",
|
|
115
130
|
" if (-not (Test-Path -LiteralPath $lxss)) { return $null }",
|
|
@@ -119,17 +134,65 @@ export function wslDistroProperties(distro, pins, repositories = {}) {
|
|
|
119
134
|
" if ($matches.Count -eq 1) { return $matches[0] }",
|
|
120
135
|
" return $null",
|
|
121
136
|
"}",
|
|
122
|
-
"function Assert-
|
|
123
|
-
" if ((Normalize-WinixWslPath $Registration.BasePath) -ine (Normalize-WinixWslPath $location) -or $Registration.Version -ne 2) {",
|
|
137
|
+
"function Assert-WinixWslLocation($Registration) {",
|
|
138
|
+
" if ((Normalize-WinixWslPath $Registration.BasePath) -ine (Normalize-WinixWslPath $location) -or $Registration.Version -ne 2 -or -not $Registration.PSChildName) {",
|
|
124
139
|
" throw \"Conflicting WSL registration for $name; refusing to move, replace, or convert an existing distro\"",
|
|
125
140
|
" }",
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
141
|
+
"}",
|
|
142
|
+
"function Get-WinixWslTracking {",
|
|
143
|
+
" if (-not (Test-Path -LiteralPath $tracking)) { return $null }",
|
|
144
|
+
" $record = [IO.File]::ReadAllText($tracking) | ConvertFrom-Json",
|
|
145
|
+
" if ($record.version -ne 1 -or $record.source -ne 'nixos-wsl' -or $record.name -ine $name -or",
|
|
146
|
+
" $record.adopted -isnot [bool] -or $record.registration -isnot [string] -or -not $record.registration -or",
|
|
147
|
+
" $record.location -isnot [string] -or -not [IO.Path]::IsPathFullyQualified($record.location) -or",
|
|
148
|
+
" ($record.adopted -and ($record.host -isnot [string] -or -not $record.host))) {",
|
|
149
|
+
" throw \"Invalid WSL tracking record: $tracking; inspect it before manual recovery\"",
|
|
150
|
+
" }",
|
|
151
|
+
" return $record",
|
|
152
|
+
"}",
|
|
153
|
+
"function Assert-WinixWslIdentity {",
|
|
154
|
+
" if (-not $expectedHostname) { throw \"Cannot adopt existing WSL distro $name without an expected Linux hostname; declare host or setup.host\" }",
|
|
155
|
+
" if (-not (Invoke-WinixWslIdentity $true)) { throw 'WSL identity validation did not complete' }",
|
|
156
|
+
"}",
|
|
157
|
+
"function Get-WinixWslKind($Registration, $Record) {",
|
|
158
|
+
" if ($Registration.Version -ne 2 -or -not $Registration.PSChildName) { throw \"Expected a WSL 2 registration for $name; refusing conversion or replacement\" }",
|
|
159
|
+
" if ($null -ne $Record) {",
|
|
160
|
+
" if ($Record.registration -ine $Registration.PSChildName -or",
|
|
161
|
+
" (Normalize-WinixWslPath $Record.location) -ine (Normalize-WinixWslPath $Registration.BasePath)) {",
|
|
162
|
+
" throw \"Tracked WSL registration changed for $name; refusing replacement\"",
|
|
163
|
+
" }",
|
|
164
|
+
" if ($Record.adopted) {",
|
|
165
|
+
" if ($Record.host -cne $expectedHostname) { throw \"Adopted WSL hostname declaration changed for $name; refusing relink\" }",
|
|
166
|
+
" Assert-WinixWslIdentity",
|
|
167
|
+
" return 'adopted'",
|
|
168
|
+
" }",
|
|
169
|
+
" }",
|
|
170
|
+
" $existingMarker = Join-Path $Registration.BasePath '.winix-wsl.json'",
|
|
171
|
+
" if (Test-Path -LiteralPath $existingMarker) {",
|
|
172
|
+
" Assert-WinixWslLocation $Registration",
|
|
173
|
+
" $legacy = [IO.File]::ReadAllText($existingMarker) | ConvertFrom-Json",
|
|
174
|
+
" if ($legacy.version -ne 1 -or $legacy.source -ne 'nixos-wsl' -or $legacy.name -ine $name -or $legacy.registration -ine $Registration.PSChildName) {",
|
|
130
175
|
" throw \"WSL ownership marker does not match registration for $name\"",
|
|
131
176
|
" }",
|
|
177
|
+
" return 'created'",
|
|
178
|
+
" }",
|
|
179
|
+
" if ($null -ne $Record) { throw \"Winix-created WSL distro $name has lost its ownership marker; refusing adoption\" }",
|
|
180
|
+
" if (Test-Path -LiteralPath $marker) { throw \"Conflicting WSL registration for $name; the configured location already has a Winix marker\" }",
|
|
181
|
+
" Assert-WinixWslIdentity",
|
|
182
|
+
" return 'adopted'",
|
|
183
|
+
"}",
|
|
184
|
+
"function Register-WinixWsl($Registration, [bool]$Adopted) {",
|
|
185
|
+
" $current = Get-WinixWslRegistration",
|
|
186
|
+
" if ($null -eq $current -or $current.PSChildName -ine $Registration.PSChildName -or",
|
|
187
|
+
" (Normalize-WinixWslPath $current.BasePath) -ine (Normalize-WinixWslPath $Registration.BasePath) -or $current.Version -ne 2) {",
|
|
188
|
+
" throw 'WSL registration changed during validation; refusing to record it'",
|
|
132
189
|
" }",
|
|
190
|
+
" [IO.Directory]::CreateDirectory($trackingDirectory) | Out-Null",
|
|
191
|
+
" $record = @{ version = 1; source = 'nixos-wsl'; name = $name; registration = $Registration.PSChildName;",
|
|
192
|
+
" location = Normalize-WinixWslPath $Registration.BasePath; adopted = $Adopted; host = $expectedHostname }",
|
|
193
|
+
" $stream = [IO.File]::Open($tracking, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::None)",
|
|
194
|
+
" $writer = [IO.StreamWriter]::new($stream, [Text.UTF8Encoding]::new($false))",
|
|
195
|
+
" try { $writer.Write(($record | ConvertTo-Json -Compress)) } finally { $writer.Dispose() }",
|
|
133
196
|
"}",
|
|
134
197
|
"function Test-WinixWslDefault($Registration) {",
|
|
135
198
|
" if (-not $makeDefault) { return $true }",
|
|
@@ -140,6 +203,8 @@ export function wslDistroProperties(distro, pins, repositories = {}) {
|
|
|
140
203
|
" if ($LASTEXITCODE -ne 0) { throw \"WSL command failed ($LASTEXITCODE): $($Arguments -join ' ') $($output -join ' ')\" }",
|
|
141
204
|
"}",
|
|
142
205
|
];
|
|
206
|
+
const identity = wslIdentityProbe(distro.host ?? distro.setup?.host ?? "");
|
|
207
|
+
prelude.push(...wslScriptInvocation("Invoke-WinixWslIdentity", identity, identity, "WSL identity validation"));
|
|
143
208
|
if (distro.setup) {
|
|
144
209
|
const pin = repositories[wslRepositoryKey(distro.setup)];
|
|
145
210
|
if (!pin)
|
|
@@ -147,19 +212,32 @@ export function wslDistroProperties(distro, pins, repositories = {}) {
|
|
|
147
212
|
prelude.push(...wslSetupPrelude(distro.setup, pin));
|
|
148
213
|
}
|
|
149
214
|
return {
|
|
150
|
-
getScript: [
|
|
215
|
+
getScript: [
|
|
216
|
+
...prelude,
|
|
217
|
+
"$registration = Get-WinixWslRegistration",
|
|
218
|
+
"$record = Get-WinixWslTracking",
|
|
219
|
+
"if ($null -eq $registration -and $null -ne $record) { throw 'Tracked WSL registration is missing; inspect tracking before creating a replacement' }",
|
|
220
|
+
"if ($null -ne $registration) { [void](Get-WinixWslKind $registration $record) }",
|
|
221
|
+
"$registration | Select-Object DistributionName,BasePath,Version",
|
|
222
|
+
].join("\n"),
|
|
151
223
|
testScript: [
|
|
152
224
|
...prelude,
|
|
153
225
|
"$registration = Get-WinixWslRegistration",
|
|
226
|
+
"$record = Get-WinixWslTracking",
|
|
227
|
+
"if ($null -eq $registration -and $null -ne $record) { throw 'Tracked WSL registration is missing; inspect tracking before creating a replacement' }",
|
|
154
228
|
"if ($null -eq $registration) { return $false }",
|
|
155
|
-
"
|
|
229
|
+
"$kind = Get-WinixWslKind $registration $record",
|
|
230
|
+
"if ($null -eq $record) { return $false }",
|
|
231
|
+
"if ($kind -eq 'adopted') { return $true }",
|
|
156
232
|
...(distro.setup ? ["if (-not (Invoke-WinixWslSetup $true)) { return $false }"] : []),
|
|
157
233
|
"Test-WinixWslDefault $registration",
|
|
158
234
|
].join("\n"),
|
|
159
235
|
setScript: [
|
|
160
236
|
...prelude,
|
|
161
237
|
"$registration = Get-WinixWslRegistration",
|
|
162
|
-
"
|
|
238
|
+
"$record = Get-WinixWslTracking",
|
|
239
|
+
"if ($null -eq $registration -and $null -ne $record) { throw 'Tracked WSL registration is missing; inspect tracking before creating a replacement' }",
|
|
240
|
+
"if ($null -ne $registration) { $kind = Get-WinixWslKind $registration $record } else {",
|
|
163
241
|
" if ((Test-Path -LiteralPath 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending') -or",
|
|
164
242
|
" (Test-Path -LiteralPath 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired')) {",
|
|
165
243
|
" throw 'WINIX_REBOOT_REQUIRED: Restart Windows yourself, then rerun winix switch before registering WSL.'",
|
|
@@ -180,13 +258,16 @@ export function wslDistroProperties(distro, pins, repositories = {}) {
|
|
|
180
258
|
" Invoke-WinixWsl @('--import', $name, $location, $archive, '--version', '2')",
|
|
181
259
|
" $registration = Get-WinixWslRegistration",
|
|
182
260
|
" if ($null -eq $registration) { throw 'WSL import returned success without registering the requested distro' }",
|
|
183
|
-
" Assert-
|
|
184
|
-
" $
|
|
261
|
+
" Assert-WinixWslLocation $registration",
|
|
262
|
+
" $markerRecord = @{ version = 1; source = 'nixos-wsl'; name = $name; registration = $registration.PSChildName; imageVersion = $image.Version; sha256 = $image.Sha256 }",
|
|
185
263
|
" $stream = [IO.File]::Open($marker, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::None)",
|
|
186
264
|
" $writer = [IO.StreamWriter]::new($stream, [Text.UTF8Encoding]::new($false))",
|
|
187
|
-
" try { $writer.Write(($
|
|
265
|
+
" try { $writer.Write(($markerRecord | ConvertTo-Json -Compress)) } finally { $writer.Dispose() }",
|
|
188
266
|
" } finally { Remove-Item -LiteralPath $temporary -Recurse -Force }",
|
|
267
|
+
" $kind = 'created'",
|
|
189
268
|
"}",
|
|
269
|
+
"if ($null -eq $record) { Register-WinixWsl $registration ($kind -eq 'adopted') }",
|
|
270
|
+
"if ($kind -eq 'adopted') { Write-Host 'Existing NixOS WSL distro linked; Linux activation remains manual.'; return }",
|
|
190
271
|
...(distro.setup ? ["[void](Invoke-WinixWslSetup $false)"] : []),
|
|
191
272
|
"if (-not (Test-WinixWslDefault $registration)) { Invoke-WinixWsl @('--set-default', $name) }",
|
|
192
273
|
"if (-not (Test-WinixWslDefault $registration)) { throw 'WSL default distribution verification failed' }",
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { evaluate } from "../../evaluator/index.js";
|
|
1
2
|
import { type WindowsLock, type WindowsPackageVersionResolver, type WindowsModuleVersionResolver } from "../../backends/windows/lockfile.js";
|
|
2
3
|
import { type WindowsWslImageResolver } from "../../backends/windows/wsl.js";
|
|
3
4
|
import { type WindowsWslRepositoryResolver } from "../../backends/windows/wsl-setup.js";
|
|
4
5
|
import { type ActivationPlatform } from "../activation.js";
|
|
5
6
|
interface ApplyOptions {
|
|
7
|
+
/** Activation-only overrides; the committed lock and inline declarations remain unchanged. */
|
|
8
|
+
windowsPackageVersions?: (hosts: ReturnType<typeof evaluate>, lock: WindowsLock) => Promise<Record<string, string>>;
|
|
6
9
|
host?: string;
|
|
7
10
|
dry: boolean;
|
|
8
11
|
diff: boolean;
|
|
@@ -32,8 +32,14 @@ export async function applyWorkspace(cwd, opts) {
|
|
|
32
32
|
? await prepareWindowsLock(configDir, windowsHosts, opts.dry || opts.windowsLockDry === true, opts.resolveWindowsPackageVersion ?? resolveWingetVersion, opts.resolveWindowsModuleVersion ?? resolvePowerShellModuleVersion, opts.resolveWindowsWslImage ?? resolveNixosWslImage, opts.resolveWindowsWslRepository ?? resolveWslRepository)
|
|
33
33
|
: undefined;
|
|
34
34
|
const nixOutput = nixHosts.length > 0 ? generateNix(workspace, nixHosts) : undefined;
|
|
35
|
+
const runtimeVersions = windowsLock && opts.windowsPackageVersions
|
|
36
|
+
? await opts.windowsPackageVersions(windowsHosts, windowsLock) : {};
|
|
37
|
+
const activationLock = windowsLock ? {
|
|
38
|
+
...windowsLock,
|
|
39
|
+
packages: Object.fromEntries(Object.entries(windowsLock.packages).map(([id, pin]) => [id, runtimeVersions[id] === undefined ? pin : { ...pin, version: runtimeVersions[id] }])),
|
|
40
|
+
} : undefined;
|
|
35
41
|
const windowsOutput = windowsHosts.length > 0
|
|
36
|
-
? generateWindows(windowsHosts,
|
|
42
|
+
? generateWindows(windowsHosts, activationLock, configDir)
|
|
37
43
|
: undefined;
|
|
38
44
|
printWarnings(nixOutput?.warnings ?? []);
|
|
39
45
|
printWarnings(windowsOutput?.warnings ?? []);
|
|
@@ -7,6 +7,8 @@ import { loadWorkspace } from "../loader.js";
|
|
|
7
7
|
import { runCommand } from "../run.js";
|
|
8
8
|
import { activationCommand, assertActivationSupported, platformForEvaluatedHost, } from "../activation.js";
|
|
9
9
|
import { applyWorkspace } from "./apply.js";
|
|
10
|
+
import { readWindowsLock, serializeWindowsLock, writeWindowsLock } from "../../backends/windows/lockfile.js";
|
|
11
|
+
import { compareWindowsPackageVersions, confirmWindowsPackageLockUpdate, effectiveWindowsPackageVersion, } from "../windows-package-versions.js";
|
|
10
12
|
export async function switchCommand(cwd, opts) {
|
|
11
13
|
const { workspace, configDir } = await loadWorkspace(cwd);
|
|
12
14
|
const evaluated = evaluate(workspace);
|
|
@@ -21,18 +23,67 @@ export async function switchCommand(cwd, opts) {
|
|
|
21
23
|
const statePath = platform === "windows" && process.platform === "win32"
|
|
22
24
|
? opts.windowsState?.path ?? windowsStatePath() : undefined;
|
|
23
25
|
const performSwitch = async () => {
|
|
26
|
+
const adapter = opts.windowsState?.adapter ?? nativeWindowsStateAdapter;
|
|
27
|
+
const requirements = {};
|
|
28
|
+
const activationVersions = {};
|
|
29
|
+
const newer = [];
|
|
24
30
|
const result = await applyWorkspace(cwd, {
|
|
25
31
|
host: hostName,
|
|
26
32
|
dry: opts.dry && platform === "windows",
|
|
27
33
|
diff: false,
|
|
28
34
|
windowsLockDry: opts.dry,
|
|
35
|
+
windowsPackageVersions: statePath ? async (hosts, lock) => {
|
|
36
|
+
const versions = {};
|
|
37
|
+
for (const host of hosts) {
|
|
38
|
+
for (const resource of managedWindowsResources(host)) {
|
|
39
|
+
if (resource.kind !== "package")
|
|
40
|
+
continue;
|
|
41
|
+
const pkg = host.windows.packages?.[resource.id];
|
|
42
|
+
const version = pkg?.version ?? lock.packages[resource.id]?.version;
|
|
43
|
+
if (!version)
|
|
44
|
+
throw new Error(`Missing package version: ${resource.id}`);
|
|
45
|
+
const requirement = { version, exact: pkg?.version !== undefined };
|
|
46
|
+
requirements[resourceKey(resource)] = requirement;
|
|
47
|
+
const snapshot = await adapter.inspect(resource);
|
|
48
|
+
if (snapshot !== null && !("version" in snapshot))
|
|
49
|
+
throw new Error(`Invalid package snapshot: ${resource.id}`);
|
|
50
|
+
const installed = snapshot?.version;
|
|
51
|
+
versions[resource.id] = effectiveWindowsPackageVersion(resource.id, requirement, installed);
|
|
52
|
+
activationVersions[resourceKey(resource)] = versions[resource.id];
|
|
53
|
+
if (!requirement.exact && installed !== undefined && compareWindowsPackageVersions(installed, version) > 0) {
|
|
54
|
+
console.log(`Keeping ${resource.id} ${installed} (locked ${version}).`);
|
|
55
|
+
newer.push({ id: resource.id, installed, locked: version });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return versions;
|
|
60
|
+
} : undefined,
|
|
29
61
|
});
|
|
30
62
|
const activationTarget = platform === "windows"
|
|
31
63
|
? windowsConfigurationForHost(result.outDir, hostName)
|
|
32
64
|
: flakeRefForHost(result.outDir, hostName);
|
|
33
65
|
const command = activationCommand(platform, activationTarget);
|
|
34
66
|
console.log(`\nRunning: ${command.join(" ")}`);
|
|
35
|
-
const activate = () =>
|
|
67
|
+
const activate = async () => {
|
|
68
|
+
if (statePath && !opts.dry) {
|
|
69
|
+
for (const resource of managedWindowsResources(selected)) {
|
|
70
|
+
if (resource.kind !== "package")
|
|
71
|
+
continue;
|
|
72
|
+
const key = resourceKey(resource);
|
|
73
|
+
const current = await adapter.inspect(resource);
|
|
74
|
+
if (current !== null) {
|
|
75
|
+
if (!("version" in current))
|
|
76
|
+
throw new Error(`Invalid package snapshot: ${resource.id}`);
|
|
77
|
+
effectiveWindowsPackageVersion(resource.id, requirements[key], current.version);
|
|
78
|
+
if (!requirements[key].exact &&
|
|
79
|
+
compareWindowsPackageVersions(current.version, activationVersions[key]) > 0) {
|
|
80
|
+
throw new Error(`Package ${resource.id} updated during switch. Rerun switch to keep ${current.version}; refusing stale activation.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
await runCommand(command[0], command.slice(1), { dry: opts.dry });
|
|
86
|
+
};
|
|
36
87
|
if (statePath) {
|
|
37
88
|
const desired = managedWindowsResources(selected);
|
|
38
89
|
const windows = selected.windows;
|
|
@@ -50,12 +101,40 @@ export async function switchCommand(cwd, opts) {
|
|
|
50
101
|
statePath,
|
|
51
102
|
owner: await windowsStateOwner(configDir, hostName),
|
|
52
103
|
desired, definitions,
|
|
104
|
+
packageRequirements: requirements,
|
|
53
105
|
dry: opts.dry,
|
|
54
106
|
yes: opts.yes,
|
|
55
|
-
adapter
|
|
107
|
+
adapter,
|
|
56
108
|
lockHeld: true,
|
|
57
109
|
activate,
|
|
58
110
|
});
|
|
111
|
+
if (!opts.dry && lock) {
|
|
112
|
+
let expected = serializeWindowsLock(lock);
|
|
113
|
+
for (const candidate of newer) {
|
|
114
|
+
const current = await adapter.inspect({
|
|
115
|
+
kind: "package", id: candidate.id, source: lock.packages[candidate.id].source,
|
|
116
|
+
});
|
|
117
|
+
if (!current || !("version" in current) || current.version !== candidate.installed) {
|
|
118
|
+
console.log(`Not updating lock for ${candidate.id}: installed version changed during activation.`);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (!await confirmWindowsPackageLockUpdate(candidate.id, candidate.installed, candidate.locked))
|
|
122
|
+
continue;
|
|
123
|
+
const saved = readWindowsLock(configDir);
|
|
124
|
+
if (!saved || serializeWindowsLock(saved) !== expected) {
|
|
125
|
+
throw new Error("winix-windows.lock changed during switch; refusing to overwrite concurrent changes.");
|
|
126
|
+
}
|
|
127
|
+
const now = new Date().toISOString();
|
|
128
|
+
const updated = {
|
|
129
|
+
...saved, generatedAt: now, packages: {
|
|
130
|
+
...saved.packages, [candidate.id]: { ...saved.packages[candidate.id], version: candidate.installed, resolvedAt: now },
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
writeWindowsLock(configDir, updated);
|
|
134
|
+
expected = serializeWindowsLock(updated);
|
|
135
|
+
console.log(`Updated winix-windows.lock: ${candidate.id} ${candidate.locked} -> ${candidate.installed}.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
59
138
|
}
|
|
60
139
|
else {
|
|
61
140
|
if (platform === "windows")
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Only dotted numeric versions have an unambiguous ordering across Windows installers. */
|
|
2
|
+
export declare function compareWindowsPackageVersions(left: string, right: string): number;
|
|
3
|
+
export interface WindowsPackageRequirement {
|
|
4
|
+
version: string;
|
|
5
|
+
exact: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function effectiveWindowsPackageVersion(id: string, requirement: WindowsPackageRequirement, installed?: string): string;
|
|
8
|
+
export declare function confirmWindowsPackageLockUpdate(id: string, installed: string, locked: string): Promise<boolean>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
/** Only dotted numeric versions have an unambiguous ordering across Windows installers. */
|
|
3
|
+
export function compareWindowsPackageVersions(left, right) {
|
|
4
|
+
if (left === right)
|
|
5
|
+
return 0;
|
|
6
|
+
if (!/^\d+(?:\.\d+)*$/.test(left) || !/^\d+(?:\.\d+)*$/.test(right)) {
|
|
7
|
+
throw new Error(`Cannot reliably compare Windows package versions "${left}" and "${right}". Declare an exact version or resolve the package version explicitly.`);
|
|
8
|
+
}
|
|
9
|
+
const a = left.split(".").map(BigInt);
|
|
10
|
+
const b = right.split(".").map(BigInt);
|
|
11
|
+
for (let index = 0; index < Math.max(a.length, b.length); index++) {
|
|
12
|
+
const difference = (a[index] ?? 0n) - (b[index] ?? 0n);
|
|
13
|
+
if (difference !== 0n)
|
|
14
|
+
return difference > 0n ? 1 : -1;
|
|
15
|
+
}
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
export function effectiveWindowsPackageVersion(id, requirement, installed) {
|
|
19
|
+
if (installed === undefined)
|
|
20
|
+
return requirement.version;
|
|
21
|
+
if (requirement.exact) {
|
|
22
|
+
if (installed !== requirement.version) {
|
|
23
|
+
throw new Error(`Exact version mismatch for ${id}: installed ${installed}, required ${requirement.version}. Resolve it explicitly; Winix will not silently replace or downgrade it.`);
|
|
24
|
+
}
|
|
25
|
+
return requirement.version;
|
|
26
|
+
}
|
|
27
|
+
return compareWindowsPackageVersions(installed, requirement.version) >= 0 ? installed : requirement.version;
|
|
28
|
+
}
|
|
29
|
+
export async function confirmWindowsPackageLockUpdate(id, installed, locked) {
|
|
30
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
31
|
+
return false;
|
|
32
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
prompt.once("close", () => controller.abort());
|
|
35
|
+
prompt.once("SIGINT", () => controller.abort());
|
|
36
|
+
try {
|
|
37
|
+
const answer = await prompt.question(`${id}: installed ${installed}, locked ${locked}. Update winix-windows.lock to ${installed}? [y/N] `, { signal: controller.signal });
|
|
38
|
+
return /^(y|yes)$/i.test(answer.trim());
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
prompt.close();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EvaluatedHost } from "../evaluator/index.js";
|
|
2
|
+
import { type WindowsPackageRequirement } from "./windows-package-versions.js";
|
|
2
3
|
export type ManagedResource = {
|
|
3
4
|
kind: "startup";
|
|
4
5
|
name: string;
|
|
@@ -18,6 +19,7 @@ interface Entry {
|
|
|
18
19
|
owned: boolean;
|
|
19
20
|
snapshot: ResourceSnapshot;
|
|
20
21
|
definition: string;
|
|
22
|
+
packageExact?: boolean;
|
|
21
23
|
}
|
|
22
24
|
interface AppliedState {
|
|
23
25
|
version: 1;
|
|
@@ -28,6 +30,7 @@ export interface WindowsStateAdapter {
|
|
|
28
30
|
remove(resource: ManagedResource, snapshot: NonNullable<ResourceSnapshot>): Promise<void>;
|
|
29
31
|
}
|
|
30
32
|
export interface ReconcileOptions {
|
|
33
|
+
packageRequirements?: Record<string, WindowsPackageRequirement>;
|
|
31
34
|
statePath: string;
|
|
32
35
|
owner: string;
|
|
33
36
|
desired: ManagedResource[];
|
|
@@ -6,6 +6,7 @@ import { dirname, join } from "node:path";
|
|
|
6
6
|
import { createInterface } from "node:readline/promises";
|
|
7
7
|
import { powerShellLiteral } from "../helpers/utils.js";
|
|
8
8
|
import { runCommand } from "./run.js";
|
|
9
|
+
import { compareWindowsPackageVersions, effectiveWindowsPackageVersion } from "./windows-package-versions.js";
|
|
9
10
|
export function resourceKey(resource) {
|
|
10
11
|
return JSON.stringify(resource.kind === "startup"
|
|
11
12
|
? ["startup", resource.name.toLowerCase()]
|
|
@@ -99,6 +100,7 @@ export function parseAppliedState(text) {
|
|
|
99
100
|
key !== resourceKey(entry.resource) || typeof entry.owned !== "boolean" ||
|
|
100
101
|
typeof entry.definition !== "string" ||
|
|
101
102
|
!Array.isArray(entry.owners) || !entry.owners.every((owner) => typeof owner === "string") ||
|
|
103
|
+
(entry.packageExact !== undefined && typeof entry.packageExact !== "boolean") ||
|
|
102
104
|
!(entry.snapshot === null || (entry.resource.kind === "startup"
|
|
103
105
|
? typeof entry.snapshot?.fingerprint === "string" && /^[a-f0-9]{64}$/.test(entry.snapshot.fingerprint)
|
|
104
106
|
: typeof entry.snapshot?.version === "string" && entry.snapshot.version.length > 0))) {
|
|
@@ -207,14 +209,31 @@ export async function reconcileWindows(opts) {
|
|
|
207
209
|
const current = await opts.adapter.inspect(resource);
|
|
208
210
|
before.set(key, current);
|
|
209
211
|
const entry = state.entries[key];
|
|
212
|
+
const requirement = resource.kind === "package" ? opts.packageRequirements?.[key] : undefined;
|
|
213
|
+
if (requirement && current && "version" in current) {
|
|
214
|
+
effectiveWindowsPackageVersion(resource.kind === "package" ? resource.id : key, requirement, current.version);
|
|
215
|
+
}
|
|
210
216
|
if (typeof opts.definitions[key] !== "string")
|
|
211
217
|
throw new Error(`Missing resource definition: ${key}`);
|
|
212
218
|
if (entry?.owners.some((owner) => owner !== opts.owner) && entry.definition !== opts.definitions[key]) {
|
|
213
219
|
throw new Error(`Conflicting declaration for resource required by another workspace/host: ${key}. ` +
|
|
214
220
|
"Run winix state owners; after a checkout move or host rename, explicitly preview state migrate-owner <id> --host <name> --dry.");
|
|
215
221
|
}
|
|
222
|
+
if (requirement && entry?.owners.some((owner) => owner !== opts.owner)) {
|
|
223
|
+
if (entry.packageExact !== undefined && entry.packageExact !== requirement.exact) {
|
|
224
|
+
throw new Error(`Conflicting exact/minimum package policies across workspace/hosts: ${key}`);
|
|
225
|
+
}
|
|
226
|
+
if (!sameSnapshot(current, entry.snapshot) && entry.packageExact !== false) {
|
|
227
|
+
throw new Error(`Package changed while required by another exact or legacy workspace/host: ${key}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
216
230
|
if (entry?.owned && current !== null && !sameSnapshot(current, entry.snapshot)) {
|
|
217
|
-
|
|
231
|
+
const upgrade = requirement && !requirement.exact && "version" in current &&
|
|
232
|
+
entry.snapshot && "version" in entry.snapshot &&
|
|
233
|
+
compareWindowsPackageVersions(current.version, entry.snapshot.version) > 0;
|
|
234
|
+
if (!upgrade)
|
|
235
|
+
throw new Error(`Managed resource changed outside Winix: ${key}. Restore it or explicitly resolve ownership before activation.`);
|
|
236
|
+
report(`Keeping externally upgraded package: ${key} ${current.version}`);
|
|
218
237
|
}
|
|
219
238
|
}
|
|
220
239
|
const removals = [];
|
|
@@ -253,8 +272,25 @@ export async function reconcileWindows(opts) {
|
|
|
253
272
|
if (current === null)
|
|
254
273
|
throw new Error(`Activation succeeded but managed resource is missing: ${key}`);
|
|
255
274
|
const entry = state.entries[key];
|
|
275
|
+
const requirement = resource.kind === "package" ? opts.packageRequirements?.[key] : undefined;
|
|
276
|
+
if (requirement) {
|
|
277
|
+
if (!("version" in current) || (requirement.exact
|
|
278
|
+
? current.version !== requirement.version
|
|
279
|
+
: compareWindowsPackageVersions(current.version, requirement.version) < 0)) {
|
|
280
|
+
throw new Error(`Activation did not satisfy package version requirement: ${key}`);
|
|
281
|
+
}
|
|
282
|
+
const initial = before.get(key);
|
|
283
|
+
if (!requirement.exact && initial && "version" in initial &&
|
|
284
|
+
compareWindowsPackageVersions(current.version, initial.version) < 0) {
|
|
285
|
+
throw new Error(`Activation unexpectedly downgraded package: ${key}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
256
288
|
if (entry && entry.owners.some((owner) => owner !== opts.owner) && !sameSnapshot(current, entry.snapshot)) {
|
|
257
|
-
|
|
289
|
+
const upgrade = requirement && !requirement.exact && entry.packageExact === false && "version" in current &&
|
|
290
|
+
entry.snapshot && "version" in entry.snapshot &&
|
|
291
|
+
compareWindowsPackageVersions(current.version, entry.snapshot.version) > 0;
|
|
292
|
+
if (!upgrade)
|
|
293
|
+
throw new Error(`Activation changed a resource required by another workspace/host: ${key}`);
|
|
258
294
|
}
|
|
259
295
|
after.set(key, current);
|
|
260
296
|
}
|
|
@@ -272,6 +308,9 @@ export async function reconcileWindows(opts) {
|
|
|
272
308
|
(resource.kind === "startup" && !sameSnapshot(initial, current)),
|
|
273
309
|
snapshot: current,
|
|
274
310
|
definition: opts.definitions[key],
|
|
311
|
+
...(resource.kind === "package" && opts.packageRequirements?.[key]
|
|
312
|
+
? { packageExact: opts.packageRequirements[key].exact }
|
|
313
|
+
: previous?.packageExact === undefined ? {} : { packageExact: previous.packageExact }),
|
|
275
314
|
};
|
|
276
315
|
}
|
|
277
316
|
await saveState(opts.statePath, state);
|
|
@@ -76,6 +76,7 @@ export interface WinWslOpts extends Pick<WinFileOpts, "backup" | "force" | "depe
|
|
|
76
76
|
export interface WinWslNamespace {
|
|
77
77
|
/** Declare the locked Microsoft.WSL package, required features, and optional .wslconfig. */
|
|
78
78
|
(opts?: WinWslOpts): ResourceHandle;
|
|
79
|
+
/** Create an absent distro or adopt a matching WSL 2/NixOS/Linux hostname registration. */
|
|
79
80
|
distro(name: string, spec: WinWslDistroSpec): ResourceHandle;
|
|
80
81
|
}
|
|
81
82
|
export declare function filePathExpression(value: WinFilePath): string;
|
package/dist/helpers/windows.js
CHANGED
|
@@ -994,12 +994,17 @@ export const windows = {
|
|
|
994
994
|
(spec.default !== undefined && typeof spec.default !== "boolean")) {
|
|
995
995
|
throw new Error("windows.wsl.distro requires source 'nixos-wsl', an absolute/environment/known-folder installLocation, and an optional boolean default");
|
|
996
996
|
}
|
|
997
|
+
if (spec.host !== undefined && (typeof spec.host !== "string" ||
|
|
998
|
+
!/^[a-z0-9][a-z0-9._-]*$/i.test(spec.host))) {
|
|
999
|
+
throw new Error("windows.wsl.distro host must be a valid expected Linux hostname");
|
|
1000
|
+
}
|
|
997
1001
|
return dscHandle(withDscMetadata(withDscToken({
|
|
998
1002
|
resourceType: POWERSHELL_SCRIPT_RESOURCE,
|
|
999
1003
|
name: `WSL distro ${name}`,
|
|
1000
1004
|
dependsOn: resolveDependsOn(spec.dependsOn),
|
|
1001
1005
|
}), { kind: "wsl-distro", distro: {
|
|
1002
1006
|
name, source: spec.source, installLocation: spec.installLocation, default: spec.default ?? false,
|
|
1007
|
+
...(spec.host === undefined ? {} : { host: spec.host }),
|
|
1003
1008
|
...(spec.setup === undefined ? {} : { setup: normalizeWslSetup(spec.setup) }),
|
|
1004
1009
|
} }));
|
|
1005
1010
|
},
|
package/dist/skill.js
CHANGED
|
@@ -310,13 +310,23 @@ Resources return handles that can be passed through \`dependsOn\`.
|
|
|
310
310
|
leaves the file untouched. The returned handle covers the complete setup.
|
|
311
311
|
If a reboot is needed, restart Windows manually and rerun switch.
|
|
312
312
|
It never shuts down WSL; restart WSL manually when configuration changes.
|
|
313
|
-
- \`windows.wsl.distro()\`
|
|
314
|
-
installLocation, optional default and dependsOn. Declare windows.wsl() in the
|
|
313
|
+
- \`windows.wsl.distro()\` creates or adopts a named distro with source "nixos-wsl",
|
|
314
|
+
installLocation, optional host, default and dependsOn. Declare windows.wsl() in the
|
|
315
315
|
same host; features, config, and runtime become
|
|
316
316
|
automatic dependencies.
|
|
317
317
|
Images for x64/ARM64 are verified against winix-windows.lock wslImages pins.
|
|
318
318
|
Update with winix update --windows nixos-wsl. Updates never reinstall an
|
|
319
|
-
existing distro.
|
|
319
|
+
existing distro. An untracked existing registration is automatically adopted
|
|
320
|
+
only if it is WSL 2, runs NixOS, and its Linux hostname matches host (defaults
|
|
321
|
+
to setup.host). An expected hostname is required for adoption, not creation.
|
|
322
|
+
No Git/user/checkout/config inspection. Mismatches fail without replacement.
|
|
323
|
+
Adoption preserves actual location and defaults, skips setup permanently, and
|
|
324
|
+
leaves Linux activation manual. Probing may start WSL but makes no Linux changes.
|
|
325
|
+
Local AppData Winix/wsl-registrations records GUID/location/adoption/hostname;
|
|
326
|
+
later runs reject changed or missing registrations and hostname mismatches.
|
|
327
|
+
Legacy Winix import markers retain their provisioning behavior.
|
|
328
|
+
check/dry are static only; creation pins may still resolve. Adoption is not
|
|
329
|
+
available in preview.3.
|
|
320
330
|
Removing a declaration never unregisters a distro or deletes its data.
|
|
321
331
|
Optional setup opts into trusted first-run Linux provisioning:
|
|
322
332
|
{ repository: "https://github.com/example/dotfiles.git", ref: "main",
|
|
@@ -378,8 +388,19 @@ are automatically uninstalled after successful activation; always preview
|
|
|
378
388
|
with \`winix switch --dry\`. Other recorded owners prevent removal.
|
|
379
389
|
Switches with package/startup removals prompt before activation; declining cancels
|
|
380
390
|
the entire switch. Use \`--yes\`/\`-y\` for automation; noninteractive runs with
|
|
381
|
-
removals require it. Dry runs
|
|
382
|
-
|
|
391
|
+
removals require it. Dry runs do not prompt.
|
|
392
|
+
Native Windows switch treats floating package locks as minimum versions/fresh
|
|
393
|
+
install targets: install missing, upgrade older, keep newer without downgrading.
|
|
394
|
+
Owned external upgrades retain ownership and refresh observed snapshots after
|
|
395
|
+
successful activation; pre-installed packages remain unowned. An inline version
|
|
396
|
+
is exact: existing mismatches fail explicitly before activation.
|
|
397
|
+
Unequal non-dotted-numeric versions cannot be ordered and require explicit
|
|
398
|
+
resolution. Interactive successful switches offer a separate [y/N] lock update
|
|
399
|
+
for newer floating packages. Declining continues; dry/noninteractive runs do not
|
|
400
|
+
update observed-version pins, and --yes does not accept lock-update prompts.
|
|
401
|
+
Plain apply/direct DSC scripts keep lock-based generation.
|
|
402
|
+
External shortcut edits, package downgrades and exact-pin drift still block
|
|
403
|
+
reconciliation; externally modified removals remain protected.
|
|
383
404
|
\`winix state forget startup <name>\` or
|
|
384
405
|
\`winix state forget package <winget|msstore> <id>\` releases removal ownership
|
|
385
406
|
without deleting the resource; --dry previews. Do not copy applied state to a
|
package/dist/types/windows.d.ts
CHANGED
|
@@ -35,8 +35,13 @@ export interface WinPowerShellRepositoryPolicy {
|
|
|
35
35
|
export interface WinWslDistro {
|
|
36
36
|
name: string;
|
|
37
37
|
source: "nixos-wsl";
|
|
38
|
+
/** Creation destination; an adopted distro keeps its registered location. */
|
|
38
39
|
installLocation: WinFilePath;
|
|
40
|
+
/** Default selection is managed only for Winix-created distros. */
|
|
39
41
|
default: boolean;
|
|
42
|
+
/** Expected Linux hostname for adoption; defaults to setup.host. */
|
|
43
|
+
host?: string;
|
|
44
|
+
/** First-run setup for Winix-created distros; never run for adopted distros. */
|
|
40
45
|
setup?: WinWslSetup;
|
|
41
46
|
}
|
|
42
47
|
export interface WinWslSetup {
|
package/package.json
CHANGED