@adrifer/winix 0.3.0-preview.1 → 0.3.0-preview.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -20
- package/dist/backends/windows/index.js +20 -29
- package/dist/backends/windows/lockfile.d.ts +3 -3
- package/dist/backends/windows/lockfile.js +16 -14
- package/dist/backends/windows/powershell.d.ts +1 -1
- package/dist/backends/windows/powershell.js +20 -9
- package/dist/backends/windows/wsl-setup.js +1 -1
- package/dist/backends/windows/wsl.d.ts +1 -1
- package/dist/backends/windows/wsl.js +22 -21
- package/dist/cli/commands/apply.js +3 -3
- package/dist/cli/commands/bootstrap.d.ts +1 -1
- package/dist/cli/commands/bootstrap.js +2 -7
- package/dist/cli/commands/switch.js +2 -3
- package/dist/cli/commands/update.js +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +29 -7
- package/dist/cli/loader.d.ts +1 -0
- package/dist/cli/loader.js +2 -2
- package/dist/cli/node.d.ts +1 -0
- package/dist/cli/node.js +8 -0
- package/dist/cli/windows-state.d.ts +11 -0
- package/dist/cli/windows-state.js +48 -2
- package/dist/helpers/windows-repositories.d.ts +2 -0
- package/dist/helpers/windows-repositories.js +4 -0
- package/dist/helpers/windows.d.ts +3 -0
- package/dist/helpers/windows.js +12 -2
- package/dist/skill.js +27 -5
- package/dist/types/windows.d.ts +2 -0
- package/package.json +6 -2
- package/scripts/bootstrap-linux.sh +2 -1
- package/scripts/bootstrap-windows.ps1 +10 -4
- package/scripts/winix.mjs +16 -0
package/README.md
CHANGED
|
@@ -147,6 +147,12 @@ activation and ARM64 execution are not yet verified.
|
|
|
147
147
|
|
|
148
148
|
### Bootstrap an existing repository
|
|
149
149
|
|
|
150
|
+
Repository-specific entry scripts can download/verify Winix bootstrap installers and supply
|
|
151
|
+
repository, ref, destination, config-directory and host defaults. Git installation,
|
|
152
|
+
cloning and existing-checkout validation remain owned by Winix. Private HTTPS
|
|
153
|
+
repositories use Git's configured authentication/credential helper; never embed
|
|
154
|
+
credentials in scripts or repository URLs.
|
|
155
|
+
|
|
150
156
|
The Winix-owned `bootstrap-windows.ps1` and `bootstrap-linux.sh` release assets
|
|
151
157
|
prepare a trusted config repository without Node/npm. Download the script and
|
|
152
158
|
its `.sha256` from a **versioned release supporting repository bootstrap**,
|
|
@@ -213,7 +219,7 @@ For ongoing use, bootstrap writes `.winix/bin/winix.ps1` (Windows) or
|
|
|
213
219
|
|
|
214
220
|
The launcher rereads the manifest on every invocation. If an optional
|
|
215
221
|
`node_modules/@adrifer/winix` is installed, its version must match the pin and
|
|
216
|
-
the launcher uses its own CLI/SDK under Node
|
|
222
|
+
the launcher uses its own CLI/SDK under supported Node 22.13+, 24 or 26. Install dependencies
|
|
217
223
|
explicitly with `npm ci` using an approved npm source; bootstrap never does it.
|
|
218
224
|
Existing `npm run` scripts also use that local CLI, without a global installation.
|
|
219
225
|
Without the npm SDK, the verified standalone executable must match the pin;
|
|
@@ -235,8 +241,12 @@ npx @adrifer/winix@latest init
|
|
|
235
241
|
npm install
|
|
236
242
|
```
|
|
237
243
|
|
|
238
|
-
The npm CLI
|
|
239
|
-
`--experimental-transform-types`
|
|
244
|
+
The npm CLI supports stable Node.js 22.13+ (22.x), 24.x and 26.x.
|
|
245
|
+
Its launcher enables `--experimental-transform-types` on Node 22/24 and omits
|
|
246
|
+
the removed flag on Node 26. Node 26 only supports erasable TypeScript: use Node
|
|
247
|
+
24 if your config or local imports contain enums, parameter properties or other
|
|
248
|
+
syntax requiring transformation. Odd-numbered and untested future majors are
|
|
249
|
+
rejected explicitly.
|
|
240
250
|
The standalone executable has no installed Node version requirement.
|
|
241
251
|
|
|
242
252
|
If you prefer to set up files yourself instead of using `init`, add the package to your own `package.json`:
|
|
@@ -589,13 +599,13 @@ modules:
|
|
|
589
599
|
|
|
590
600
|
```ts
|
|
591
601
|
host("desktop", platforms.windows(), ({ windows }) => {
|
|
592
|
-
|
|
602
|
+
windows.setting({ DeveloperMode: true });
|
|
593
603
|
const icons = windows.powershell.module("Terminal-Icons");
|
|
594
604
|
|
|
595
605
|
windows.file.symlink(
|
|
596
606
|
windows.knownFolder.documents("PowerShell\\Microsoft.PowerShell_profile.ps1"),
|
|
597
607
|
"../windows/powershell/Microsoft.PowerShell_profile.ps1",
|
|
598
|
-
{ backup: true, dependsOn:
|
|
608
|
+
{ backup: true, dependsOn: icons },
|
|
599
609
|
);
|
|
600
610
|
});
|
|
601
611
|
```
|
|
@@ -611,6 +621,11 @@ and require the checkout to remain in place. Existing backup/force protections
|
|
|
611
621
|
are unchanged. Direct `generateWindows(hosts, lock, configDir)` callers must
|
|
612
622
|
supply `configDir` when using relative sources.
|
|
613
623
|
|
|
624
|
+
Symlinks automatically depend on typed `windows.setting({ DeveloperMode: true })`
|
|
625
|
+
resources declared anywhere in the same host. Developer Mode remains an explicit
|
|
626
|
+
machine-policy choice: Winix does not enable it merely because a symlink exists.
|
|
627
|
+
Without that declaration, symlinks still require existing Developer Mode or elevation.
|
|
628
|
+
|
|
614
629
|
When generating in WSL, Winix uses `wslpath` to translate filesystem sources to
|
|
615
630
|
Windows drive/UNC paths. Sources inside the Linux filesystem use a WSL UNC path,
|
|
616
631
|
so that distribution must remain available during activation. Generation on
|
|
@@ -626,7 +641,7 @@ subsequent applies reuse pins without querying the repository.
|
|
|
626
641
|
only selected entries; `--dry` resolves without writing. Resolution errors never
|
|
627
642
|
replace existing pins. Network access is still needed for installation.
|
|
628
643
|
|
|
629
|
-
`windows.powershell.module(name, { repository?, dependsOn? })` defaults to
|
|
644
|
+
`windows.powershell.module(name, { repository?, prerelease?, dependsOn? })` defaults to
|
|
630
645
|
the host repository policy, otherwise PSGallery, selects stable releases, and installs the exact locked version for
|
|
631
646
|
the current user. PowerShell 7 with PSResourceGet must already be available for
|
|
632
647
|
resolution. Installation is idempotent and runs directly in DSC's
|
|
@@ -634,6 +649,17 @@ resolution. Installation is idempotent and runs directly in DSC's
|
|
|
634
649
|
automatic dependency. Other versions are not removed. Profiles still import
|
|
635
650
|
modules themselves; an unversioned `Import-Module` can load a newer installed
|
|
636
651
|
version, so installation locking alone does not enforce session imports.
|
|
652
|
+
Set `prerelease: true` to allow a prerelease pin; its full version, including
|
|
653
|
+
the prerelease label, is locked and checked. A shared module with any stable-only
|
|
654
|
+
declaration remains stable-only.
|
|
655
|
+
|
|
656
|
+
`windows.setting(...)` implicitly declares `Microsoft.Windows.Settings` through
|
|
657
|
+
this same mechanism, with prereleases allowed and the host's repository policy
|
|
658
|
+
enforced. First apply adds its exact source-qualified module pin; no version
|
|
659
|
+
belongs in handwritten configuration. A different installed version does not
|
|
660
|
+
satisfy that pin. Native Settings activation and adapted-resource discovery with
|
|
661
|
+
multiple side-by-side module versions remain unverified; installing the pin
|
|
662
|
+
does not claim to force DSC's module selection.
|
|
637
663
|
|
|
638
664
|
Work profiles can enforce an approved feed without changing shared features:
|
|
639
665
|
|
|
@@ -674,7 +700,6 @@ prerelease ensure behavior rather than adding a stable module lock.
|
|
|
674
700
|
|
|
675
701
|
```ts
|
|
676
702
|
host("DESKTOP", platforms.windows(), ({ windows }) => {
|
|
677
|
-
const runtime = windows.package("Microsoft.WSL");
|
|
678
703
|
const setup = windows.wsl({
|
|
679
704
|
config: {
|
|
680
705
|
wsl2: { memory: "16GB", processors: 8 },
|
|
@@ -686,13 +711,15 @@ host("DESKTOP", platforms.windows(), ({ windows }) => {
|
|
|
686
711
|
source: "nixos-wsl",
|
|
687
712
|
installLocation: "D:/WSL/NixOS",
|
|
688
713
|
default: true,
|
|
689
|
-
dependsOn:
|
|
714
|
+
dependsOn: setup,
|
|
690
715
|
});
|
|
691
716
|
});
|
|
692
717
|
```
|
|
693
718
|
|
|
694
|
-
`windows.wsl({ config?, backup?, force?, dependsOn? })`
|
|
695
|
-
Virtual Machine Platform Windows features and
|
|
719
|
+
`windows.wsl({ config?, backup?, force?, dependsOn? })` declares the `Microsoft.WSL`
|
|
720
|
+
package, enables the WSL and Virtual Machine Platform Windows features, and
|
|
721
|
+
optionally manages `.wslconfig`. The runtime uses normal package locking; a separate
|
|
722
|
+
`windows.package({ id: "Microsoft.WSL", ... })` can customize its package options.
|
|
696
723
|
Calling `windows.wsl()` without config leaves that file untouched.
|
|
697
724
|
`windows.optionalFeature(name,
|
|
698
725
|
{ enabled?, dependsOn? })` also supports individual optional features.
|
|
@@ -700,10 +727,10 @@ Feature changes require administrator approval. If a restart is required,
|
|
|
700
727
|
dependent provisioning stops: restart Windows yourself and rerun `winix switch`.
|
|
701
728
|
Winix never automatically restarts Windows or shuts down WSL.
|
|
702
729
|
|
|
703
|
-
Declare
|
|
730
|
+
Declare `windows.wsl()` in the same Windows host as its distros.
|
|
704
731
|
The distro automatically depends on the features, optional configuration file,
|
|
705
732
|
and runtime package; explicit `dependsOn` also supports other handles. The setup
|
|
706
|
-
handle covers
|
|
733
|
+
handle covers the runtime package, features, and configuration when provided. Registration runs
|
|
707
734
|
as the current Windows user, not SYSTEM;
|
|
708
735
|
use the intended account rather than another administrator's credentials.
|
|
709
736
|
`installLocation` accepts an absolute local-drive path, an environment-variable
|
|
@@ -811,20 +838,20 @@ Store policy. Run from a normal Windows account, not WSL or another admin accoun
|
|
|
811
838
|
|
|
812
839
|
```powershell
|
|
813
840
|
# Read-only: reports missing/old prerequisites and exits unsuccessfully if not ready.
|
|
814
|
-
powershell.exe -NoProfile -
|
|
841
|
+
powershell.exe -NoProfile -File .\scripts\bootstrap-windows.ps1 -Check
|
|
815
842
|
# Executable workflow: omit all Node/npm checks and installations.
|
|
816
|
-
powershell.exe -NoProfile -
|
|
817
|
-
powershell.exe -NoProfile -
|
|
843
|
+
powershell.exe -NoProfile -File .\scripts\bootstrap-windows.ps1 -Standalone -Check
|
|
844
|
+
powershell.exe -NoProfile -File .\scripts\bootstrap-windows.ps1 -Standalone
|
|
818
845
|
# Review and confirm installation/upgrade of missing or outdated prerequisites.
|
|
819
|
-
powershell.exe -NoProfile -
|
|
846
|
+
powershell.exe -NoProfile -File .\scripts\bootstrap-windows.ps1
|
|
820
847
|
# Choose NVM for Windows rather than standalone Node on NVM-based setups.
|
|
821
|
-
powershell.exe -NoProfile -
|
|
848
|
+
powershell.exe -NoProfile -File .\scripts\bootstrap-windows.ps1 -UseNvm
|
|
822
849
|
```
|
|
823
850
|
|
|
824
|
-
|
|
825
|
-
|
|
851
|
+
Run scripts only through an execution route permitted by your signing and
|
|
852
|
+
organizational policies; the bootstrap does not override them. `-Yes` accepts bootstrap
|
|
826
853
|
installation for automation. Installers may request UAC elevation. The script
|
|
827
|
-
checks Git, Node (22.13
|
|
854
|
+
checks Git, supported stable Node (22.13+/24/26), npm, PowerShell (7.4+), PSResourceGet/PSGallery, DSC
|
|
828
855
|
(3.2+), and the backend's required DSC resources. Supported existing versions
|
|
829
856
|
are kept; standalone installs use `Git.Git`, `OpenJS.NodeJS.LTS`,
|
|
830
857
|
`Microsoft.PowerShell`, and `Microsoft.DSC` from the exact WinGet source/IDs.
|
|
@@ -918,6 +945,23 @@ requirements across activations by the same Windows account.
|
|
|
918
945
|
Removing a host or moving a workspace does not automatically release its old
|
|
919
946
|
recorded requirements.
|
|
920
947
|
|
|
948
|
+
After moving a checkout or renaming a host, explicitly transfer the old owner's
|
|
949
|
+
requirements to the current config directory and new host:
|
|
950
|
+
|
|
951
|
+
```powershell
|
|
952
|
+
winix state owners
|
|
953
|
+
winix state migrate-owner <old-owner-id> --host new-host --dry
|
|
954
|
+
winix state migrate-owner <old-owner-id> --host new-host --yes
|
|
955
|
+
winix switch --host new-host --dry
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
Run migration from the new config checkout. It changes inventory
|
|
959
|
+
metadata only, never evaluates config or activates/deletes resources. Every
|
|
960
|
+
resource's snapshots and removal rights, including external/unowned status, are
|
|
961
|
+
preserved; other owners stay recorded. The next switch still enforces shared
|
|
962
|
+
requirements, drift checks and removal confirmation. Migration requires `--yes`
|
|
963
|
+
unless previewing with `--dry`; old owners are never discarded automatically.
|
|
964
|
+
|
|
921
965
|
When packages or startup shortcuts would be removed, `switch` lists them and asks
|
|
922
966
|
`Continue with switch? [y/N]` before activation. Declining or closing the prompt
|
|
923
967
|
cancels the whole switch without activation or cleanup. Switches without removals
|
|
@@ -938,6 +982,7 @@ winix state forget package winget Example.App
|
|
|
938
982
|
`state forget` preserves recorded requirements but releases ownership for that
|
|
939
983
|
resource across this user's inventory. If still declared, it remains required;
|
|
940
984
|
future creation or explicit shortcut replacement can grant ownership again.
|
|
985
|
+
It does not fix a stale owner identity; use explicit owner migration instead.
|
|
941
986
|
Package removal requires an exact installed-version match and uses exact ID,
|
|
942
987
|
source, and version selection.
|
|
943
988
|
|
|
@@ -31,7 +31,7 @@ import { emptyWindowsLock, reconcileInlinePins, windowsModulePin, } from "./lock
|
|
|
31
31
|
import { isWindowsHost } from "./host.js";
|
|
32
32
|
import { resolveWindowsFileProperties } from "../../helpers/windows.js";
|
|
33
33
|
import { powerShellModuleProperties, powerShellRepositoryScripts } from "./powershell.js";
|
|
34
|
-
import { powerShellRepositoryUri, resolvePowerShellModule, validateWindowsPowerShellPolicy } from "../../helpers/windows-repositories.js";
|
|
34
|
+
import { powerShellRepositoryUri, resolvePowerShellModule, validateWindowsPowerShellPolicy, windowsSettingsModule, } from "../../helpers/windows-repositories.js";
|
|
35
35
|
import { powerShellLiteral as psSingleQuoted } from "../../helpers/utils.js";
|
|
36
36
|
import { windowsSourcePath } from "./paths.js";
|
|
37
37
|
import { optionalFeatureProperties, wslDistroProperties } from "./wsl.js";
|
|
@@ -80,6 +80,9 @@ function generateConfiguration(hostName, win, lock, configDir) {
|
|
|
80
80
|
const repositoryDependencies = (repository) => registrations
|
|
81
81
|
.filter((entry) => entry.name.toLowerCase() === repository.toLowerCase())
|
|
82
82
|
.map((entry) => ({ kind: "dsc", token: entry.resource.token }));
|
|
83
|
+
const developerModeRefs = (win.dsc ?? [])
|
|
84
|
+
.filter((resource) => resource.winix?.kind === "setting" && resource.properties?.DeveloperMode === true)
|
|
85
|
+
.map((resource) => ({ kind: "dsc", token: resource.token }));
|
|
83
86
|
const resources = (win.dsc ?? []).map((resource) => {
|
|
84
87
|
const metadata = resource.winix;
|
|
85
88
|
if (metadata?.kind === "file") {
|
|
@@ -87,7 +90,9 @@ function generateConfiguration(hostName, win, lock, configDir) {
|
|
|
87
90
|
if (metadata.wslConfig && properties) {
|
|
88
91
|
properties.setScript += "\nWrite-Warning 'WSL configuration changed. Restart WSL manually when safe; Winix will not stop running distros.'";
|
|
89
92
|
}
|
|
90
|
-
return cloneDscResource(resource, properties
|
|
93
|
+
return cloneDscResource(resource, properties, metadata.action === "symlink"
|
|
94
|
+
? [...(resource.dependsOn ?? []), ...developerModeRefs]
|
|
95
|
+
: resource.dependsOn);
|
|
91
96
|
}
|
|
92
97
|
if (metadata?.kind === "optional-features") {
|
|
93
98
|
return cloneDscResource(resource, optionalFeatureProperties(metadata.names, metadata.enabled));
|
|
@@ -118,8 +123,10 @@ function generateConfiguration(hostName, win, lock, configDir) {
|
|
|
118
123
|
}
|
|
119
124
|
return resource;
|
|
120
125
|
});
|
|
121
|
-
const settingsModule =
|
|
122
|
-
const prepared = prepareWindowsDscResources(win.commands ?? [], resources, settingsModule
|
|
126
|
+
const settingsModule = windowsSettingsModule(win);
|
|
127
|
+
const prepared = prepareWindowsDscResources(win.commands ?? [], resources, settingsModule, lock, [...repositoryDependencies(settingsModule.repository),
|
|
128
|
+
...packages.filter((pkg) => pkg.id.toLowerCase() === "microsoft.powershell")
|
|
129
|
+
.map((pkg) => ({ kind: "package", id: pkg.id }))]);
|
|
123
130
|
const commands = prepared.commands;
|
|
124
131
|
const dscResources = [...registrations.map((entry) => entry.resource), ...prepared.dscResources];
|
|
125
132
|
const lines = [];
|
|
@@ -202,12 +209,15 @@ export function validateWindowsWslResources(win) {
|
|
|
202
209
|
throw new Error('WSL distro provisioning requires windows.package("Microsoft.WSL")');
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
|
-
function prepareWindowsDscResources(commands, resources,
|
|
212
|
+
function prepareWindowsDscResources(commands, resources, settingsModule, lock, repositoryDependencies) {
|
|
206
213
|
const envResolvedResources = resolveManagedEnvironmentReferences(resources);
|
|
207
214
|
if (!envResolvedResources.some((resource) => resource.winix?.kind === "setting")) {
|
|
208
215
|
return { commands: [...commands], dscResources: envResolvedResources };
|
|
209
216
|
}
|
|
210
|
-
const
|
|
217
|
+
const pin = windowsModulePin(lock, settingsModule);
|
|
218
|
+
if (!pin)
|
|
219
|
+
throw new Error('PowerShell module "Microsoft.Windows.Settings" has no matching pin in winix-windows.lock. Run winix update --windows.');
|
|
220
|
+
const ensureModule = createWindowsSettingsEnsureCommand(settingsModule, pin, repositoryDependencies);
|
|
211
221
|
const ensureRef = { kind: "dsc", token: ensureModule.token };
|
|
212
222
|
return {
|
|
213
223
|
commands: [...commands],
|
|
@@ -224,31 +234,12 @@ function prepareWindowsDscResources(commands, resources, settingsRepository, rep
|
|
|
224
234
|
],
|
|
225
235
|
};
|
|
226
236
|
}
|
|
227
|
-
function createWindowsSettingsEnsureCommand(
|
|
228
|
-
// Microsoft.Windows.Settings currently publishes the WindowsSettings resource
|
|
229
|
-
// as a prerelease module (the upstream sample uses v0.1.0-alpha), so the
|
|
230
|
-
// ensure step must opt into prerelease discovery for now. Revisit/remove
|
|
231
|
-
// -Prerelease once a stable module exists so future alphas are not preferred.
|
|
237
|
+
function createWindowsSettingsEnsureCommand(module, pin, dependsOn) {
|
|
232
238
|
const resource = {
|
|
233
239
|
name: WINDOWS_SETTINGS_MODULE_COMMAND_NAME,
|
|
234
|
-
resourceType:
|
|
240
|
+
resourceType: "Microsoft.DSC.Transitional/PowerShellScript",
|
|
235
241
|
dependsOn,
|
|
236
|
-
properties:
|
|
237
|
-
executable: "pwsh",
|
|
238
|
-
arguments: {
|
|
239
|
-
"0": "-NoProfile",
|
|
240
|
-
"1": "-NoLogo",
|
|
241
|
-
"2": "-Command",
|
|
242
|
-
"3": [
|
|
243
|
-
"$ErrorActionPreference = 'Stop';",
|
|
244
|
-
"if (-not (Get-Module -ListAvailable -Name Microsoft.Windows.Settings)) {",
|
|
245
|
-
` Install-PSResource -Name Microsoft.Windows.Settings -Repository ${psSingleQuoted(repository)} -Scope CurrentUser -Prerelease -TrustRepository -AcceptLicense -ErrorAction Stop | Out-Null;`,
|
|
246
|
-
" if (-not (Get-Module -ListAvailable -Name Microsoft.Windows.Settings)) { throw 'Microsoft.Windows.Settings was not installed' }",
|
|
247
|
-
"}",
|
|
248
|
-
].join(" "),
|
|
249
|
-
treatAsArray: true,
|
|
250
|
-
},
|
|
251
|
-
},
|
|
242
|
+
properties: powerShellModuleProperties(module, pin),
|
|
252
243
|
};
|
|
253
244
|
Object.defineProperty(resource, "token", {
|
|
254
245
|
value: Symbol("winix.windows-settings-module"),
|
|
@@ -502,7 +493,7 @@ function resolveDependsOnRefs(refs, naming) {
|
|
|
502
493
|
}
|
|
503
494
|
ids.push(target.name);
|
|
504
495
|
}
|
|
505
|
-
return ids;
|
|
496
|
+
return [...new Set(ids)];
|
|
506
497
|
}
|
|
507
498
|
/**
|
|
508
499
|
* Render one package as a DSC v3 `Microsoft.WinGet/Package` resource.
|
|
@@ -33,7 +33,7 @@ export interface WindowsLockModule {
|
|
|
33
33
|
version: string;
|
|
34
34
|
resolvedAt: string;
|
|
35
35
|
}
|
|
36
|
-
export type WindowsModuleVersionResolver = (name: string, repository: string, repositoryUri?: string) => string;
|
|
36
|
+
export type WindowsModuleVersionResolver = (name: string, repository: string, repositoryUri?: string, prerelease?: boolean) => string;
|
|
37
37
|
export declare function windowsModuleKey(module: ResolvedPowerShellModule): string;
|
|
38
38
|
export declare function windowsModulePin(lock: WindowsLock, module: ResolvedPowerShellModule): WindowsLockModule | undefined;
|
|
39
39
|
export type WindowsPackageVersionResolver = (id: string, source: WinPackageSource) => string;
|
|
@@ -59,10 +59,10 @@ export declare function windowsLockChanged(before: WindowsLock, after: WindowsLo
|
|
|
59
59
|
export declare function serializeWindowsLock(lock: WindowsLock): string;
|
|
60
60
|
export declare function collectWindowsModules(hosts: EvaluatedHost[]): Map<string, ResolvedPowerShellModule>;
|
|
61
61
|
export declare function hasWindowsWslDistros(hosts: EvaluatedHost[]): boolean;
|
|
62
|
-
export declare function resolveWindowsWslImages(lock: WindowsLock, resolve: WindowsWslImageResolver, now?: Date, missingOnly?: boolean): {
|
|
62
|
+
export declare function resolveWindowsWslImages(lock: WindowsLock, resolve: WindowsWslImageResolver, now?: Date, missingOnly?: boolean): Promise<{
|
|
63
63
|
lock: WindowsLock;
|
|
64
64
|
changed: boolean;
|
|
65
|
-
}
|
|
65
|
+
}>;
|
|
66
66
|
export declare function resolveWindowsWslRepositories(lock: WindowsLock, hosts: EvaluatedHost[], resolve: WindowsWslRepositoryResolver, now?: Date, missingOnly?: boolean): {
|
|
67
67
|
lock: WindowsLock;
|
|
68
68
|
changed: boolean;
|
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { validWslImage } from "./wsl.js";
|
|
5
5
|
import { validWslRepository, wslRepositoryKey, } from "./wsl-setup.js";
|
|
6
|
-
import { resolvePowerShellModule, powerShellRepositoryUri, } from "../../helpers/windows-repositories.js";
|
|
6
|
+
import { resolvePowerShellModule, powerShellRepositoryUri, powerShellModuleVersion, windowsSettingsModule, } from "../../helpers/windows-repositories.js";
|
|
7
7
|
export const WINDOWS_LOCKFILE_NAME = "winix-windows.lock";
|
|
8
8
|
export const WINDOWS_LOCK_VERSION = 1;
|
|
9
9
|
export function windowsModuleKey(module) {
|
|
@@ -19,7 +19,8 @@ export function windowsModulePin(lock, module) {
|
|
|
19
19
|
const pin = lock.modules?.[windowsModuleKey(module)] ??
|
|
20
20
|
(!module.repositoryUri ? lock.modules?.[module.name.toLowerCase()] : undefined);
|
|
21
21
|
if (pin?.repository.toLowerCase() !== module.repository.toLowerCase() ||
|
|
22
|
-
pin?.repositoryUri !== module.repositoryUri
|
|
22
|
+
pin?.repositoryUri !== module.repositoryUri ||
|
|
23
|
+
(!module.prerelease && pin.version.includes("-")))
|
|
23
24
|
return undefined;
|
|
24
25
|
return pin;
|
|
25
26
|
}
|
|
@@ -183,17 +184,18 @@ export function collectWindowsModules(hosts) {
|
|
|
183
184
|
for (const host of hosts) {
|
|
184
185
|
const win = host.windows;
|
|
185
186
|
const hostModules = new Map();
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
const declared = (win.dsc ?? []).flatMap((resource) => resource.winix?.kind === "powershell-module" ? [resolvePowerShellModule(win, resource.winix.module)] : []);
|
|
188
|
+
if (win.dsc?.some((resource) => resource.winix?.kind === "setting"))
|
|
189
|
+
declared.push(windowsSettingsModule(win));
|
|
190
|
+
for (const module of declared) {
|
|
190
191
|
const key = windowsModuleKey(module);
|
|
191
192
|
const existing = hostModules.get(module.name.toLowerCase());
|
|
192
193
|
if (existing && existing !== key) {
|
|
193
194
|
throw new Error(`PowerShell module "${module.name}" is declared with conflicting repositories.`);
|
|
194
195
|
}
|
|
195
196
|
hostModules.set(module.name.toLowerCase(), key);
|
|
196
|
-
modules.
|
|
197
|
+
const previous = modules.get(key);
|
|
198
|
+
modules.set(key, previous ? { ...module, prerelease: !!previous.prerelease && !!module.prerelease } : module);
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
201
|
return modules;
|
|
@@ -201,14 +203,14 @@ export function collectWindowsModules(hosts) {
|
|
|
201
203
|
export function hasWindowsWslDistros(hosts) {
|
|
202
204
|
return hosts.some((host) => host.windows.dsc?.some((resource) => resource.winix?.kind === "wsl-distro"));
|
|
203
205
|
}
|
|
204
|
-
export function resolveWindowsWslImages(lock, resolve, now = new Date(), missingOnly = false) {
|
|
206
|
+
export async function resolveWindowsWslImages(lock, resolve, now = new Date(), missingOnly = false) {
|
|
205
207
|
const images = { ...lock.wslImages };
|
|
206
208
|
let changed = false;
|
|
207
209
|
for (const architecture of ["x64", "arm64"]) {
|
|
208
210
|
const key = `nixos-wsl/${architecture}`;
|
|
209
211
|
if (missingOnly && images[key])
|
|
210
212
|
continue;
|
|
211
|
-
const image = { ...resolve(architecture), resolvedAt: now.toISOString() };
|
|
213
|
+
const image = { ...await resolve(architecture), resolvedAt: now.toISOString() };
|
|
212
214
|
if (!validWslImage(image) || image.architecture !== architecture) {
|
|
213
215
|
throw new Error(`Invalid NixOS-WSL image resolution for ${architecture}`);
|
|
214
216
|
}
|
|
@@ -262,9 +264,9 @@ export function resolveWindowsModuleLockEntries(lock, modules, resolveVersion, n
|
|
|
262
264
|
if (missingOnly && previous) {
|
|
263
265
|
continue;
|
|
264
266
|
}
|
|
265
|
-
const version = resolveVersion(module.name, module.repository, module.repositoryUri);
|
|
266
|
-
if (
|
|
267
|
-
throw new Error(`PowerShell module "${module.name}" resolver did not return
|
|
267
|
+
const version = resolveVersion(module.name, module.repository, module.repositoryUri, !!module.prerelease);
|
|
268
|
+
if (!powerShellModuleVersion.test(version) || (!module.prerelease && version.includes("-"))) {
|
|
269
|
+
throw new Error(`PowerShell module "${module.name}" resolver did not return an allowed version: ${version}`);
|
|
268
270
|
}
|
|
269
271
|
const unchanged = previous?.version === version &&
|
|
270
272
|
previous.repository.toLowerCase() === module.repository.toLowerCase();
|
|
@@ -335,9 +337,9 @@ function validateWindowsLock(value) {
|
|
|
335
337
|
for (const [name, entry] of Object.entries(value.modules)) {
|
|
336
338
|
if (!/^[a-z0-9][a-z0-9._-]*(?:@[a-z0-9][a-z0-9._-]*(?:\/[a-f0-9]{64})?)?$/i.test(name) || !isObject(entry) ||
|
|
337
339
|
typeof entry.repository !== "string" || !/^[a-z0-9][a-z0-9._-]*$/i.test(entry.repository) ||
|
|
338
|
-
typeof entry.version !== "string" ||
|
|
340
|
+
typeof entry.version !== "string" || !powerShellModuleVersion.test(entry.version) ||
|
|
339
341
|
typeof entry.resolvedAt !== "string") {
|
|
340
|
-
throw new Error(`${WINDOWS_LOCKFILE_NAME} module "${name}" has an invalid repository,
|
|
342
|
+
throw new Error(`${WINDOWS_LOCKFILE_NAME} module "${name}" has an invalid repository, version, or resolvedAt.`);
|
|
341
343
|
}
|
|
342
344
|
if (entry.repositoryUri !== undefined &&
|
|
343
345
|
(typeof entry.repositoryUri !== "string" || powerShellRepositoryUri(entry.repositoryUri) !== entry.repositoryUri)) {
|
|
@@ -7,5 +7,5 @@ export declare function powerShellRepositoryScripts(name: string, uri: string):
|
|
|
7
7
|
};
|
|
8
8
|
export type PowerShellGalleryRunner = (script: string) => string;
|
|
9
9
|
/** Find-PSResource returns the newest stable release unless -Prerelease is requested. */
|
|
10
|
-
export declare function resolvePowerShellModuleVersion(name: string, repository: string, repositoryUriOrRunner?: string | PowerShellGalleryRunner, runner?: PowerShellGalleryRunner): string;
|
|
10
|
+
export declare function resolvePowerShellModuleVersion(name: string, repository: string, repositoryUriOrRunner?: string | PowerShellGalleryRunner, prereleaseOrRunner?: boolean | PowerShellGalleryRunner, runner?: PowerShellGalleryRunner): string;
|
|
11
11
|
export declare function powerShellModuleProperties(module: WinPowerShellModule, pin: WindowsLockModule): WinDscProperties;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { powerShellLiteral } from "../../helpers/utils.js";
|
|
3
|
+
import { powerShellModuleVersion } from "../../helpers/windows-repositories.js";
|
|
3
4
|
export function powerShellRepositoryScripts(name, uri) {
|
|
4
5
|
const prelude = [
|
|
5
6
|
"$ErrorActionPreference = 'Stop'",
|
|
@@ -18,21 +19,25 @@ export function powerShellRepositoryScripts(name, uri) {
|
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
/** Find-PSResource returns the newest stable release unless -Prerelease is requested. */
|
|
21
|
-
export function resolvePowerShellModuleVersion(name, repository, repositoryUriOrRunner, runner) {
|
|
22
|
+
export function resolvePowerShellModuleVersion(name, repository, repositoryUriOrRunner, prereleaseOrRunner = false, runner) {
|
|
22
23
|
const repositoryUri = typeof repositoryUriOrRunner === "string" ? repositoryUriOrRunner : undefined;
|
|
23
|
-
const
|
|
24
|
+
const prerelease = prereleaseOrRunner === true;
|
|
25
|
+
const run = (typeof repositoryUriOrRunner === "function" ? repositoryUriOrRunner :
|
|
26
|
+
typeof prereleaseOrRunner === "function" ? prereleaseOrRunner : runner) ??
|
|
24
27
|
((script) => execFileSync("pwsh", ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", encode(script)], { encoding: "utf8" }));
|
|
25
28
|
const script = [
|
|
26
29
|
"$ErrorActionPreference = 'Stop'",
|
|
27
30
|
...(repositoryUri ? [powerShellRepositoryScripts(repository, repositoryUri).set] : []),
|
|
28
|
-
`$found = @(Find-PSResource -Name ${powerShellLiteral(name)} -Repository ${powerShellLiteral(repository)} -ErrorAction Stop)`,
|
|
29
|
-
`if ($found.Count -ne 1 -or $found[0].Name -ine ${powerShellLiteral(name)} -or $found[0].Prerelease) { throw 'Expected one
|
|
30
|
-
"$found[0].Version.ToString()
|
|
31
|
+
`$found = @(Find-PSResource -Name ${powerShellLiteral(name)} -Repository ${powerShellLiteral(repository)}${prerelease ? " -Prerelease" : ""} -ErrorAction Stop)`,
|
|
32
|
+
`if ($found.Count -ne 1 -or $found[0].Name -ine ${powerShellLiteral(name)}${prerelease ? "" : " -or $found[0].Prerelease"}) { throw 'Expected one matching module release' }`,
|
|
33
|
+
"$version = $found[0].Version.ToString()",
|
|
34
|
+
"if ($found[0].Prerelease) { $version += '-' + $found[0].Prerelease }",
|
|
35
|
+
"$version | ConvertTo-Json -Compress",
|
|
31
36
|
].join("\n");
|
|
32
37
|
try {
|
|
33
38
|
const version = JSON.parse(run(script).trim());
|
|
34
|
-
if (typeof version !== "string" ||
|
|
35
|
-
throw new Error("Repository did not return
|
|
39
|
+
if (typeof version !== "string" || !powerShellModuleVersion.test(version) || (!prerelease && version.includes("-"))) {
|
|
40
|
+
throw new Error("Repository did not return an allowed module version");
|
|
36
41
|
}
|
|
37
42
|
return version;
|
|
38
43
|
}
|
|
@@ -46,11 +51,17 @@ function encode(script) {
|
|
|
46
51
|
return Buffer.from(script, "utf16le").toString("base64");
|
|
47
52
|
}
|
|
48
53
|
export function powerShellModuleProperties(module, pin) {
|
|
54
|
+
if (!powerShellModuleVersion.test(pin.version) || (!module.prerelease && pin.version.includes("-"))) {
|
|
55
|
+
throw new Error(`Module ${module.name} has an invalid or disallowed version pin`);
|
|
56
|
+
}
|
|
57
|
+
const [version, prerelease = ""] = pin.version.split(/-(.*)/s);
|
|
49
58
|
const variables = [
|
|
50
59
|
`$name = ${powerShellLiteral(module.name)}`,
|
|
51
60
|
`$version = ${powerShellLiteral(pin.version)}`,
|
|
61
|
+
`$baseVersion = ${powerShellLiteral(version)}`,
|
|
62
|
+
`$prerelease = ${powerShellLiteral(prerelease)}`,
|
|
52
63
|
];
|
|
53
|
-
const present = "@(Get-Module -ListAvailable -Name $name | Where-Object { $_.Version -eq [version]$
|
|
64
|
+
const present = "@(Get-Module -ListAvailable -Name $name | Where-Object { $_.Version -eq [version]$baseVersion -and [string]$_.PrivateData.PSData.Prerelease -ceq $prerelease }).Count -gt 0";
|
|
54
65
|
const prelude = [
|
|
55
66
|
"$ErrorActionPreference = 'Stop'",
|
|
56
67
|
"if ($PSVersionTable.PSVersion.Major -lt 7) { throw 'PowerShell 7 is required' }",
|
|
@@ -65,7 +76,7 @@ export function powerShellModuleProperties(module, pin) {
|
|
|
65
76
|
setScript: [
|
|
66
77
|
...prelude,
|
|
67
78
|
`if (${present}) { return }`,
|
|
68
|
-
`Install-PSResource -Name $name -Version $version -Repository ${powerShellLiteral(pin.repository)} -Scope CurrentUser -TrustRepository -AcceptLicense -Reinstall -ErrorAction Stop | Out-Null`,
|
|
79
|
+
`Install-PSResource -Name $name -Version $version -Repository ${powerShellLiteral(pin.repository)}${prerelease ? " -Prerelease" : ""} -Scope CurrentUser -TrustRepository -AcceptLicense -Reinstall -ErrorAction Stop | Out-Null`,
|
|
69
80
|
`if (-not (${present})) { throw "Module $name $version was not installed" }`,
|
|
70
81
|
].join("\n"),
|
|
71
82
|
};
|
|
@@ -99,7 +99,7 @@ export function wslSetupPrelude(setup, pin) {
|
|
|
99
99
|
const extension = import.meta.url.endsWith(".ts") ? "ts" : "js";
|
|
100
100
|
const source = readFileSync(new URL(`./wsl-setup-runtime.${extension}`, import.meta.url), "utf8");
|
|
101
101
|
const runtime = extension === "ts"
|
|
102
|
-
? createRequire(import.meta.url)("node:module").stripTypeScriptTypes(source, { mode: "
|
|
102
|
+
? createRequire(import.meta.url)("node:module").stripTypeScriptTypes(source, { mode: "strip" })
|
|
103
103
|
: source;
|
|
104
104
|
launch = [
|
|
105
105
|
`export WINIX_WSL_SETUP_RUNTIME='${Buffer.from(runtime + "\nawait dispatchWslSetup();\n").toString("base64")}'`,
|
|
@@ -2,7 +2,7 @@ import type { WinDscProperties, WinWslDistro } from "../../types/index.js";
|
|
|
2
2
|
import type { WindowsLockWslImage } from "./lockfile.js";
|
|
3
3
|
import { type WindowsLockWslRepository } from "./wsl-setup.js";
|
|
4
4
|
export type WslArchitecture = "x64" | "arm64";
|
|
5
|
-
export type WindowsWslImageResolver = (architecture: WslArchitecture) => Omit<WindowsLockWslImage, "resolvedAt"
|
|
5
|
+
export type WindowsWslImageResolver = (architecture: WslArchitecture) => Omit<WindowsLockWslImage, "resolvedAt"> | Promise<Omit<WindowsLockWslImage, "resolvedAt">>;
|
|
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;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
1
|
import { filePathExpression, filePathPrelude } from "../../helpers/windows.js";
|
|
3
2
|
import { powerShellLiteral as ps } from "../../helpers/utils.js";
|
|
4
3
|
import { wslRepositoryKey, wslSetupPrelude } from "./wsl-setup.js";
|
|
@@ -14,32 +13,34 @@ export function validWslImage(value) {
|
|
|
14
13
|
const asset = entry.architecture === "x64" ? "nixos.wsl" : "nixos.aarch64.wsl";
|
|
15
14
|
return entry.url === `https://github.com/nix-community/NixOS-WSL/releases/download/${entry.version}/${asset}`;
|
|
16
15
|
}
|
|
17
|
-
export const resolveNixosWslImage = (architecture) => {
|
|
16
|
+
export const resolveNixosWslImage = async (architecture) => {
|
|
18
17
|
const assetName = architecture === "x64" ? "nixos.wsl" : "nixos.aarch64.wsl";
|
|
19
|
-
const script = `
|
|
20
18
|
const response = await fetch("https://api.github.com/repos/nix-community/NixOS-WSL/releases/latest", {
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
headers: { Accept: "application/vnd.github+json", "User-Agent": "Winix" },
|
|
20
|
+
signal: AbortSignal.timeout(30000),
|
|
23
21
|
});
|
|
24
|
-
if (!response.ok)
|
|
22
|
+
if (!response.ok)
|
|
23
|
+
throw new Error(`NixOS-WSL release lookup failed: HTTP ${response.status}`);
|
|
25
24
|
const release = await response.json();
|
|
26
|
-
if (release
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
if (!release || typeof release !== "object" || !("draft" in release) || release.draft !== false ||
|
|
26
|
+
!("prerelease" in release) || release.prerelease !== false) {
|
|
27
|
+
throw new Error("Expected a stable NixOS-WSL release");
|
|
28
|
+
}
|
|
29
|
+
const asset = "assets" in release && Array.isArray(release.assets)
|
|
30
|
+
? release.assets.find((entry) => !!entry && typeof entry === "object" && "name" in entry && entry.name === assetName)
|
|
31
|
+
: undefined;
|
|
32
|
+
if (!asset || typeof asset.digest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(asset.digest)) {
|
|
33
|
+
throw new Error("Release asset lacks a SHA256 digest");
|
|
34
|
+
}
|
|
35
|
+
const image = {
|
|
36
|
+
source: "nixos-wsl", architecture,
|
|
37
|
+
version: "tag_name" in release ? release.tag_name : undefined,
|
|
38
|
+
url: asset.browser_download_url, sha256: asset.digest.slice(7), resolvedAt: "",
|
|
39
|
+
};
|
|
40
|
+
if (!validWslImage(image)) {
|
|
38
41
|
throw new Error("Invalid official NixOS-WSL release image");
|
|
39
42
|
}
|
|
40
|
-
const validated = image;
|
|
41
|
-
if (validated.architecture !== architecture)
|
|
42
|
-
throw new Error("NixOS-WSL image architecture mismatch");
|
|
43
|
+
const { resolvedAt: _, ...validated } = image;
|
|
43
44
|
return validated;
|
|
44
45
|
};
|
|
45
46
|
export function optionalFeatureProperties(names, enabled) {
|
|
@@ -29,7 +29,7 @@ export async function applyWorkspace(cwd, opts) {
|
|
|
29
29
|
for (const host of windowsHosts)
|
|
30
30
|
validateWindowsWslResources(host.windows);
|
|
31
31
|
const windowsLock = windowsHosts.length > 0
|
|
32
|
-
? prepareWindowsLock(configDir, windowsHosts, opts.dry || opts.windowsLockDry === true, opts.resolveWindowsPackageVersion ?? resolveWingetVersion, opts.resolveWindowsModuleVersion ?? resolvePowerShellModuleVersion, opts.resolveWindowsWslImage ?? resolveNixosWslImage, opts.resolveWindowsWslRepository ?? resolveWslRepository)
|
|
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
35
|
const windowsOutput = windowsHosts.length > 0
|
|
@@ -85,14 +85,14 @@ export async function applyWorkspace(cwd, opts) {
|
|
|
85
85
|
export async function apply(cwd, opts) {
|
|
86
86
|
await applyWorkspace(cwd, opts);
|
|
87
87
|
}
|
|
88
|
-
function prepareWindowsLock(configDir, windowsHosts, dry, resolveVersion, resolveModuleVersion, resolveWslImage, resolveRepository) {
|
|
88
|
+
async function prepareWindowsLock(configDir, windowsHosts, dry, resolveVersion, resolveModuleVersion, resolveWslImage, resolveRepository) {
|
|
89
89
|
const now = new Date();
|
|
90
90
|
const lock = readWindowsLock(configDir) ?? emptyWindowsLock(now);
|
|
91
91
|
const reconciled = reconcileInlinePins(lock, windowsHosts, now);
|
|
92
92
|
const resolved = resolveMissingWindowsLockEntries(reconciled, windowsHosts, resolveVersion, now);
|
|
93
93
|
const modules = resolveWindowsModuleLockEntries(resolved.lock, collectWindowsModules(windowsHosts).values(), resolveModuleVersion, now, true);
|
|
94
94
|
const images = hasWindowsWslDistros(windowsHosts)
|
|
95
|
-
? resolveWindowsWslImages(modules.lock, resolveWslImage, now, true)
|
|
95
|
+
? await resolveWindowsWslImages(modules.lock, resolveWslImage, now, true)
|
|
96
96
|
: { lock: modules.lock, changed: false };
|
|
97
97
|
const repositories = resolveWindowsWslRepositories(images.lock, windowsHosts, resolveRepository, now, true);
|
|
98
98
|
const changed = windowsLockChanged(lock, repositories.lock);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { runCommand } from "../run.js";
|
|
2
|
+
export { nodeTypeArguments } from "../node.js";
|
|
2
3
|
export declare function pinnedWinixVersion(spec: unknown): string;
|
|
3
4
|
export declare function checkoutWinixVersion(directory: string): Promise<string>;
|
|
4
5
|
export declare function localWinixCommand(directory: string, expected: string, runtimeVersion: string, executable: string): Promise<{
|
|
@@ -6,7 +7,6 @@ export declare function localWinixCommand(directory: string, expected: string, r
|
|
|
6
7
|
args: string[];
|
|
7
8
|
}>;
|
|
8
9
|
export declare function runCheckout(directory: string, args: string[], run?: typeof runCommand): Promise<void>;
|
|
9
|
-
export declare function nodeTypeArguments(version: string): string[];
|
|
10
10
|
export declare function bootstrapCheckout(directory: string, opts: {
|
|
11
11
|
host: string;
|
|
12
12
|
yes: boolean;
|
|
@@ -7,6 +7,8 @@ import { execFileSync } from "node:child_process";
|
|
|
7
7
|
import { standaloneRuntime } from "../../runtime.js";
|
|
8
8
|
import { resolveWinixVersionRange } from "./init.js";
|
|
9
9
|
import { runCommand } from "../run.js";
|
|
10
|
+
import { nodeTypeArguments } from "../node.js";
|
|
11
|
+
export { nodeTypeArguments } from "../node.js";
|
|
10
12
|
export function pinnedWinixVersion(spec) {
|
|
11
13
|
if (typeof spec !== "string")
|
|
12
14
|
throw new Error("package.json must declare an exact @adrifer/winix dependency");
|
|
@@ -77,13 +79,6 @@ export async function runCheckout(directory, args, run = runCommand) {
|
|
|
77
79
|
}
|
|
78
80
|
await run(command.command, [...command.args, ...args], { cwd: directory });
|
|
79
81
|
}
|
|
80
|
-
export function nodeTypeArguments(version) {
|
|
81
|
-
const parsed = /^v?(\d+)\.(\d+)\.\d+$/.exec(version);
|
|
82
|
-
if (!parsed || Number(parsed[1]) < 22 || Number(parsed[1]) === 22 && Number(parsed[2]) < 13) {
|
|
83
|
-
throw new Error(`Local SDK requires stable Node >=22.13, found ${version}. Install it explicitly or remove the optional node_modules SDK to retain standalone mode.`);
|
|
84
|
-
}
|
|
85
|
-
return Number(parsed[1]) >= 26 ? [] : ["--experimental-transform-types"];
|
|
86
|
-
}
|
|
87
82
|
async function confirm(message, yes) {
|
|
88
83
|
if (yes)
|
|
89
84
|
return;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { hostname } from "node:os";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { realpath } from "node:fs/promises";
|
|
4
3
|
import { createHash } from "node:crypto";
|
|
5
|
-
import { managedWindowsResources, nativeWindowsStateAdapter, reconcileWindows, resourceKey, windowsStatePath, withWindowsStateLock, } from "../windows-state.js";
|
|
4
|
+
import { managedWindowsResources, nativeWindowsStateAdapter, reconcileWindows, resourceKey, windowsStatePath, windowsStateOwner, withWindowsStateLock, } from "../windows-state.js";
|
|
6
5
|
import { evaluate } from "../../evaluator/index.js";
|
|
7
6
|
import { loadWorkspace } from "../loader.js";
|
|
8
7
|
import { runCommand } from "../run.js";
|
|
@@ -49,7 +48,7 @@ export async function switchCommand(cwd, opts) {
|
|
|
49
48
|
}
|
|
50
49
|
await reconcileWindows({
|
|
51
50
|
statePath,
|
|
52
|
-
owner:
|
|
51
|
+
owner: await windowsStateOwner(configDir, hostName),
|
|
53
52
|
desired, definitions,
|
|
54
53
|
dry: opts.dry,
|
|
55
54
|
yes: opts.yes,
|
|
@@ -105,7 +105,7 @@ async function updateWindowsLock(cwd, opts) {
|
|
|
105
105
|
lock = resolvedModules.lock;
|
|
106
106
|
changed = changed || resolvedModules.changed;
|
|
107
107
|
if (wslImages && (opts.inputs.length === 0 || opts.inputs.includes("nixos-wsl"))) {
|
|
108
|
-
const images = resolveWindowsWslImages(lock, opts.resolveWindowsWslImage ?? resolveNixosWslImage, now);
|
|
108
|
+
const images = await resolveWindowsWslImages(lock, opts.resolveWindowsWslImage ?? resolveNixosWslImage, now);
|
|
109
109
|
lock = images.lock;
|
|
110
110
|
changed = changed || images.changed;
|
|
111
111
|
console.log(` ${images.changed ? "resolved" : "up to date"} NixOS-WSL images (existing distros will not be reinstalled)`);
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
export {};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
// Winix CLI entry point
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
+
import { dirname } from "node:path";
|
|
4
5
|
import { apply } from "./commands/apply.js";
|
|
5
6
|
import { check } from "./commands/check.js";
|
|
6
7
|
import { init, resolveWinixVersionRange } from "./commands/init.js";
|
|
@@ -10,7 +11,8 @@ import { switchCommand } from "./commands/switch.js";
|
|
|
10
11
|
import { update } from "./commands/update.js";
|
|
11
12
|
import { renderSkill } from "../skill.js";
|
|
12
13
|
import { bootstrapCheckout, runCheckout } from "./commands/bootstrap.js";
|
|
13
|
-
import { forgetWindowsResource, windowsStatePath } from "./windows-state.js";
|
|
14
|
+
import { forgetWindowsResource, windowsStatePath, listWindowsOwners, migrateWindowsOwner, windowsStateOwner, } from "./windows-state.js";
|
|
15
|
+
import { findConfig } from "./loader.js";
|
|
14
16
|
if (process.argv[2] === "run") {
|
|
15
17
|
try {
|
|
16
18
|
await runCheckout(process.cwd(), process.argv.slice(3));
|
|
@@ -66,12 +68,14 @@ Commands:
|
|
|
66
68
|
update Update generated flake.lock and copy it to project root
|
|
67
69
|
inspect Print host composition and fragment graph
|
|
68
70
|
state forget Release Windows removal ownership without deleting a resource
|
|
71
|
+
state owners List Windows applied-state owners and their migration IDs
|
|
72
|
+
state migrate-owner <id> Transfer an old owner's requirements to this checkout/--host
|
|
69
73
|
|
|
70
74
|
Options:
|
|
71
75
|
--host <name> Target a specific host
|
|
72
76
|
--prepare-only Stop bootstrap after validation/preview; no activation
|
|
73
|
-
--dry Preview generation
|
|
74
|
-
-y, --yes Confirm managed
|
|
77
|
+
--dry Preview generation, activation/cleanup, or owner migration
|
|
78
|
+
-y, --yes Confirm bootstrap, managed removals, or explicit owner migration
|
|
75
79
|
--diff Show diff against current output (apply)
|
|
76
80
|
--windows Resolve Windows package/module/WSL image lockfile (update)
|
|
77
81
|
--strict Treat conflicts as errors (check)
|
|
@@ -100,8 +104,9 @@ if (values["prepare-only"] && command !== "bootstrap") {
|
|
|
100
104
|
console.error("--prepare-only is only supported by winix bootstrap.");
|
|
101
105
|
process.exit(2);
|
|
102
106
|
}
|
|
103
|
-
if (values.yes && command !== "switch" && command !== "bootstrap"
|
|
104
|
-
|
|
107
|
+
if (values.yes && command !== "switch" && command !== "bootstrap" &&
|
|
108
|
+
!(command === "state" && positionals[1] === "migrate-owner")) {
|
|
109
|
+
console.error("--yes is only supported by winix switch, bootstrap or state migrate-owner.");
|
|
105
110
|
process.exit(2);
|
|
106
111
|
}
|
|
107
112
|
switch (command) {
|
|
@@ -199,6 +204,23 @@ switch (command) {
|
|
|
199
204
|
try {
|
|
200
205
|
if (process.platform !== "win32")
|
|
201
206
|
throw new Error("Windows applied state is only available on native Windows.");
|
|
207
|
+
if (positionals[1] === "owners" && positionals.length === 2) {
|
|
208
|
+
const owners = await listWindowsOwners(windowsStatePath());
|
|
209
|
+
for (const entry of owners)
|
|
210
|
+
console.log(`${entry.id} ${entry.owner} (${entry.resources} resource(s))`);
|
|
211
|
+
if (!owners.length)
|
|
212
|
+
console.log("No recorded Windows owners.");
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
if (positionals[1] === "migrate-owner" && positionals.length === 3) {
|
|
216
|
+
if (!values.host)
|
|
217
|
+
throw new Error("Owner migration requires --host <new-declared-host>");
|
|
218
|
+
const config = findConfig(cwd);
|
|
219
|
+
if (!config)
|
|
220
|
+
throw new Error("Run owner migration from the new Winix config checkout.");
|
|
221
|
+
await migrateWindowsOwner(windowsStatePath(), positionals[2], await windowsStateOwner(dirname(config), values.host), { dry: values.dry, yes: values.yes });
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
202
224
|
let resource;
|
|
203
225
|
if (positionals[1] === "forget" && positionals[2] === "startup" && positionals.length === 4) {
|
|
204
226
|
resource = { kind: "startup", name: positionals[3] };
|
|
@@ -208,7 +230,7 @@ switch (command) {
|
|
|
208
230
|
resource = { kind: "package", source: positionals[3], id: positionals[4] };
|
|
209
231
|
}
|
|
210
232
|
else {
|
|
211
|
-
throw new Error("Usage: winix state forget startup <name> [--dry]
|
|
233
|
+
throw new Error("Usage: winix state owners | state migrate-owner <id> --host <name> [--dry|--yes] | state forget startup <name> [--dry] | state forget package <winget|msstore> <id> [--dry]");
|
|
212
234
|
}
|
|
213
235
|
await forgetWindowsResource(windowsStatePath(), resource, values.dry);
|
|
214
236
|
}
|
package/dist/cli/loader.d.ts
CHANGED
package/dist/cli/loader.js
CHANGED
|
@@ -22,7 +22,7 @@ export async function loadWorkspace(cwd) {
|
|
|
22
22
|
`Run \`winix init\` to create one.`);
|
|
23
23
|
}
|
|
24
24
|
const configDir = dirname(configPath);
|
|
25
|
-
//
|
|
25
|
+
// The npm launcher or embedded runtime supplies TypeScript support.
|
|
26
26
|
const fileUrl = pathToFileURL(configPath).href;
|
|
27
27
|
const mod = await import(__rewriteRelativeImportExtension(fileUrl));
|
|
28
28
|
const workspace = mod.default;
|
|
@@ -31,7 +31,7 @@ export async function loadWorkspace(cwd) {
|
|
|
31
31
|
}
|
|
32
32
|
return { workspace, configDir, configPath };
|
|
33
33
|
}
|
|
34
|
-
function findConfig(dir) {
|
|
34
|
+
export function findConfig(dir) {
|
|
35
35
|
let current = resolve(dir);
|
|
36
36
|
for (let i = 0; i < 10; i++) {
|
|
37
37
|
for (const name of CONFIG_NAMES) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function nodeTypeArguments(version: string): string[];
|
package/dist/cli/node.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function nodeTypeArguments(version) {
|
|
2
|
+
const parsed = /^v?(\d+)\.(\d+)\.\d+$/.exec(version);
|
|
3
|
+
if (!parsed || ![22, 24, 26].includes(Number(parsed[1])) ||
|
|
4
|
+
Number(parsed[1]) === 22 && Number(parsed[2]) < 13) {
|
|
5
|
+
throw new Error(`Winix npm requires stable Node 22.13+, 24.x or 26.x; found ${version}. Node 24 supports transformation; Node 26 supports erasable TypeScript only.`);
|
|
6
|
+
}
|
|
7
|
+
return Number(parsed[1]) >= 26 ? [] : ["--experimental-transform-types"];
|
|
8
|
+
}
|
|
@@ -41,6 +41,17 @@ export interface ReconcileOptions {
|
|
|
41
41
|
lockHeld?: boolean;
|
|
42
42
|
}
|
|
43
43
|
export declare function resourceKey(resource: ManagedResource): string;
|
|
44
|
+
export declare function windowsStateOwner(configDir: string, host: string): Promise<string>;
|
|
45
|
+
export declare function windowsOwnerId(owner: string): string;
|
|
46
|
+
export declare function listWindowsOwners(path: string): Promise<{
|
|
47
|
+
id: string;
|
|
48
|
+
owner: string;
|
|
49
|
+
resources: number;
|
|
50
|
+
}[]>;
|
|
51
|
+
export declare function migrateWindowsOwner(path: string, oldId: string, target: string, opts: {
|
|
52
|
+
dry: boolean;
|
|
53
|
+
yes?: boolean;
|
|
54
|
+
}, report?: (message: string) => void): Promise<void>;
|
|
44
55
|
export declare function managedWindowsResources(host: EvaluatedHost): ManagedResource[];
|
|
45
56
|
export declare function parseAppliedState(text: string): AppliedState;
|
|
46
57
|
export declare function withWindowsStateLock<T>(path: string, dry: boolean, action: () => Promise<T>): Promise<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, readFile, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { hostname } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { createInterface } from "node:readline/promises";
|
|
@@ -11,6 +11,51 @@ export function resourceKey(resource) {
|
|
|
11
11
|
? ["startup", resource.name.toLowerCase()]
|
|
12
12
|
: ["package", resource.source.toLowerCase(), resource.id.toLowerCase()]);
|
|
13
13
|
}
|
|
14
|
+
export async function windowsStateOwner(configDir, host) {
|
|
15
|
+
if (!host)
|
|
16
|
+
throw new Error("A host name is required");
|
|
17
|
+
return JSON.stringify([(await realpath(configDir)).toLowerCase(), host]);
|
|
18
|
+
}
|
|
19
|
+
export function windowsOwnerId(owner) {
|
|
20
|
+
return createHash("sha256").update(owner).digest("hex");
|
|
21
|
+
}
|
|
22
|
+
export async function listWindowsOwners(path) {
|
|
23
|
+
const state = await loadState(path);
|
|
24
|
+
const counts = new Map();
|
|
25
|
+
for (const entry of Object.values(state.entries)) {
|
|
26
|
+
for (const owner of new Set(entry.owners))
|
|
27
|
+
counts.set(owner, (counts.get(owner) ?? 0) + 1);
|
|
28
|
+
}
|
|
29
|
+
return [...counts].sort(([left], [right]) => left.localeCompare(right))
|
|
30
|
+
.map(([owner, resources]) => ({ id: windowsOwnerId(owner), owner, resources }));
|
|
31
|
+
}
|
|
32
|
+
export async function migrateWindowsOwner(path, oldId, target, opts, report = console.log) {
|
|
33
|
+
if (!/^[a-f0-9]{64}$/i.test(oldId) || !target)
|
|
34
|
+
throw new Error("Use an owner ID from winix state owners and a target owner");
|
|
35
|
+
if (!opts.dry && !opts.yes) {
|
|
36
|
+
throw new Error("Owner migration changes applied-state requirements. Preview with --dry, then confirm with --yes. No resources will be deleted.");
|
|
37
|
+
}
|
|
38
|
+
await withWindowsStateLock(path, opts.dry, async () => {
|
|
39
|
+
const state = await loadState(path);
|
|
40
|
+
const owners = new Set(Object.values(state.entries).flatMap((entry) => entry.owners));
|
|
41
|
+
const matches = [...owners].filter((owner) => windowsOwnerId(owner) === oldId.toLowerCase());
|
|
42
|
+
if (matches.length !== 1)
|
|
43
|
+
throw new Error("Recorded owner not found or ambiguous; run winix state owners");
|
|
44
|
+
const previous = matches[0];
|
|
45
|
+
if (previous === target)
|
|
46
|
+
throw new Error("The recorded owner already matches this checkout and host");
|
|
47
|
+
report(`${opts.dry ? "Would migrate" : "Migrating"} owner ${previous} -> ${target}`);
|
|
48
|
+
for (const [key, entry] of Object.entries(state.entries)) {
|
|
49
|
+
if (!entry.owners.includes(previous))
|
|
50
|
+
continue;
|
|
51
|
+
report(` ${key}`);
|
|
52
|
+
entry.owners = [...new Set(entry.owners.map((owner) => owner === previous ? target : owner))];
|
|
53
|
+
}
|
|
54
|
+
if (!opts.dry)
|
|
55
|
+
await saveState(path, state);
|
|
56
|
+
report("No installed resources changed. Ownership, snapshots and shared requirements are preserved; the next switch still checks drift and confirms removals.");
|
|
57
|
+
});
|
|
58
|
+
}
|
|
14
59
|
export function managedWindowsResources(host) {
|
|
15
60
|
const windows = host.windows;
|
|
16
61
|
const resources = Object.values(windows.packages ?? {}).map((pkg) => ({ kind: "package", id: pkg.id, source: pkg.source }));
|
|
@@ -165,7 +210,8 @@ export async function reconcileWindows(opts) {
|
|
|
165
210
|
if (typeof opts.definitions[key] !== "string")
|
|
166
211
|
throw new Error(`Missing resource definition: ${key}`);
|
|
167
212
|
if (entry?.owners.some((owner) => owner !== opts.owner) && entry.definition !== opts.definitions[key]) {
|
|
168
|
-
throw new Error(`Conflicting declaration for resource required by another workspace/host: ${key}`
|
|
213
|
+
throw new Error(`Conflicting declaration for resource required by another workspace/host: ${key}. ` +
|
|
214
|
+
"Run winix state owners; after a checkout move or host rename, explicitly preview state migrate-owner <id> --host <name> --dry.");
|
|
169
215
|
}
|
|
170
216
|
if (entry?.owned && current !== null && !sameSnapshot(current, entry.snapshot)) {
|
|
171
217
|
throw new Error(`Managed resource changed outside Winix: ${key}. Restore it or explicitly resolve ownership before activation.`);
|
|
@@ -3,6 +3,8 @@ export interface ResolvedPowerShellModule extends WinPowerShellModule {
|
|
|
3
3
|
repository: string;
|
|
4
4
|
repositoryUri?: string;
|
|
5
5
|
}
|
|
6
|
+
export declare const powerShellModuleVersion: RegExp;
|
|
7
|
+
export declare function windowsSettingsModule(win: WindowsOptions): ResolvedPowerShellModule;
|
|
6
8
|
export declare const powerShellRepositoryName: RegExp;
|
|
7
9
|
export declare function powerShellRepositoryUri(value: string): string;
|
|
8
10
|
export declare function validatePowerShellRepositoryPolicy(policy: WinPowerShellRepositoryPolicy): void;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export const powerShellModuleVersion = /^\d+\.\d+\.\d+(?:\.\d+)?(?:-[a-z0-9]+(?:[.-][a-z0-9]+)*)?$/i;
|
|
2
|
+
export function windowsSettingsModule(win) {
|
|
3
|
+
return resolvePowerShellModule(win, { name: "Microsoft.Windows.Settings", prerelease: true });
|
|
4
|
+
}
|
|
1
5
|
export const powerShellRepositoryName = /^[a-z0-9][a-z0-9._-]*$/i;
|
|
2
6
|
export function powerShellRepositoryUri(value) {
|
|
3
7
|
let url;
|
|
@@ -50,6 +50,8 @@ export interface WinSettingOpts {
|
|
|
50
50
|
export interface WinPowerShellModuleOpts {
|
|
51
51
|
/** Registered repository; inherits the host policy, otherwise PSGallery. */
|
|
52
52
|
repository?: string;
|
|
53
|
+
/** Include prereleases during lock resolution. Defaults to stable releases only. */
|
|
54
|
+
prerelease?: boolean;
|
|
53
55
|
dependsOn?: ResourceHandle | ResourceHandle[];
|
|
54
56
|
}
|
|
55
57
|
export interface WinStartupCommandSpec extends WinStartupCommand {
|
|
@@ -72,6 +74,7 @@ export interface WinWslOpts extends Pick<WinFileOpts, "backup" | "force" | "depe
|
|
|
72
74
|
config?: WinWslConfig;
|
|
73
75
|
}
|
|
74
76
|
export interface WinWslNamespace {
|
|
77
|
+
/** Declare the locked Microsoft.WSL package, required features, and optional .wslconfig. */
|
|
75
78
|
(opts?: WinWslOpts): ResourceHandle;
|
|
76
79
|
distro(name: string, spec: WinWslDistroSpec): ResourceHandle;
|
|
77
80
|
}
|
package/dist/helpers/windows.js
CHANGED
|
@@ -965,7 +965,11 @@ export const windows = {
|
|
|
965
965
|
wsl: Object.assign((opts = {}) => {
|
|
966
966
|
normalizeFileOpts(opts, "windows.wsl");
|
|
967
967
|
const content = opts.config === undefined ? undefined : serializeWslConfig(opts.config);
|
|
968
|
-
const
|
|
968
|
+
const runtime = windows.package("Microsoft.WSL");
|
|
969
|
+
const dependencies = opts.dependsOn === undefined ? []
|
|
970
|
+
: Array.isArray(opts.dependsOn) ? opts.dependsOn : [opts.dependsOn];
|
|
971
|
+
const enabled = optionalFeatures(["Microsoft-Windows-Subsystem-Linux", "VirtualMachinePlatform"], { dependsOn: [runtime, ...dependencies] });
|
|
972
|
+
enabled.windows.packages = runtime.windows.packages;
|
|
969
973
|
if (content === undefined)
|
|
970
974
|
return enabled;
|
|
971
975
|
const resource = normalizeFileText(knownFolder("userProfile", ".wslconfig"), content, {
|
|
@@ -976,6 +980,7 @@ export const windows = {
|
|
|
976
980
|
resource.name = "WSL configuration";
|
|
977
981
|
resource.dependsOn = [enabled.__winixHandle, ...(resource.dependsOn ?? [])];
|
|
978
982
|
const configured = dscHandle(resource);
|
|
983
|
+
configured.windows.packages = enabled.windows.packages;
|
|
979
984
|
configured.windows.dsc.unshift(...enabled.windows.dsc);
|
|
980
985
|
return configured;
|
|
981
986
|
}, {
|
|
@@ -1025,11 +1030,16 @@ export const windows = {
|
|
|
1025
1030
|
if (repository !== undefined && (typeof repository !== "string" || !/^[a-z0-9][a-z0-9._-]*$/i.test(repository))) {
|
|
1026
1031
|
throw new Error("windows.powershell.module repository must be a registered repository name");
|
|
1027
1032
|
}
|
|
1033
|
+
if (opts.prerelease !== undefined && typeof opts.prerelease !== "boolean") {
|
|
1034
|
+
throw new Error("windows.powershell.module prerelease must be a boolean");
|
|
1035
|
+
}
|
|
1028
1036
|
const resource = withDscMetadata(withDscToken({
|
|
1029
1037
|
resourceType: POWERSHELL_SCRIPT_RESOURCE,
|
|
1030
1038
|
name: `PowerShell module ${name}`,
|
|
1031
1039
|
dependsOn: resolveDependsOn(opts.dependsOn),
|
|
1032
|
-
}), { kind: "powershell-module", module: {
|
|
1040
|
+
}), { kind: "powershell-module", module: {
|
|
1041
|
+
name, repository, ...(opts.prerelease !== undefined ? { prerelease: opts.prerelease } : {}),
|
|
1042
|
+
} });
|
|
1033
1043
|
return dscHandle(resource);
|
|
1034
1044
|
},
|
|
1035
1045
|
},
|
package/dist/skill.js
CHANGED
|
@@ -260,7 +260,10 @@ Resources return handles that can be passed through \`dependsOn\`.
|
|
|
260
260
|
- \`windows.package()\` installs a winget or Microsoft Store package. A string
|
|
261
261
|
means a floating winget package ID. The object form accepts \`id\`,
|
|
262
262
|
\`source\`, \`version\`, and dependency options.
|
|
263
|
-
- \`windows.setting()\` manages supported Windows settings.
|
|
263
|
+
- \`windows.setting()\` manages supported Windows settings. Symlinks automatically
|
|
264
|
+
depend on same-host typed settings declaring DeveloperMode: true. Declare that
|
|
265
|
+
policy explicitly; symlinks never enable Developer Mode themselves. Without the
|
|
266
|
+
declaration, existing Developer Mode or elevation is still required.
|
|
264
267
|
- \`windows.env.set()\` and \`windows.env.remove()\` manage environment
|
|
265
268
|
variables.
|
|
266
269
|
- \`windows.path.add()\` and \`windows.path.remove()\` manage PATH entries.
|
|
@@ -299,15 +302,17 @@ Resources return handles that can be passed through \`dependsOn\`.
|
|
|
299
302
|
- \`windows.dsc()\` declares an arbitrary DSC resource.
|
|
300
303
|
- \`windows.optionalFeature()\` enables/disables a named Windows optional feature;
|
|
301
304
|
enabled defaults to true. Changes require elevation, never reboot automatically.
|
|
302
|
-
- \`windows.wsl()\`
|
|
305
|
+
- \`windows.wsl()\` declares the Microsoft.WSL package with normal package locking
|
|
306
|
+
and enables the WSL and Virtual Machine Platform features. A separate package
|
|
307
|
+
declaration may customize the runtime's package options.
|
|
303
308
|
Options are config, backup, force, and dependsOn. The optional config manages
|
|
304
309
|
the full current-user .wslconfig with file overwrite protections; omitting it
|
|
305
310
|
leaves the file untouched. The returned handle covers the complete setup.
|
|
306
311
|
If a reboot is needed, restart Windows manually and rerun switch.
|
|
307
312
|
It never shuts down WSL; restart WSL manually when configuration changes.
|
|
308
313
|
- \`windows.wsl.distro()\` registers a named distro with source "nixos-wsl",
|
|
309
|
-
installLocation, optional default and dependsOn. Declare windows.wsl()
|
|
310
|
-
|
|
314
|
+
installLocation, optional default and dependsOn. Declare windows.wsl() in the
|
|
315
|
+
same host; features, config, and runtime become
|
|
311
316
|
automatic dependencies.
|
|
312
317
|
Images for x64/ARM64 are verified against winix-windows.lock wslImages pins.
|
|
313
318
|
Update with winix update --windows nixos-wsl. Updates never reinstall an
|
|
@@ -357,6 +362,13 @@ package/module/image/repository pins (all when omitted, nixos-wsl for images,
|
|
|
357
362
|
wsl-setup for setup commits); --dry reports without writing.
|
|
358
363
|
Keep the lock in version control. Installation still requires network access
|
|
359
364
|
when the locked package/module is not installed.
|
|
365
|
+
Typed \`windows.setting(...)\` implicitly locks Microsoft.Windows.Settings through
|
|
366
|
+
the same host-policy/source-aware module mechanism, with prereleases allowed.
|
|
367
|
+
\`windows.powershell.module(name, { prerelease: true })\` opts other modules in;
|
|
368
|
+
stable-only declarations reject prerelease pins. Exact numeric version and
|
|
369
|
+
prerelease label are checked. Do not put versions in handwritten settings config.
|
|
370
|
+
Side-by-side DSC adapted-module selection/native Settings activation is unverified;
|
|
371
|
+
installing the pin alone does not guarantee which installed module DSC selects.
|
|
360
372
|
|
|
361
373
|
Native Windows \`winix switch\` keeps a separate per-user/machine applied-state
|
|
362
374
|
inventory in LocalAppData/Winix, shared across recorded workspace/host activations.
|
|
@@ -373,6 +385,12 @@ External shortcut edits/package-version drift block reconciliation.
|
|
|
373
385
|
without deleting the resource; --dry previews. Do not copy applied state to a
|
|
374
386
|
new machine or infer ownership from version locks. Direct DSC/script activation
|
|
375
387
|
bypasses this tracking. Files, modules, env and PATH cleanup are not tracked.
|
|
388
|
+
\`state forget\` retains owner requirements; it cannot repair checkout moves or
|
|
389
|
+
host renames. Run \`winix state owners\`, then from the new config checkout use
|
|
390
|
+
\`winix state migrate-owner <old-owner-id> --host NEW --dry\` and explicitly
|
|
391
|
+
confirm with \`--yes\` instead of \`--dry\`. This transfers recorded requirements,
|
|
392
|
+
not resources, and preserves snapshots, external status, other owners, drift
|
|
393
|
+
checks and later removal confirmation. It does not evaluate config or activate.
|
|
376
394
|
|
|
377
395
|
For fresh Windows prerequisites, \`scripts/bootstrap-windows.ps1\` runs in built-in
|
|
378
396
|
Windows PowerShell 5.1 or PowerShell 7. App Installer/WinGet is the initial
|
|
@@ -412,10 +430,14 @@ Do not run real bootstrap/activation as a development check on a shared machine.
|
|
|
412
430
|
\`winix bootstrap --host HOST\` performs the checkout validation/preview/confirmation
|
|
413
431
|
phase. Its generated \`.winix/bin/winix.ps1\` or \`.winix/bin/winix\` launcher invokes
|
|
414
432
|
\`winix run <args>\`, rereading the exact pin on every invocation. A matching
|
|
415
|
-
optional node_modules SDK uses its own CLI under
|
|
433
|
+
optional node_modules SDK uses its own CLI under supported stable Node
|
|
434
|
+
22.13+ (22.x), 24.x or 26.x; stale/corrupt
|
|
416
435
|
local packages fail, never silently fall back. Otherwise the standalone must
|
|
417
436
|
match the manifest; rerun bootstrap after changing the pin. The user may run
|
|
418
437
|
\`npm ci\` explicitly using an approved source, then use normal local npm scripts.
|
|
438
|
+
The npm launcher enables transformation on Node 22/24, omits the removed
|
|
439
|
+
transform flag on 26, and rejects unsupported majors. Node 26 accepts erasable
|
|
440
|
+
TypeScript only; use Node 24 for enums/parameter properties in config/local imports.
|
|
419
441
|
|
|
420
442
|
On existing NixOS/NixOS-WSL, \`bash bootstrap-nixos.sh\` (from
|
|
421
443
|
\`scripts/bootstrap-nixos.sh\` or a reviewed release asset) opens a temporary
|
package/dist/types/windows.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface WinPowerShellModule {
|
|
|
20
20
|
name: string;
|
|
21
21
|
/** Omitted repositories inherit the host policy after all fragments merge. */
|
|
22
22
|
repository?: string;
|
|
23
|
+
/** Allow prereleases when resolving the lock; installations still use an exact pin. */
|
|
24
|
+
prerelease?: boolean;
|
|
23
25
|
}
|
|
24
26
|
export interface WinPowerShellRepositoryPolicy {
|
|
25
27
|
/** Named HTTPS feeds to register for the current Windows user. No credentials in URLs. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adrifer/winix",
|
|
3
|
-
"version": "0.3.0-preview.
|
|
3
|
+
"version": "0.3.0-preview.3",
|
|
4
4
|
"description": "TypeScript-first system configuration for NixOS, nix-darwin, and Home Manager",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Adrian Fernandez",
|
|
@@ -40,9 +40,13 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"bin": {
|
|
43
|
-
"winix": "
|
|
43
|
+
"winix": "scripts/winix.mjs"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": "^22.13.0 || ^24.0.0 || ^26.0.0"
|
|
44
47
|
},
|
|
45
48
|
"files": [
|
|
49
|
+
"scripts/winix.mjs",
|
|
46
50
|
"scripts/bootstrap-windows.ps1",
|
|
47
51
|
"scripts/bootstrap-nixos.sh",
|
|
48
52
|
"scripts/bootstrap-linux.sh",
|
|
@@ -74,9 +74,10 @@ def confirm(message, yes):
|
|
|
74
74
|
return
|
|
75
75
|
# stdin contains this script, not an interactive terminal.
|
|
76
76
|
try:
|
|
77
|
-
with open("/dev/tty", "
|
|
77
|
+
with open("/dev/tty", "w") as tty:
|
|
78
78
|
tty.write(message + " [y/N] ")
|
|
79
79
|
tty.flush()
|
|
80
|
+
with open("/dev/tty", "r") as tty:
|
|
80
81
|
answer = tty.readline().strip().lower()
|
|
81
82
|
except OSError as error:
|
|
82
83
|
raise RuntimeError("Interactive confirmation unavailable; pass --yes only after reviewing the repository/script") from error
|
|
@@ -94,12 +94,14 @@ function Get-WinixBootstrapTools {
|
|
|
94
94
|
throw "Prerelease $($tool.Command) is not supported by this bootstrap. Install a stable release."
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
$ready = $null -ne $version -and $version -ge [version]$tool.Minimum
|
|
98
|
+
if ($tool.Command -eq 'node.exe' -and $ready -and $version.Major -notin @(22, 24, 26)) { $ready = $false }
|
|
97
99
|
[pscustomobject]@{
|
|
98
100
|
Id = $tool.Id
|
|
99
101
|
Command = $tool.Command
|
|
100
102
|
Path = $path
|
|
101
103
|
Version = $version
|
|
102
|
-
Ready = $
|
|
104
|
+
Ready = $ready
|
|
103
105
|
Minimum = $tool.Minimum
|
|
104
106
|
}
|
|
105
107
|
}
|
|
@@ -116,10 +118,14 @@ function Test-WinixBootstrapCapabilities {
|
|
|
116
118
|
if (-not $npm) { throw 'npm.cmd is unavailable. Repair the Node.js installation or open a new terminal, then rerun.' }
|
|
117
119
|
Invoke-WinixBootstrapNative $npm @('--version') | Out-Null
|
|
118
120
|
$node = Get-WinixBootstrapApplication 'node.exe'
|
|
119
|
-
Invoke-WinixBootstrapNative $node @(
|
|
120
|
-
|
|
121
|
+
$nodeVersion = (Invoke-WinixBootstrapNative $node @('--version')) -join ''
|
|
122
|
+
if ($nodeVersion -notmatch '^v?(22|24|26)\.') { throw 'Winix npm supports stable Node 22.13+, 24.x or 26.x.' }
|
|
123
|
+
$nodeArgs = @(
|
|
124
|
+
'--no-warnings', '--input-type=module', '--eval',
|
|
121
125
|
"import { stripTypeScriptTypes } from 'node:module'; stripTypeScriptTypes('const x: number = 1');"
|
|
122
|
-
)
|
|
126
|
+
)
|
|
127
|
+
if ([int]$Matches[1] -lt 26) { $nodeArgs = @('--experimental-transform-types') + $nodeArgs }
|
|
128
|
+
Invoke-WinixBootstrapNative $node $nodeArgs | Out-Null
|
|
123
129
|
}
|
|
124
130
|
$pwsh = Get-WinixBootstrapApplication 'pwsh.exe'
|
|
125
131
|
$script = @'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { nodeTypeArguments } from "../dist/cli/node.js";
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const result = spawnSync(process.execPath, [
|
|
8
|
+
...nodeTypeArguments(process.version), "--no-warnings",
|
|
9
|
+
fileURLToPath(new URL("../dist/cli/index.js", import.meta.url)), ...process.argv.slice(2),
|
|
10
|
+
], { stdio: "inherit" });
|
|
11
|
+
if (result.error) throw result.error;
|
|
12
|
+
process.exitCode = result.status ?? 1;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(`Error: ${error.message}`);
|
|
15
|
+
process.exitCode = 1;
|
|
16
|
+
}
|