@adrifer/winix 0.3.0-preview.3 → 0.3.0-preview.4
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 +40 -3
- 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/helpers/windows.d.ts +1 -0
- package/dist/helpers/windows.js +5 -0
- package/dist/skill.js +13 -3
- 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", {
|
|
@@ -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' }",
|
|
@@ -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",
|
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