@adrifer/winix 0.3.0-preview.8 → 0.3.0-preview.9
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 +102 -12
- package/dist/backends/nix/index.d.ts +1 -0
- package/dist/backends/nix/index.js +18 -1
- package/dist/backends/windows/index.d.ts +9 -1
- package/dist/backends/windows/index.js +10 -10
- package/dist/backends/windows/lockfile.d.ts +3 -3
- package/dist/backends/windows/lockfile.js +4 -3
- package/dist/backends/windows/powershell.d.ts +4 -2
- package/dist/backends/windows/powershell.js +152 -21
- package/dist/backends/windows/wsl-setup-runtime.d.ts +17 -1
- package/dist/backends/windows/wsl-setup-runtime.js +75 -11
- package/dist/backends/windows/wsl-setup.d.ts +7 -1
- package/dist/backends/windows/wsl-setup.js +29 -8
- package/dist/backends/windows/wsl.js +1 -1
- package/dist/cli/analysis.d.ts +11 -2
- package/dist/cli/analysis.js +35 -7
- package/dist/cli/commands/apply.d.ts +6 -1
- package/dist/cli/commands/apply.js +12 -6
- package/dist/cli/commands/check.js +11 -5
- package/dist/cli/commands/inspect.js +2 -2
- package/dist/cli/commands/switch.d.ts +7 -0
- package/dist/cli/commands/switch.js +58 -11
- package/dist/cli/commands/update.js +4 -4
- package/dist/cli/windows-package-versions.d.ts +2 -1
- package/dist/cli/windows-package-versions.js +12 -5
- package/dist/cli/windows-state.js +45 -17
- package/dist/core/types.d.ts +18 -0
- package/dist/evaluator/index.d.ts +5 -3
- package/dist/evaluator/index.js +30 -16
- package/dist/helpers/account.js +1 -7
- package/dist/helpers/home.d.ts +18 -0
- package/dist/helpers/home.js +39 -0
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/nix.d.ts +14 -0
- package/dist/helpers/nix.js +2 -0
- package/dist/helpers/platforms.d.ts +13 -0
- package/dist/helpers/platforms.js +35 -19
- package/dist/helpers/windows.d.ts +35 -2
- package/dist/helpers/windows.js +55 -4
- package/dist/helpers/wsl-interop.d.ts +13 -0
- package/dist/helpers/wsl-interop.js +72 -0
- package/dist/helpers/wsl-repository.d.ts +12 -0
- package/dist/helpers/wsl-repository.js +93 -0
- package/dist/index.d.ts +3 -3
- package/dist/sdk/index.d.ts +5 -1
- package/dist/sdk/index.js +9 -2
- package/dist/skill.js +23 -2
- package/dist/types/windows.d.ts +6 -0
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { dirname, join } from "node:path";
|
|
|
6
6
|
import { createInterface } from "node:readline/promises";
|
|
7
7
|
import { powerShellLiteral } from "../helpers/utils.js";
|
|
8
8
|
import { runCommand } from "./run.js";
|
|
9
|
-
import { compareWindowsPackageVersions, effectiveWindowsPackageVersion } from "./windows-package-versions.js";
|
|
9
|
+
import { compareWindowsPackageVersions, effectiveWindowsPackageVersion, isComparableWindowsPackageVersion, } from "./windows-package-versions.js";
|
|
10
10
|
export function resourceKey(resource) {
|
|
11
11
|
return JSON.stringify(resource.kind === "startup"
|
|
12
12
|
? ["startup", resource.name.toLowerCase()]
|
|
@@ -77,6 +77,17 @@ export function managedWindowsResources(host) {
|
|
|
77
77
|
function sameSnapshot(a, b) {
|
|
78
78
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
79
79
|
}
|
|
80
|
+
function comparePackageSnapshots(id, current, previous) {
|
|
81
|
+
if (!isComparableWindowsPackageVersion(current.version) || !isComparableWindowsPackageVersion(previous.version))
|
|
82
|
+
return undefined;
|
|
83
|
+
return compareWindowsPackageVersions(id, current.version, previous.version);
|
|
84
|
+
}
|
|
85
|
+
function assertRemovablePackageVersion(id, version) {
|
|
86
|
+
if (!isComparableWindowsPackageVersion(version)) {
|
|
87
|
+
throw new Error(`Refusing automatic removal of ${id}: installed version was reported as non-comparable (${JSON.stringify(version)}). ` +
|
|
88
|
+
`Uninstall it manually, or keep it installed and release Winix ownership with \`winix state forget package <source> ${id}\`.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
80
91
|
function validResource(value) {
|
|
81
92
|
if (!value || typeof value !== "object")
|
|
82
93
|
return false;
|
|
@@ -228,12 +239,19 @@ export async function reconcileWindows(opts) {
|
|
|
228
239
|
}
|
|
229
240
|
}
|
|
230
241
|
if (entry?.owned && current !== null && !sameSnapshot(current, entry.snapshot)) {
|
|
231
|
-
|
|
232
|
-
entry.snapshot && "version" in entry.snapshot
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
242
|
+
if (resource.kind === "package" && requirement && !requirement.exact && "version" in current &&
|
|
243
|
+
entry.snapshot && "version" in entry.snapshot) {
|
|
244
|
+
const change = comparePackageSnapshots(resource.id, current, entry.snapshot);
|
|
245
|
+
if (change === undefined) {
|
|
246
|
+
report(`Skipping version drift check for ${key}: non-comparable version (${current.version} vs ${entry.snapshot.version})`);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (change > 0) {
|
|
250
|
+
report(`Keeping externally upgraded package: ${key} ${current.version}`);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
throw new Error(`Managed resource changed outside Winix: ${key}. Restore it or explicitly resolve ownership before activation.`);
|
|
237
255
|
}
|
|
238
256
|
}
|
|
239
257
|
const removals = [];
|
|
@@ -250,6 +268,9 @@ export async function reconcileWindows(opts) {
|
|
|
250
268
|
continue;
|
|
251
269
|
}
|
|
252
270
|
const current = await opts.adapter.inspect(entry.resource);
|
|
271
|
+
if (entry.resource.kind === "package" && current && "version" in current) {
|
|
272
|
+
assertRemovablePackageVersion(entry.resource.id, current.version);
|
|
273
|
+
}
|
|
253
274
|
if (current !== null && !sameSnapshot(current, entry.snapshot)) {
|
|
254
275
|
throw new Error(`Refusing to remove externally modified resource: ${key}. Resolve ownership explicitly.`);
|
|
255
276
|
}
|
|
@@ -273,24 +294,30 @@ export async function reconcileWindows(opts) {
|
|
|
273
294
|
throw new Error(`Activation succeeded but managed resource is missing: ${key}`);
|
|
274
295
|
const entry = state.entries[key];
|
|
275
296
|
const requirement = resource.kind === "package" ? opts.packageRequirements?.[key] : undefined;
|
|
276
|
-
if (requirement) {
|
|
277
|
-
if (!("version" in current)
|
|
278
|
-
|
|
279
|
-
|
|
297
|
+
if (resource.kind === "package" && requirement) {
|
|
298
|
+
if (!("version" in current)) {
|
|
299
|
+
throw new Error(`Activation did not satisfy package version requirement: ${key}`);
|
|
300
|
+
}
|
|
301
|
+
if (requirement.exact) {
|
|
302
|
+
effectiveWindowsPackageVersion(resource.id, requirement, current.version);
|
|
303
|
+
}
|
|
304
|
+
else if (isComparableWindowsPackageVersion(current.version) &&
|
|
305
|
+
compareWindowsPackageVersions(resource.id, current.version, requirement.version) < 0) {
|
|
280
306
|
throw new Error(`Activation did not satisfy package version requirement: ${key}`);
|
|
281
307
|
}
|
|
282
308
|
const initial = before.get(key);
|
|
283
309
|
if (!requirement.exact && initial && "version" in initial &&
|
|
284
|
-
|
|
310
|
+
(comparePackageSnapshots(resource.id, current, initial) ?? 0) < 0) {
|
|
285
311
|
throw new Error(`Activation unexpectedly downgraded package: ${key}`);
|
|
286
312
|
}
|
|
287
313
|
}
|
|
288
314
|
if (entry && entry.owners.some((owner) => owner !== opts.owner) && !sameSnapshot(current, entry.snapshot)) {
|
|
289
|
-
const
|
|
290
|
-
entry.
|
|
291
|
-
|
|
292
|
-
if (
|
|
315
|
+
const change = resource.kind === "package" && requirement && !requirement.exact &&
|
|
316
|
+
entry.packageExact === false && "version" in current && entry.snapshot && "version" in entry.snapshot
|
|
317
|
+
? comparePackageSnapshots(resource.id, current, entry.snapshot) : 0;
|
|
318
|
+
if (change !== undefined && change <= 0) {
|
|
293
319
|
throw new Error(`Activation changed a resource required by another workspace/host: ${key}`);
|
|
320
|
+
}
|
|
294
321
|
}
|
|
295
322
|
after.set(key, current);
|
|
296
323
|
}
|
|
@@ -393,7 +420,8 @@ if (Test-Path -LiteralPath $path) {
|
|
|
393
420
|
async remove(resource, snapshot) {
|
|
394
421
|
if (resource.kind === "package") {
|
|
395
422
|
if (!("version" in snapshot))
|
|
396
|
-
throw new Error(
|
|
423
|
+
throw new Error(`Missing package version for uninstall: ${resource.id}`);
|
|
424
|
+
assertRemovablePackageVersion(resource.id, snapshot.version);
|
|
397
425
|
await runCommand("winget", [
|
|
398
426
|
"uninstall", "--id", resource.id, "--exact", "--source", resource.source,
|
|
399
427
|
"--version", snapshot.version, "--silent", "--disable-interactivity",
|
package/dist/core/types.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface Fragment {
|
|
|
12
12
|
__id?: string;
|
|
13
13
|
/** Internal: marks this as a platform fragment */
|
|
14
14
|
__platform?: boolean;
|
|
15
|
+
/** Internal: account requesting a NixOS-WSL default user */
|
|
16
|
+
__wslDefaultUser?: string;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Internal reference to a workspace-relative raw Nix module file.
|
|
@@ -102,6 +104,8 @@ export interface LazyFragment {
|
|
|
102
104
|
*/
|
|
103
105
|
export interface PlatformLazyFragment extends LazyFragment {
|
|
104
106
|
__platform: true;
|
|
107
|
+
/** Platform variant within the platform id (e.g. "wsl" for NixOS-WSL hosts). */
|
|
108
|
+
__variant?: string;
|
|
105
109
|
}
|
|
106
110
|
/**
|
|
107
111
|
* A fragment factory: callable to produce a LazyFragment, with .isActive getter.
|
|
@@ -153,6 +157,20 @@ export interface HostDef {
|
|
|
153
157
|
*/
|
|
154
158
|
export interface EvalContext {
|
|
155
159
|
platform: string;
|
|
160
|
+
/** Platform variant, e.g. "wsl" for `platforms.wsl()` hosts (platform stays "nixos"). */
|
|
161
|
+
variant?: string;
|
|
156
162
|
hostname: string;
|
|
157
163
|
activeIds: Set<string>;
|
|
164
|
+
/** Directory containing the evaluated winix.config.ts, when known. */
|
|
165
|
+
configDir?: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Options for evaluating a workspace.
|
|
169
|
+
*/
|
|
170
|
+
export interface EvaluateOptions {
|
|
171
|
+
/**
|
|
172
|
+
* Directory containing winix.config.ts. Enables config-relative helpers such
|
|
173
|
+
* as `home.symlink("../nvim")` and WSL setup `repository: "self"`.
|
|
174
|
+
*/
|
|
175
|
+
configDir?: string;
|
|
158
176
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HostDef, WorkspaceDef } from "../core/types.js";
|
|
1
|
+
import type { HostDef, WorkspaceDef, EvalContext, EvaluateOptions } from "../core/types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Evaluated host: the merged result of all fragments for one host.
|
|
4
4
|
*/
|
|
@@ -12,8 +12,10 @@ export interface EvaluatedHost {
|
|
|
12
12
|
/**
|
|
13
13
|
* Evaluate a workspace: process each host's fragments and merge them.
|
|
14
14
|
*/
|
|
15
|
-
export declare function evaluate(workspace: WorkspaceDef): EvaluatedHost[];
|
|
16
|
-
|
|
15
|
+
export declare function evaluate(workspace: WorkspaceDef, options?: EvaluateOptions): EvaluatedHost[];
|
|
16
|
+
/** Build the evaluation context for one host. */
|
|
17
|
+
export declare function hostEvalContext(host: HostDef, activeIds: Set<string>, options?: EvaluateOptions): EvalContext;
|
|
18
|
+
export declare function collectActiveIds(host: HostDef, options?: EvaluateOptions): Set<string>;
|
|
17
19
|
/**
|
|
18
20
|
* Deep merge two objects. Arrays are appended + deduped.
|
|
19
21
|
* Scalars: last wins.
|
package/dist/evaluator/index.js
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
// Evaluator: takes a workspace config, evaluates fragments per host, produces merged IR
|
|
2
2
|
import { setEvalContext, restoreEvalContext } from "../sdk/index.js";
|
|
3
|
+
import { nix } from "../helpers/nix.js";
|
|
3
4
|
import { powerShellRepositoryPolicyIdentity, validateWindowsPowerShellPolicy } from "../helpers/windows-repositories.js";
|
|
4
5
|
/**
|
|
5
6
|
* Evaluate a workspace: process each host's fragments and merge them.
|
|
6
7
|
*/
|
|
7
|
-
export function evaluate(workspace) {
|
|
8
|
-
return workspace.hosts.map((host) => evaluateHost(host));
|
|
8
|
+
export function evaluate(workspace, options = {}) {
|
|
9
|
+
return workspace.hosts.map((host) => evaluateHost(host, options));
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
/** Build the evaluation context for one host. */
|
|
12
|
+
export function hostEvalContext(host, activeIds, options = {}) {
|
|
13
|
+
return {
|
|
14
|
+
platform: host.platform.__id,
|
|
15
|
+
...(host.platform.__variant === undefined ? {} : { variant: host.platform.__variant }),
|
|
16
|
+
hostname: host.name,
|
|
17
|
+
activeIds,
|
|
18
|
+
...(options.configDir === undefined ? {} : { configDir: options.configDir }),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function evaluateHost(host, options) {
|
|
11
22
|
// The platform is always host.platform (exactly one, guaranteed by type system)
|
|
12
23
|
const platformEntry = host.platform;
|
|
13
24
|
const allEntries = [platformEntry, ...host.fragments];
|
|
14
25
|
const platformId = platformEntry.__id;
|
|
15
|
-
const activeIds = collectActiveIds(host);
|
|
26
|
+
const activeIds = collectActiveIds(host, options);
|
|
16
27
|
// Pass 2: set context → resolve lazy fragments (now .isActive works)
|
|
17
|
-
const ctx =
|
|
18
|
-
platform: platformId,
|
|
19
|
-
hostname: host.name,
|
|
20
|
-
activeIds,
|
|
21
|
-
};
|
|
28
|
+
const ctx = hostEvalContext(host, activeIds, options);
|
|
22
29
|
const prevCtx = setEvalContext(ctx);
|
|
23
30
|
const resolvedFragments = [];
|
|
24
31
|
try {
|
|
@@ -37,7 +44,9 @@ function evaluateHost(host) {
|
|
|
37
44
|
darwin: {},
|
|
38
45
|
windows: {},
|
|
39
46
|
};
|
|
47
|
+
let defaultUser;
|
|
40
48
|
for (const fragment of resolvedFragments) {
|
|
49
|
+
defaultUser = fragment.__wslDefaultUser ?? defaultUser;
|
|
41
50
|
if (fragment.nixos && shouldMergeScope(resolvedFragments, "nixos")) {
|
|
42
51
|
result.nixos = deepMerge(result.nixos, fragment.nixos);
|
|
43
52
|
}
|
|
@@ -51,6 +60,16 @@ function evaluateHost(host) {
|
|
|
51
60
|
result.windows = mergeWindowsOptions(result.windows, fragment.windows);
|
|
52
61
|
}
|
|
53
62
|
}
|
|
63
|
+
const wsl = result.nixos.wsl;
|
|
64
|
+
if (defaultUser && (platformId === "nixos" || platformId === "linux") &&
|
|
65
|
+
(wsl === undefined || isPlainObject(wsl))) {
|
|
66
|
+
const options = wsl ?? {};
|
|
67
|
+
const imports = result.nixos.imports;
|
|
68
|
+
const importsWsl = Array.isArray(imports) && imports.some((entry) => typeof entry === "string" && /^inputs\.[a-z0-9._-]+\.nixosModules\.wsl$/i.test(entry.trim()));
|
|
69
|
+
if (options.defaultUser === undefined && (options.enable === true || (options.enable === undefined && importsWsl))) {
|
|
70
|
+
result.nixos.wsl = { ...options, defaultUser: nix.lib.mkDefault(defaultUser) };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
54
73
|
validateWindowsPowerShellPolicy(result.windows);
|
|
55
74
|
return result;
|
|
56
75
|
}
|
|
@@ -81,7 +100,7 @@ function shouldMergeScope(fragments, scope) {
|
|
|
81
100
|
function isLazy(entry) {
|
|
82
101
|
return typeof entry === "object" && entry !== null && "__lazy" in entry && entry.__lazy === true;
|
|
83
102
|
}
|
|
84
|
-
export function collectActiveIds(host) {
|
|
103
|
+
export function collectActiveIds(host, options = {}) {
|
|
85
104
|
const activeIds = new Set([host.platform.__id]);
|
|
86
105
|
let previousSize = -1;
|
|
87
106
|
let iterations = 0;
|
|
@@ -92,12 +111,7 @@ export function collectActiveIds(host) {
|
|
|
92
111
|
throw new Error(`Could not stabilize active fragment IDs for host "${host.name}". ` +
|
|
93
112
|
"Check for fragments that generate new fragment IDs dynamically.");
|
|
94
113
|
}
|
|
95
|
-
const
|
|
96
|
-
platform: host.platform.__id,
|
|
97
|
-
hostname: host.name,
|
|
98
|
-
activeIds,
|
|
99
|
-
};
|
|
100
|
-
const prevCtx = setEvalContext(ctx);
|
|
114
|
+
const prevCtx = setEvalContext(hostEvalContext(host, activeIds, options));
|
|
101
115
|
try {
|
|
102
116
|
collectIds(host.platform, activeIds);
|
|
103
117
|
for (const entry of host.fragments) {
|
package/dist/helpers/account.js
CHANGED
|
@@ -18,7 +18,6 @@ function accountFragment(username, opts) {
|
|
|
18
18
|
const ctx = getEvalContext();
|
|
19
19
|
const isDarwin = ctx.platform === "darwin";
|
|
20
20
|
const isNixos = ctx.platform === "nixos" || ctx.platform === "linux";
|
|
21
|
-
const isWsl = ctx.activeIds.has("wsl");
|
|
22
21
|
const usesHomebrew = ctx.activeIds.has("homebrew");
|
|
23
22
|
const homeDirectory = opts.homeDirectory ?? opts.home ?? (isDarwin ? `/Users/${username}` : `/home/${username}`);
|
|
24
23
|
const shell = normalizeShell(opts.shell);
|
|
@@ -43,6 +42,7 @@ function accountFragment(username, opts) {
|
|
|
43
42
|
...(isPlainObject(homeManager) && homeManager),
|
|
44
43
|
},
|
|
45
44
|
...(isNixos && {
|
|
45
|
+
...(opts.wslDefault && { __wslDefaultUser: username }),
|
|
46
46
|
nixos: {
|
|
47
47
|
users: {
|
|
48
48
|
users: {
|
|
@@ -66,12 +66,6 @@ function accountFragment(username, opts) {
|
|
|
66
66
|
[nixosShellProgram]: { enable: true },
|
|
67
67
|
},
|
|
68
68
|
}),
|
|
69
|
-
...(opts.wslDefault &&
|
|
70
|
-
isWsl && {
|
|
71
|
-
wsl: {
|
|
72
|
-
defaultUser: nix.lib.mkDefault(username),
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
75
69
|
},
|
|
76
70
|
}),
|
|
77
71
|
...(isDarwin && {
|
package/dist/helpers/home.d.ts
CHANGED
|
@@ -27,9 +27,27 @@ export interface HomeHelper {
|
|
|
27
27
|
files(files: Record<string, HomeFile>): Fragment;
|
|
28
28
|
configFile(name: string, opts: HomeFile): Fragment;
|
|
29
29
|
configFiles(files: Record<string, HomeFile>): Fragment;
|
|
30
|
+
/**
|
|
31
|
+
* Out-of-store symlink source. `~/` paths are home-relative; `./` and
|
|
32
|
+
* `../` paths are relative to the directory holding winix.config.ts.
|
|
33
|
+
*/
|
|
30
34
|
symlink(path: string, opts?: Omit<HomeFile, "source" | "text">): HomeFile;
|
|
31
35
|
raw(config: string): Fragment;
|
|
32
36
|
activation(name: string, opts: ActivationOpts): Fragment;
|
|
37
|
+
/** Home Manager helpers for NixOS-WSL hosts. */
|
|
38
|
+
wsl: HomeWslHelper;
|
|
39
|
+
}
|
|
40
|
+
export interface HomeWslHelper {
|
|
41
|
+
/**
|
|
42
|
+
* Use the Windows Git Credential Manager from WSL: enables
|
|
43
|
+
* `programs.git` and sets `credential.helper` to a shim that finds
|
|
44
|
+
* Git for Windows' GCM at run time.
|
|
45
|
+
*/
|
|
46
|
+
gitCredentialManager(opts?: HomeWslGitCredentialManagerOpts): Fragment;
|
|
47
|
+
}
|
|
48
|
+
export interface HomeWslGitCredentialManagerOpts {
|
|
49
|
+
/** Windows paths to try, in order. Defaults to Git for Windows' ucrt64/mingw64 GCM. */
|
|
50
|
+
paths?: readonly string[];
|
|
33
51
|
}
|
|
34
52
|
export interface ActivationOpts {
|
|
35
53
|
/** DAG dependencies. Defaults to ["writeBoundary"]. */
|
package/dist/helpers/home.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { posix as pathPosix } from "node:path";
|
|
1
2
|
import { normalizeArgs } from "./utils.js";
|
|
3
|
+
import { getOptionalEvalContext } from "../sdk/index.js";
|
|
4
|
+
import { GIT_CREDENTIAL_MANAGER_PATHS, windowsBin } from "./wsl-interop.js";
|
|
2
5
|
import { escapeNixDoubleQuoted, nixStringLiteral } from "../nix/serialize.js";
|
|
3
6
|
export const home = Object.assign((config) => ({ homeManager: config }), {
|
|
4
7
|
program: (name, opts = {}) => ({
|
|
@@ -36,6 +39,25 @@ export const home = Object.assign((config) => ({ homeManager: config }), {
|
|
|
36
39
|
},
|
|
37
40
|
}),
|
|
38
41
|
raw: (config) => ({ homeManager: { __raw: [config] } }),
|
|
42
|
+
wsl: {
|
|
43
|
+
gitCredentialManager: (opts = {}) => {
|
|
44
|
+
const shim = windowsBin("git-credential-manager", opts.paths ?? GIT_CREDENTIAL_MANAGER_PATHS);
|
|
45
|
+
return {
|
|
46
|
+
homeManager: {
|
|
47
|
+
programs: {
|
|
48
|
+
git: {
|
|
49
|
+
enable: true,
|
|
50
|
+
settings: {
|
|
51
|
+
credential: {
|
|
52
|
+
helper: { __winixNixExpr: true, expr: `"\${${shim.expr}}/bin/git-credential-manager"` },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
},
|
|
39
61
|
activation: (name, opts) => {
|
|
40
62
|
const after = opts.after ?? ["writeBoundary"];
|
|
41
63
|
const afterList = after.map((s) => nixStringLiteral(s)).join(" ");
|
|
@@ -57,5 +79,22 @@ function homePathToNixString(path) {
|
|
|
57
79
|
if (path.startsWith("~/")) {
|
|
58
80
|
return '"${config.home.homeDirectory}/' + escapeNixDoubleQuoted(path.slice(2)) + '"';
|
|
59
81
|
}
|
|
82
|
+
if (path.startsWith("./") || path.startsWith("../")) {
|
|
83
|
+
return nixStringLiteral(configRelativePath(path));
|
|
84
|
+
}
|
|
60
85
|
return nixStringLiteral(path);
|
|
61
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Resolve a "./" or "../" path against the directory holding winix.config.ts,
|
|
89
|
+
* matching how Windows file sources resolve. The result is an absolute POSIX
|
|
90
|
+
* path into the checkout, so out-of-store symlinks follow the working tree.
|
|
91
|
+
*/
|
|
92
|
+
function configRelativePath(path) {
|
|
93
|
+
const configDir = getOptionalEvalContext()?.configDir;
|
|
94
|
+
if (!configDir) {
|
|
95
|
+
throw new Error(`home.symlink("${path}"): config-relative paths need the config directory; ` +
|
|
96
|
+
"evaluate the workspace through the Winix CLI");
|
|
97
|
+
}
|
|
98
|
+
const base = configDir.replace(/\\/g, "/");
|
|
99
|
+
return pathPosix.normalize(pathPosix.join(base, path)).replace(/\/+$/, "");
|
|
100
|
+
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { account } from "./account.js";
|
|
2
2
|
export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, AccountNamespace, AccountOpts, AccountUserFactory, AccountUserRef, } from "./account.js";
|
|
3
3
|
export { platforms } from "./platforms.js";
|
|
4
|
-
export type { DarwinPlatformOpts, NixosPlatformOpts, WindowsPlatformOpts, PlatformsHelper } from "./platforms.js";
|
|
4
|
+
export type { DarwinPlatformOpts, NixosPlatformOpts, WindowsPlatformOpts, WslPlatformOpts, PlatformsHelper } from "./platforms.js";
|
|
5
5
|
export { nix } from "./nix.js";
|
|
6
6
|
export type { BinaryReleaseArch, BinaryReleaseCompletions, BinaryReleaseFormat, BinaryReleaseMeta, BinaryReleaseOpts, BinaryReleasePlatform, NixNamespace, PkgHelper, ScriptHelper, } from "./nix.js";
|
|
7
7
|
export { overlay } from "./overlay.js";
|
|
@@ -13,4 +13,4 @@ export type { NixosHelper, NixosProgramOptions, NixosServiceOptions, SysctlSetti
|
|
|
13
13
|
export { darwin } from "./darwin.js";
|
|
14
14
|
export type { DarwinHelper, DarwinProgramOptions, DarwinServiceOptions, LaunchdHelper } from "./darwin.js";
|
|
15
15
|
export { windows } from "./windows.js";
|
|
16
|
-
export type { WindowsHelper, WinDscSpec, WinEnvNamespace, WinEnvOpts, WinEnvScope, WinFileEncoding, WinFileNamespace, WinFileOpts, WinPackageArg, WinPackageSpec, WinPathNamespace, WinRawCommandArg, WinRawCommandSpec, WinSettingOpts, WinPowerShellModuleOpts, WinStartupCommandSpec, WinStartupNamespace, WinOptionalFeatureOpts, WinWslDistroSpec, WinWslOpts, WinWslNamespace, } from "./windows.js";
|
|
16
|
+
export type { WindowsHelper, WinDscSpec, WinEnvNamespace, WinEnvOpts, WinEnvScope, WinFileEncoding, WinFileNamespace, WinFileOpts, WinPackageArg, WinPackageSpec, WinPathNamespace, WinRawCommandArg, WinRawCommandSpec, WinSettingOpts, WinPowerShellModuleOpts, WinStartupCommandSpec, WinStartupNamespace, WinOptionalFeatureOpts, WinWslDistroSpec, WinWslSetupSpec, WinWslOpts, WinWslNamespace, } from "./windows.js";
|
package/dist/helpers/nix.d.ts
CHANGED
|
@@ -69,6 +69,20 @@ export interface NixNamespace {
|
|
|
69
69
|
* @see {@link BinaryReleaseOpts} for the full options interface
|
|
70
70
|
*/
|
|
71
71
|
binaryRelease(opts: BinaryReleaseOpts): NixExpr;
|
|
72
|
+
/** Helpers for NixOS-WSL hosts reaching into Windows. */
|
|
73
|
+
wsl: {
|
|
74
|
+
/**
|
|
75
|
+
* Package with `bin/<name>`: a shim that runs the first existing Windows
|
|
76
|
+
* executable among `paths`. Paths are absolute (`C:\\...`) or start with
|
|
77
|
+
* an environment variable (`%LOCALAPPDATA%\\...`), resolved through interop
|
|
78
|
+
* on each run, so no Windows user name or drive is hard-coded.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* home.packages(nix.wsl.windowsBin("code-insiders",
|
|
82
|
+
* "%LOCALAPPDATA%\\Programs\\Microsoft VS Code Insiders\\bin\\code-insiders"));
|
|
83
|
+
*/
|
|
84
|
+
windowsBin(name: string, paths: string | readonly string[]): NixExpr;
|
|
85
|
+
};
|
|
72
86
|
lib: {
|
|
73
87
|
mkDefault(value: NixValue): NixExpr;
|
|
74
88
|
mkForce(value: NixValue): NixExpr;
|
package/dist/helpers/nix.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { escapeNixDoubleQuoted, nixStringLiteral } from "../nix/serialize.js";
|
|
2
|
+
import { windowsBin } from "./wsl-interop.js";
|
|
2
3
|
const expr = (value) => ({ __winixNixExpr: true, expr: value });
|
|
3
4
|
const pkg = Object.assign((name) => expr(`pkgs.${name}`), {
|
|
4
5
|
stable: (name) => expr(`pkgs.stable.${name}`),
|
|
@@ -55,6 +56,7 @@ export const nix = {
|
|
|
55
56
|
isDarwin: expr("pkgs.stdenv.isDarwin"),
|
|
56
57
|
isLinux: expr("pkgs.stdenv.isLinux"),
|
|
57
58
|
binaryRelease,
|
|
59
|
+
wsl: { windowsBin },
|
|
58
60
|
lib: {
|
|
59
61
|
mkDefault: (value) => nixLibCall("mkDefault", value),
|
|
60
62
|
mkForce: (value) => nixLibCall("mkForce", value),
|
|
@@ -14,12 +14,25 @@ export interface DarwinPlatformOpts {
|
|
|
14
14
|
homebrew?: boolean;
|
|
15
15
|
hostname?: string | false;
|
|
16
16
|
}
|
|
17
|
+
export interface WslPlatformOpts extends NixosPlatformOpts {
|
|
18
|
+
/**
|
|
19
|
+
* Nix input name providing NixOS-WSL, as it appears in `inputs.<name>`.
|
|
20
|
+
* Defaults to "nixos-wsl" (the kebab-case name of a `nixosWsl` input).
|
|
21
|
+
*/
|
|
22
|
+
input?: string;
|
|
23
|
+
}
|
|
17
24
|
export interface WindowsPlatformOpts {
|
|
18
25
|
/** Hostname override; falls back to the host name from eval context. */
|
|
19
26
|
hostname?: string | false;
|
|
20
27
|
}
|
|
21
28
|
export interface PlatformsHelper {
|
|
22
29
|
nixos: PlatformFactory<[opts?: NixosPlatformOpts]>;
|
|
30
|
+
/**
|
|
31
|
+
* NixOS running under WSL: imports the NixOS-WSL module and enables it.
|
|
32
|
+
* The host is still a NixOS host, so `platforms.nixos.isActive` is also
|
|
33
|
+
* true; `platforms.wsl.isActive` is true only for WSL hosts.
|
|
34
|
+
*/
|
|
35
|
+
wsl: PlatformFactory<[opts?: WslPlatformOpts]>;
|
|
23
36
|
darwin: PlatformFactory<[opts?: DarwinPlatformOpts]>;
|
|
24
37
|
windows: PlatformFactory<[opts?: WindowsPlatformOpts]>;
|
|
25
38
|
}
|
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
import { platform, getOptionalEvalContext } from "../sdk/index.js";
|
|
2
|
+
function nixosPlatform(opts) {
|
|
3
|
+
const ctx = getOptionalEvalContext();
|
|
4
|
+
const hostname = opts.hostname === false ? undefined : opts.hostname ?? ctx?.hostname;
|
|
5
|
+
const useHomeManager = opts.homeManager ?? true;
|
|
6
|
+
return {
|
|
7
|
+
nixos: {
|
|
8
|
+
...(useHomeManager && { imports: ["inputs.home-manager.nixosModules.home-manager"] }),
|
|
9
|
+
nixpkgs: {
|
|
10
|
+
hostPlatform: opts.system ?? "x86_64-linux",
|
|
11
|
+
config: { allowUnfree: opts.allowUnfree ?? true },
|
|
12
|
+
},
|
|
13
|
+
nix: { settings: { experimentalFeatures: ["nix-command", "flakes"] } },
|
|
14
|
+
...(hostname && { networking: { hostName: hostname } }),
|
|
15
|
+
...(opts.stateVersion && { system: { stateVersion: opts.stateVersion } }),
|
|
16
|
+
...(useHomeManager && {
|
|
17
|
+
homeManager: {
|
|
18
|
+
useGlobalPkgs: true,
|
|
19
|
+
useUserPackages: true,
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
2
25
|
export const platforms = {
|
|
3
|
-
nixos: platform("nixos", (opts = {}) =>
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
26
|
+
nixos: platform("nixos", (opts = {}) => nixosPlatform(opts)),
|
|
27
|
+
wsl: platform("nixos", (opts = {}) => {
|
|
28
|
+
const { input = "nixos-wsl", ...nixosOpts } = opts;
|
|
29
|
+
if (typeof input !== "string" || !/^[A-Za-z_][A-Za-z0-9_'-]*$/.test(input)) {
|
|
30
|
+
throw new Error("platforms.wsl input must be a Nix input name, e.g. \"nixos-wsl\"");
|
|
31
|
+
}
|
|
32
|
+
const base = nixosPlatform(nixosOpts);
|
|
33
|
+
const imports = base.nixos?.imports ?? [];
|
|
7
34
|
return {
|
|
8
35
|
nixos: {
|
|
9
|
-
...
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
config: { allowUnfree: opts.allowUnfree ?? true },
|
|
13
|
-
},
|
|
14
|
-
nix: { settings: { experimentalFeatures: ["nix-command", "flakes"] } },
|
|
15
|
-
...(hostname && { networking: { hostName: hostname } }),
|
|
16
|
-
...(opts.stateVersion && { system: { stateVersion: opts.stateVersion } }),
|
|
17
|
-
...(useHomeManager && {
|
|
18
|
-
homeManager: {
|
|
19
|
-
useGlobalPkgs: true,
|
|
20
|
-
useUserPackages: true,
|
|
21
|
-
},
|
|
22
|
-
}),
|
|
36
|
+
...base.nixos,
|
|
37
|
+
imports: [...imports, `inputs.${input}.nixosModules.wsl`],
|
|
38
|
+
wsl: { enable: true },
|
|
23
39
|
},
|
|
24
40
|
};
|
|
25
|
-
}),
|
|
41
|
+
}, { variant: "wsl" }),
|
|
26
42
|
darwin: platform("darwin", (opts = {}) => {
|
|
27
43
|
const ctx = getOptionalEvalContext();
|
|
28
44
|
const hostname = opts.hostname === false ? undefined : opts.hostname ?? ctx?.hostname;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Fragment, ResourceHandle } from "../core/types.js";
|
|
1
|
+
import type { Fragment, HostDef, ResourceHandle } from "../core/types.js";
|
|
2
|
+
import type { AccountUserRef } from "./account.js";
|
|
2
3
|
import type { WinDscProperties, WinDscResource, WinPackageSource, WinSettings, WinFilePath, WinKnownFolder, WinKnownFolderName, WinStartupCommand, WinWslConfig, WinWslDistro, WinWslSetup, WinPowerShellRepositoryPolicy, WinFontSource, WinWallpaper, WinPersonalization } from "../types/index.js";
|
|
3
4
|
import type { WinNpmRegistryPolicy } from "../types/windows.js";
|
|
4
5
|
/**
|
|
@@ -67,8 +68,32 @@ export interface WinOptionalFeatureOpts {
|
|
|
67
68
|
enabled?: boolean;
|
|
68
69
|
dependsOn?: ResourceHandle | ResourceHandle[];
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Authoring form of a distro's first-run `setup`. Accepts host/account values
|
|
73
|
+
* instead of matching strings, and `repository: "self"` to clone the
|
|
74
|
+
* checkout that holds winix.config.ts.
|
|
75
|
+
*/
|
|
76
|
+
export interface WinWslSetupSpec extends Omit<WinWslSetup, "repository" | "configDirectory" | "host" | "user"> {
|
|
77
|
+
/**
|
|
78
|
+
* HTTPS Git URL, or "self": use the tracked remote of the checkout holding
|
|
79
|
+
* winix.config.ts (SSH remotes are converted to HTTPS). With "self", `ref`
|
|
80
|
+
* defaults to the current upstream branch (or commit when detached) and
|
|
81
|
+
* `configDirectory` to the config's path within the repository.
|
|
82
|
+
*/
|
|
83
|
+
repository: string;
|
|
84
|
+
/** Required unless `repository` is "self". */
|
|
85
|
+
configDirectory?: string;
|
|
86
|
+
/** Linux host to activate: its name, or the value returned by `host(...)`. */
|
|
87
|
+
host: string | HostDef;
|
|
88
|
+
/** Linux account: its name, or the factory returned by `account.user(...)`. */
|
|
89
|
+
user?: string | AccountUserRef;
|
|
90
|
+
}
|
|
91
|
+
export interface WinWslDistroSpec extends Omit<WinWslDistro, "name" | "default" | "host" | "setup" | "setupRefFromCheckout"> {
|
|
71
92
|
default?: boolean;
|
|
93
|
+
/** Expected Linux hostname for adoption (a name or `host(...)` value); defaults to setup.host. */
|
|
94
|
+
host?: string | HostDef;
|
|
95
|
+
/** First-run setup for Winix-created distros; never run for adopted distros. */
|
|
96
|
+
setup?: WinWslSetupSpec;
|
|
72
97
|
dependsOn?: ResourceHandle | ResourceHandle[];
|
|
73
98
|
}
|
|
74
99
|
export interface WinWslOpts extends Pick<WinFileOpts, "backup" | "force" | "dependsOn"> {
|
|
@@ -228,4 +253,12 @@ export interface WindowsHelper {
|
|
|
228
253
|
file: WinFileNamespace;
|
|
229
254
|
}
|
|
230
255
|
export declare const windows: WindowsHelper;
|
|
256
|
+
/**
|
|
257
|
+
* Resolve the authoring form of a WSL setup into its normalized, concrete
|
|
258
|
+
* shape. `repository: "self"` reads the config checkout (local Git only).
|
|
259
|
+
*/
|
|
260
|
+
export declare function resolveWslSetupSpec(spec: WinWslSetupSpec): {
|
|
261
|
+
setup: WinWslSetup;
|
|
262
|
+
refFromCheckout: boolean;
|
|
263
|
+
};
|
|
231
264
|
export declare function normalizeWslSetup(setup: WinWslSetup): WinWslSetup;
|