@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
package/dist/helpers/windows.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// MVP vertical slice: packages plus raw commands. Mirrors the shape and
|
|
4
4
|
// naming of the `nixos.*` / `darwin.*` namespaces. Additional helpers
|
|
5
5
|
// (env, path, file, dsc, wsl, programs) land in follow-up milestones.
|
|
6
|
+
import { getOptionalEvalContext } from "../sdk/index.js";
|
|
7
|
+
import { inferWslSetupRepository } from "./wsl-repository.js";
|
|
6
8
|
import { resolve, win32, posix } from "node:path";
|
|
7
9
|
import { fileURLToPath } from "node:url";
|
|
8
10
|
import { powerShellLiteral as psSingleQuoted } from "./utils.js";
|
|
@@ -1001,18 +1003,20 @@ export const windows = {
|
|
|
1001
1003
|
(spec.default !== undefined && typeof spec.default !== "boolean")) {
|
|
1002
1004
|
throw new Error("windows.wsl.distro requires source 'nixos-wsl', an absolute/environment/known-folder installLocation, and an optional boolean default");
|
|
1003
1005
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
+
const expectedHost = spec.host === undefined ? undefined : hostName(spec.host, "windows.wsl.distro host");
|
|
1007
|
+
if (expectedHost !== undefined && !/^[a-z0-9][a-z0-9._-]*$/i.test(expectedHost)) {
|
|
1006
1008
|
throw new Error("windows.wsl.distro host must be a valid expected Linux hostname");
|
|
1007
1009
|
}
|
|
1010
|
+
const setup = spec.setup === undefined ? undefined : resolveWslSetupSpec(spec.setup);
|
|
1008
1011
|
return dscHandle(withDscMetadata(withDscToken({
|
|
1009
1012
|
resourceType: POWERSHELL_SCRIPT_RESOURCE,
|
|
1010
1013
|
name: `WSL distro ${name}`,
|
|
1011
1014
|
dependsOn: resolveDependsOn(spec.dependsOn),
|
|
1012
1015
|
}), { kind: "wsl-distro", distro: {
|
|
1013
1016
|
name, source: spec.source, installLocation: spec.installLocation, default: spec.default ?? false,
|
|
1014
|
-
...(
|
|
1015
|
-
...(
|
|
1017
|
+
...(expectedHost === undefined ? {} : { host: expectedHost }),
|
|
1018
|
+
...(setup === undefined ? {} : { setup: setup.setup }),
|
|
1019
|
+
...(setup?.refFromCheckout ? { setupRefFromCheckout: true } : {}),
|
|
1016
1020
|
} }));
|
|
1017
1021
|
},
|
|
1018
1022
|
}),
|
|
@@ -1111,6 +1115,53 @@ export const windows = {
|
|
|
1111
1115
|
remove: (target, opts) => dscHandle(normalizeFileRemove(target, opts)),
|
|
1112
1116
|
},
|
|
1113
1117
|
};
|
|
1118
|
+
function hostName(value, label) {
|
|
1119
|
+
if (typeof value === "string")
|
|
1120
|
+
return value;
|
|
1121
|
+
if (value && typeof value === "object" && typeof value.name === "string" && value.platform)
|
|
1122
|
+
return value.name;
|
|
1123
|
+
throw new Error(`${label} must be a host name or a host(...) value`);
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Resolve the authoring form of a WSL setup into its normalized, concrete
|
|
1127
|
+
* shape. `repository: "self"` reads the config checkout (local Git only).
|
|
1128
|
+
*/
|
|
1129
|
+
export function resolveWslSetupSpec(spec) {
|
|
1130
|
+
if (!spec || typeof spec !== "object" || Array.isArray(spec)) {
|
|
1131
|
+
throw new Error("windows.wsl.distro setup must be an object");
|
|
1132
|
+
}
|
|
1133
|
+
const host = hostName(spec.host, "WSL setup host");
|
|
1134
|
+
let user;
|
|
1135
|
+
if (spec.user === undefined || typeof spec.user === "string")
|
|
1136
|
+
user = spec.user;
|
|
1137
|
+
else if ((typeof spec.user === "object" || typeof spec.user === "function") &&
|
|
1138
|
+
spec.user.kind === "account.user" && typeof spec.user.name === "string")
|
|
1139
|
+
user = spec.user.name;
|
|
1140
|
+
else
|
|
1141
|
+
throw new Error("WSL setup user must be a Linux account name or an account.user(...) value");
|
|
1142
|
+
let { repository, ref, configDirectory } = spec;
|
|
1143
|
+
let refFromCheckout = false;
|
|
1144
|
+
if (repository === "self") {
|
|
1145
|
+
const configDir = getOptionalEvalContext()?.configDir;
|
|
1146
|
+
if (!configDir) {
|
|
1147
|
+
throw new Error('WSL setup repository "self" needs the config directory; evaluate the workspace through the Winix CLI');
|
|
1148
|
+
}
|
|
1149
|
+
const inferred = inferWslSetupRepository(configDir);
|
|
1150
|
+
repository = inferred.repository;
|
|
1151
|
+
refFromCheckout = ref === undefined;
|
|
1152
|
+
ref ??= inferred.ref;
|
|
1153
|
+
configDirectory ??= inferred.configDirectory;
|
|
1154
|
+
}
|
|
1155
|
+
if (configDirectory === undefined) {
|
|
1156
|
+
throw new Error('WSL setup configDirectory is required unless repository is "self"');
|
|
1157
|
+
}
|
|
1158
|
+
return {
|
|
1159
|
+
setup: normalizeWslSetup({
|
|
1160
|
+
...spec, repository, ref, configDirectory, host, ...(user === undefined ? {} : { user }),
|
|
1161
|
+
}),
|
|
1162
|
+
refFromCheckout,
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1114
1165
|
export function normalizeWslSetup(setup) {
|
|
1115
1166
|
if (!setup || typeof setup !== "object" || Array.isArray(setup)) {
|
|
1116
1167
|
throw new Error("windows.wsl.distro setup must be an object");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NixExpr } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default Git Credential Manager locations shipped with Git for Windows.
|
|
4
|
+
*/
|
|
5
|
+
export declare const GIT_CREDENTIAL_MANAGER_PATHS: readonly ["%ProgramFiles%\\Git\\ucrt64\\bin\\git-credential-manager.exe", "%ProgramFiles%\\Git\\mingw64\\bin\\git-credential-manager.exe"];
|
|
6
|
+
/**
|
|
7
|
+
* Build a package containing `bin/<name>`, a shell shim that resolves the
|
|
8
|
+
* first existing Windows path among `targets` and execs it with all arguments.
|
|
9
|
+
* Targets are Windows paths, absolute (`C:\...`) or starting with an
|
|
10
|
+
* environment variable (`%LOCALAPPDATA%\...`), expanded through `cmd.exe`
|
|
11
|
+
* interop at run time and converted with `wslpath`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function windowsBin(name: string, targets: string | readonly string[]): NixExpr;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// WSL → Windows interop helpers: shims that locate Windows executables at
|
|
2
|
+
// runtime, so Linux configs never hard-code the Windows user or drive layout.
|
|
3
|
+
import { nixStringLiteral } from "../nix/serialize.js";
|
|
4
|
+
/**
|
|
5
|
+
* Default Git Credential Manager locations shipped with Git for Windows.
|
|
6
|
+
*/
|
|
7
|
+
export const GIT_CREDENTIAL_MANAGER_PATHS = [
|
|
8
|
+
"%ProgramFiles%\\Git\\ucrt64\\bin\\git-credential-manager.exe",
|
|
9
|
+
"%ProgramFiles%\\Git\\mingw64\\bin\\git-credential-manager.exe",
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* Build a package containing `bin/<name>`, a shell shim that resolves the
|
|
13
|
+
* first existing Windows path among `targets` and execs it with all arguments.
|
|
14
|
+
* Targets are Windows paths, absolute (`C:\...`) or starting with an
|
|
15
|
+
* environment variable (`%LOCALAPPDATA%\...`), expanded through `cmd.exe`
|
|
16
|
+
* interop at run time and converted with `wslpath`.
|
|
17
|
+
*/
|
|
18
|
+
export function windowsBin(name, targets) {
|
|
19
|
+
if (typeof name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._+-]*$/.test(name)) {
|
|
20
|
+
throw new Error("nix.wsl.windowsBin requires an executable name containing only letters, numbers, '.', '_', '+' or '-'");
|
|
21
|
+
}
|
|
22
|
+
const list = (typeof targets === "string" ? [targets] : [...(targets ?? [])]).map(normalizeWindowsTarget);
|
|
23
|
+
if (list.length === 0)
|
|
24
|
+
throw new Error(`nix.wsl.windowsBin("${name}") requires at least one Windows path`);
|
|
25
|
+
const quoted = list.map((target) => `'${target}'`).join(" ");
|
|
26
|
+
const script = [
|
|
27
|
+
"wslpath=/bin/wslpath",
|
|
28
|
+
`[ -x "$wslpath" ] || wslpath=$(command -v wslpath) || { echo '${name}: wslpath not found; this shim only works inside WSL' >&2; exit 127; }`,
|
|
29
|
+
`cmd=$("$wslpath" -u 'C:\\Windows\\System32\\cmd.exe' 2>/dev/null)`,
|
|
30
|
+
"resolve() {",
|
|
31
|
+
' local win=$1',
|
|
32
|
+
' case "$win" in',
|
|
33
|
+
" *%*)",
|
|
34
|
+
' [ -n "$cmd" ] && [ -x "$cmd" ] || return 1',
|
|
35
|
+
// cmd.exe cannot run from a WSL (UNC) working directory.
|
|
36
|
+
' win=$(cd "${cmd%/*}" && "$cmd" /d /c "echo $win" 2>/dev/null) || return 1',
|
|
37
|
+
" win=${win%$'\\r'}",
|
|
38
|
+
" case \"$win\" in *%*) return 1 ;; esac",
|
|
39
|
+
" ;;",
|
|
40
|
+
" esac",
|
|
41
|
+
' "$wslpath" -u "$win" 2>/dev/null',
|
|
42
|
+
"}",
|
|
43
|
+
`for candidate in ${quoted}; do`,
|
|
44
|
+
' if target=$(resolve "$candidate") && [ -n "$target" ] && [ -f "$target" ]; then',
|
|
45
|
+
' exec "$target" "$@"',
|
|
46
|
+
" fi",
|
|
47
|
+
"done",
|
|
48
|
+
`echo '${name}: Windows executable not found at: ${list.join(", ")}' >&2`,
|
|
49
|
+
"exit 127",
|
|
50
|
+
].join("\n");
|
|
51
|
+
return {
|
|
52
|
+
__winixNixExpr: true,
|
|
53
|
+
expr: `(pkgs.writeShellScriptBin ${nixStringLiteral(name)} ''\n${escapeIndentedString(script)}\n'')`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function normalizeWindowsTarget(target) {
|
|
57
|
+
if (typeof target !== "string")
|
|
58
|
+
throw new Error("nix.wsl.windowsBin paths must be strings");
|
|
59
|
+
const path = target.replace(/\//g, "\\");
|
|
60
|
+
if (!/^(?:[A-Za-z]:\\|%[A-Za-z_][A-Za-z0-9_()]*%\\)/.test(path)) {
|
|
61
|
+
throw new Error(`nix.wsl.windowsBin path "${target}" must be absolute (C:\\...) or start with an environment variable (%LOCALAPPDATA%\\...)`);
|
|
62
|
+
}
|
|
63
|
+
// Paths are embedded in single-quoted shell words and echoed through cmd.exe.
|
|
64
|
+
if (/['"&|<>^\r\n\0`]/.test(path)) {
|
|
65
|
+
throw new Error(`nix.wsl.windowsBin path "${target}" contains unsupported characters`);
|
|
66
|
+
}
|
|
67
|
+
return path;
|
|
68
|
+
}
|
|
69
|
+
/** Escape text for a Nix indented string (`'' ... ''`). */
|
|
70
|
+
function escapeIndentedString(text) {
|
|
71
|
+
return text.replace(/''/g, "'''").replace(/\$\{/g, "''${");
|
|
72
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface InferredWslRepository {
|
|
2
|
+
/** HTTPS clone URL of the tracked remote. */
|
|
3
|
+
repository: string;
|
|
4
|
+
/** Upstream branch name, or the commit when HEAD is detached. */
|
|
5
|
+
ref: string;
|
|
6
|
+
/** Config directory relative to the repository root, POSIX separators. */
|
|
7
|
+
configDirectory: string;
|
|
8
|
+
}
|
|
9
|
+
export type GitRunner = (args: string[], cwd: string) => string;
|
|
10
|
+
export declare function inferWslSetupRepository(configDir: string, git?: GitRunner): InferredWslRepository;
|
|
11
|
+
/** Convert common Git remote forms (HTTPS with userinfo, scp-like SSH, ssh://) to an HTTPS clone URL. */
|
|
12
|
+
export declare function httpsCloneUrl(url: string, context?: string): string;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Infers a WSL setup repository from the Git checkout that holds winix.config.ts
|
|
2
|
+
// (`setup: { repository: "self" }`). Only local, read-only Git queries run here;
|
|
3
|
+
// the commit pin is still resolved against the remote into winix-windows.lock.
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { realpathSync } from "node:fs";
|
|
6
|
+
import { relative, sep } from "node:path";
|
|
7
|
+
const runGit = (args, cwd) => execFileSync("git", args, {
|
|
8
|
+
cwd, encoding: "utf8", timeout: 15000, stdio: ["ignore", "pipe", "pipe"],
|
|
9
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
|
|
10
|
+
}).trim();
|
|
11
|
+
function tryGit(git, args, cwd) {
|
|
12
|
+
try {
|
|
13
|
+
return git(args, cwd) || undefined;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function inferWslSetupRepository(configDir, git = runGit) {
|
|
20
|
+
const context = `setup.repository "self" (config directory ${configDir})`;
|
|
21
|
+
let toplevel;
|
|
22
|
+
try {
|
|
23
|
+
toplevel = git(["rev-parse", "--show-toplevel"], configDir);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new Error(`${context}: not inside a Git checkout`, { cause: error });
|
|
27
|
+
}
|
|
28
|
+
const branch = tryGit(git, ["symbolic-ref", "--quiet", "--short", "HEAD"], configDir);
|
|
29
|
+
let remote = "origin";
|
|
30
|
+
let ref;
|
|
31
|
+
if (branch) {
|
|
32
|
+
const upstreamRemote = tryGit(git, ["config", "--get", `branch.${branch}.remote`], configDir);
|
|
33
|
+
const upstreamMerge = tryGit(git, ["config", "--get", `branch.${branch}.merge`], configDir);
|
|
34
|
+
if (upstreamRemote && upstreamRemote !== "." && upstreamMerge?.startsWith("refs/heads/")) {
|
|
35
|
+
remote = upstreamRemote;
|
|
36
|
+
ref = upstreamMerge.slice("refs/heads/".length);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
ref = branch;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
ref = git(["rev-parse", "HEAD"], configDir);
|
|
44
|
+
}
|
|
45
|
+
const url = tryGit(git, ["remote", "get-url", remote], configDir);
|
|
46
|
+
if (!url)
|
|
47
|
+
throw new Error(`${context}: the checkout has no "${remote}" remote to clone from`);
|
|
48
|
+
return {
|
|
49
|
+
repository: httpsCloneUrl(url, context),
|
|
50
|
+
ref,
|
|
51
|
+
configDirectory: configDirectoryWithin(toplevel, configDir, context),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Convert common Git remote forms (HTTPS with userinfo, scp-like SSH, ssh://) to an HTTPS clone URL. */
|
|
55
|
+
export function httpsCloneUrl(url, context = "setup.repository") {
|
|
56
|
+
const trimmed = url.trim();
|
|
57
|
+
const azureSsh = /^(?:ssh:\/\/)?[^@/]+@ssh\.dev\.azure\.com(?::22)?[:/]v3\/([^/]+)\/([^/]+)\/([^/]+?)\/?$/.exec(trimmed);
|
|
58
|
+
if (azureSsh) {
|
|
59
|
+
const [, org, project, repo] = azureSsh;
|
|
60
|
+
return `https://dev.azure.com/${org}/${project}/_git/${repo}`;
|
|
61
|
+
}
|
|
62
|
+
const scp = /^[^@/\s]+@([^:/\s]+):(?!\/)(.+)$/.exec(trimmed);
|
|
63
|
+
if (scp)
|
|
64
|
+
return `https://${scp[1]}/${scp[2]}`;
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = new URL(trimmed);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new Error(`${context}: remote URL "${trimmed}" is not an HTTPS or SSH Git URL`);
|
|
71
|
+
}
|
|
72
|
+
if (parsed.protocol === "ssh:")
|
|
73
|
+
return `https://${parsed.hostname}${parsed.pathname}`;
|
|
74
|
+
if (parsed.protocol !== "https:") {
|
|
75
|
+
throw new Error(`${context}: remote URL "${trimmed}" must use HTTPS or SSH; set setup.repository explicitly`);
|
|
76
|
+
}
|
|
77
|
+
parsed.username = "";
|
|
78
|
+
parsed.password = "";
|
|
79
|
+
return parsed.href;
|
|
80
|
+
}
|
|
81
|
+
function configDirectoryWithin(toplevel, configDir, context) {
|
|
82
|
+
const real = (path) => { try {
|
|
83
|
+
return realpathSync(path);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return path;
|
|
87
|
+
} };
|
|
88
|
+
const inside = relative(real(toplevel), real(configDir));
|
|
89
|
+
if (inside.startsWith("..") || /^[a-z]:/i.test(inside) || inside.startsWith(sep)) {
|
|
90
|
+
throw new Error(`${context}: config directory is outside the repository root ${toplevel}`);
|
|
91
|
+
}
|
|
92
|
+
return inside === "" ? "." : inside.split(sep).join("/");
|
|
93
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Fragment, ResourceHandle, FragmentFactory, PlatformFactory, ProfileFactory, LazyFragment, PlatformLazyFragment, FragmentEntry, FragmentResult, NixExpr, RawModuleRef, ImportRef, InputDef, InputWithOptions, WorkspaceDef, HostDef, EvalContext } from "./core/types.js";
|
|
1
|
+
export type { Fragment, ResourceHandle, FragmentFactory, PlatformFactory, ProfileFactory, LazyFragment, PlatformLazyFragment, FragmentEntry, FragmentResult, NixExpr, RawModuleRef, ImportRef, InputDef, InputWithOptions, WorkspaceDef, HostDef, EvalContext, EvaluateOptions } from "./core/types.js";
|
|
2
2
|
export type { Attrs, BootOptions, DarwinNetworking, DarwinOptions, DarwinSecurity, DarwinDefaults, DarwinSystem, EnvironmentOptions, FirewallOptions, FontsOptions, FzfOptions, GitInclude, GitOptions, HomeActivation, HomebrewOptions, HomeConfig, HomeFile, HomeOptions, I18nOptions, LaunchdAgentOptions, LaunchdOptions, NeovimOptions, NetworkingOptions, NixConfig, NixGcOptions, NixHomebrewOptions, NixOptions, NixpkgsOptions, NixosSecurityOptions, NixosSystemOptions, NixPrimitive, NixSettings, NixValue, NixosOptions, OciContainerOptions, PackageRef, Script, ServicesOptions, StarshipOptions, SystemdOptions, SystemdService, SystemdTimer, TimeOptions, TmuxOptions, UserOptions, UsersOptions, VirtualisationOptions, WslOptions, XdgFile, XdgOptions, ZoxideOptions, ZshOptions, WindowsOptions, WinPackage, WinPackageSource, WinRawCommand, WinSettings, WinFontSource, WinWallpaper, WinPersonalization, WinColorMode, WinStartFolder, WinTaskbarAlignment, WinTaskbarGroupingMode, WinTaskbarMultiMonMode, WinKnownFolder, WinKnownFolderName, WinFilePath, WinPowerShellModule, WinPowerShellRepositoryPolicy, WinNpmRegistryPolicy, WinStartupCommand, WinStartupWindowStyle, } from "./types/index.js";
|
|
3
3
|
export { platform, feature, profile, host, workspace, input, defineInputs, rawModule, withContext } from "./sdk/index.js";
|
|
4
4
|
export type { WinixContext } from "./sdk/context.js";
|
|
@@ -9,6 +9,6 @@ export type { NixOutput } from "./backends/nix/index.js";
|
|
|
9
9
|
export { generateWindows, isWindowsHost } from "./backends/windows/index.js";
|
|
10
10
|
export type { WindowsOutput, WindowsHostOutput } from "./backends/windows/index.js";
|
|
11
11
|
export { account, darwin, home, nix, nixos, overlay, platforms, windows } from "./helpers/index.js";
|
|
12
|
-
export type { WinPowerShellModuleOpts, WinStartupCommandSpec, WinStartupNamespace, WinOptionalFeatureOpts, WinWslDistroSpec, WinWslOpts, WinWslNamespace } from "./helpers/index.js";
|
|
12
|
+
export type { WinPowerShellModuleOpts, WinStartupCommandSpec, WinStartupNamespace, WinOptionalFeatureOpts, WinWslDistroSpec, WinWslSetupSpec, WinWslOpts, WinWslNamespace } from "./helpers/index.js";
|
|
13
13
|
export type { WinWslConfig, WinWslDistro, WinWslSetup } from "./types/index.js";
|
|
14
|
-
export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, AccountNamespace, AccountOpts, AccountUserFactory, AccountUserRef, ActivationOpts, BinaryReleaseArch, BinaryReleaseCompletions, BinaryReleaseFormat, BinaryReleaseMeta, BinaryReleaseOpts, BinaryReleasePlatform, DarwinHelper, DarwinPlatformOpts, DarwinProgramOptions, DarwinServiceOptions, HomeHelper, HomeProgramOptions, HomeServiceOptions, LaunchdHelper, NixNamespace, NixosHelper, NixosPlatformOpts, NixosProgramOptions, NixosServiceOptions, OverlayHelper, PkgHelper, PlatformsHelper, ScriptHelper, SysctlSettings, SystemdHelper, VirtualisationHelper, WindowsHelper, WindowsPlatformOpts, WinEnvNamespace, WinEnvOpts, WinEnvScope, WinFileEncoding, WinFileNamespace, WinFileOpts, WinPackageArg, WinPackageSpec, WinPathNamespace, WinRawCommandArg, WinRawCommandSpec, WinSettingOpts } from "./helpers/index.js";
|
|
14
|
+
export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, AccountNamespace, AccountOpts, AccountUserFactory, AccountUserRef, ActivationOpts, BinaryReleaseArch, BinaryReleaseCompletions, BinaryReleaseFormat, BinaryReleaseMeta, BinaryReleaseOpts, BinaryReleasePlatform, DarwinHelper, DarwinPlatformOpts, DarwinProgramOptions, DarwinServiceOptions, HomeHelper, HomeProgramOptions, HomeServiceOptions, LaunchdHelper, NixNamespace, NixosHelper, NixosPlatformOpts, NixosProgramOptions, NixosServiceOptions, OverlayHelper, PkgHelper, PlatformsHelper, ScriptHelper, SysctlSettings, SystemdHelper, VirtualisationHelper, WindowsHelper, WindowsPlatformOpts, WslPlatformOpts, WinEnvNamespace, WinEnvOpts, WinEnvScope, WinFileEncoding, WinFileNamespace, WinFileOpts, WinPackageArg, WinPackageSpec, WinPathNamespace, WinRawCommandArg, WinRawCommandSpec, WinSettingOpts } from "./helpers/index.js";
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export declare function restoreEvalContext(ctx: EvalContext | null): void;
|
|
|
5
5
|
export declare function clearEvalContext(): void;
|
|
6
6
|
export declare function getEvalContext(): EvalContext;
|
|
7
7
|
export declare function getOptionalEvalContext(): EvalContext | null;
|
|
8
|
-
export declare function platform<T extends unknown[]>(id: string, factory: (...args: T) => Fragment
|
|
8
|
+
export declare function platform<T extends unknown[]>(id: string, factory: (...args: T) => Fragment, options?: {
|
|
9
|
+
variant?: string;
|
|
10
|
+
}): PlatformFactory<T>;
|
|
9
11
|
export declare function feature<T extends unknown[]>(id: string, factory: (ctx: WinixContext, ...args: T) => AuthoringResult): FragmentFactory<T>;
|
|
10
12
|
export declare function profile(id: string, entries: readonly FragmentEntry[]): ProfileFactory<[]>;
|
|
11
13
|
export declare function host(name: string, platform: PlatformLazyFragment, fragments: readonly FragmentEntry[]): HostDef;
|
|
@@ -22,6 +24,8 @@ export declare const rawModule: RawModuleHelper;
|
|
|
22
24
|
export declare function escape(expr: string): NixExpr;
|
|
23
25
|
export declare function withContext<R>(ctx: {
|
|
24
26
|
platform: string;
|
|
27
|
+
variant?: string;
|
|
25
28
|
hostname?: string;
|
|
26
29
|
features?: string[];
|
|
30
|
+
configDir?: string;
|
|
27
31
|
}, fn: () => R): R;
|
package/dist/sdk/index.js
CHANGED
|
@@ -30,12 +30,14 @@ export function getOptionalEvalContext() {
|
|
|
30
30
|
return G.__winixEvalContext ?? null;
|
|
31
31
|
}
|
|
32
32
|
// --- platform() ---
|
|
33
|
-
export function platform(id, factory) {
|
|
33
|
+
export function platform(id, factory, options = {}) {
|
|
34
|
+
const { variant } = options;
|
|
34
35
|
const fn = ((...args) => {
|
|
35
36
|
return {
|
|
36
37
|
__lazy: true,
|
|
37
38
|
__id: id,
|
|
38
39
|
__platform: true,
|
|
40
|
+
...(variant === undefined ? {} : { __variant: variant }),
|
|
39
41
|
__resolve: () => {
|
|
40
42
|
const result = factory(...args);
|
|
41
43
|
return { ...result, __id: id, __platform: true };
|
|
@@ -43,7 +45,10 @@ export function platform(id, factory) {
|
|
|
43
45
|
};
|
|
44
46
|
});
|
|
45
47
|
Object.defineProperty(fn, "isActive", {
|
|
46
|
-
get: () =>
|
|
48
|
+
get: () => {
|
|
49
|
+
const ctx = getCtx();
|
|
50
|
+
return ctx.platform === id && (variant === undefined || ctx.variant === variant);
|
|
51
|
+
},
|
|
47
52
|
configurable: true,
|
|
48
53
|
enumerable: false,
|
|
49
54
|
});
|
|
@@ -258,8 +263,10 @@ export function withContext(ctx, fn) {
|
|
|
258
263
|
const prev = G.__winixEvalContext ?? null;
|
|
259
264
|
G.__winixEvalContext = {
|
|
260
265
|
platform: ctx.platform,
|
|
266
|
+
...(ctx.variant === undefined ? {} : { variant: ctx.variant }),
|
|
261
267
|
hostname: ctx.hostname ?? "test",
|
|
262
268
|
activeIds: new Set(ctx.features ?? []),
|
|
269
|
+
...(ctx.configDir === undefined ? {} : { configDir: ctx.configDir }),
|
|
263
270
|
};
|
|
264
271
|
try {
|
|
265
272
|
return fn();
|
package/dist/skill.js
CHANGED
|
@@ -150,8 +150,13 @@ Use one platform factory as the second argument to each host:
|
|
|
150
150
|
- \`platforms.nixos({ system, stateVersion, allowUnfree, homeManager, hostname })\`
|
|
151
151
|
- \`platforms.darwin({ system, stateVersion, allowUnfree, homeManager, homebrew, hostname })\`
|
|
152
152
|
- \`platforms.windows({ hostname })\`
|
|
153
|
+
- \`platforms.wsl({ stateVersion, input, ... })\` is NixOS under WSL: the NixOS
|
|
154
|
+
options plus the NixOS-WSL module import (\`inputs.nixos-wsl\` unless \`input\`
|
|
155
|
+
names another Nix input) and \`wsl.enable = true\`. Declare the input, e.g.
|
|
156
|
+
\`nixosWsl: input("github:nix-community/NixOS-WSL", { follows: { nixpkgs: "nixpkgs" } })\`.
|
|
153
157
|
|
|
154
|
-
The platform factories also expose \`.isActive\` during evaluation.
|
|
158
|
+
The platform factories also expose \`.isActive\` during evaluation. A WSL host is
|
|
159
|
+
still NixOS: \`platforms.nixos.isActive\` and \`platforms.wsl.isActive\` are both true.
|
|
155
160
|
|
|
156
161
|
## Fragment and merge rules
|
|
157
162
|
|
|
@@ -232,7 +237,11 @@ Available helpers:
|
|
|
232
237
|
- \`home.env()\` for \`home.sessionVariables\`
|
|
233
238
|
- \`home.path()\` for \`home.sessionPath\`
|
|
234
239
|
- \`home.files()\`, \`home.configFile()\`, and \`home.configFiles()\`
|
|
235
|
-
- \`home.symlink()\` for out-of-store symlink file values
|
|
240
|
+
- \`home.symlink()\` for out-of-store symlink file values: \`~/\` paths are
|
|
241
|
+
home-relative, \`./\` and \`../\` paths are relative to winix.config.ts (like
|
|
242
|
+
Windows file sources), e.g. \`home.symlink("../nvim/.config/nvim")\`
|
|
243
|
+
- \`home.wsl.gitCredentialManager({ paths })\` enables git and points
|
|
244
|
+
credential.helper at a shim for Git for Windows' Credential Manager
|
|
236
245
|
- \`home.activation(name, { after, script })\`
|
|
237
246
|
- \`home.raw()\` as a last-resort raw Nix escape hatch
|
|
238
247
|
|
|
@@ -370,6 +379,14 @@ Resources return handles that can be passed through \`dependsOn\`.
|
|
|
370
379
|
{ repository: "https://github.com/example/dotfiles.git", ref: "main",
|
|
371
380
|
configDirectory: "winix", host: "wsl-work", user: "alice",
|
|
372
381
|
checkout: "/home/alice/dotfiles" }.
|
|
382
|
+
Prefer values over matching strings: host accepts the value returned by
|
|
383
|
+
host(...) and user the account.user(...) factory. repository: "self" clones the
|
|
384
|
+
checkout holding winix.config.ts: its tracked remote (SSH converted to HTTPS),
|
|
385
|
+
current upstream branch as ref (commit when detached; excluded from the
|
|
386
|
+
completed-setup fingerprint) and config path as configDirectory. winix check
|
|
387
|
+
validates the whole setup plan offline (host, account, NixOS-WSL module,
|
|
388
|
+
stateVersion, checkout inside the home). After switch, Winix prints the
|
|
389
|
+
command that applies later Linux changes inside each distro.
|
|
373
390
|
Repository URLs must be HTTPS without credentials; authentication must already
|
|
374
391
|
work inside Linux. Commit flake.lock in configDirectory; npm-based Winix also
|
|
375
392
|
requires package.json/package-lock.json and a released SDK supporting setup.
|
|
@@ -519,6 +536,10 @@ Import \`nix\` at file scope. It builds values and does not declare fragments:
|
|
|
519
536
|
\`nix.optionalString()\` build common expressions.
|
|
520
537
|
- \`nix.isDarwin\` and \`nix.isLinux\` are Nix-side conditions.
|
|
521
538
|
- \`nix.binaryRelease()\` builds a package for a prebuilt CLI release.
|
|
539
|
+
- \`nix.wsl.windowsBin(name, paths)\` builds a package whose bin/<name> runs the
|
|
540
|
+
first existing Windows executable among paths (\`C:\\\\...\` or
|
|
541
|
+
\`%LOCALAPPDATA%\\\\...\`), resolved through interop at run time, e.g.
|
|
542
|
+
\`home.packages(nix.wsl.windowsBin("code", "%LOCALAPPDATA%\\\\Programs\\\\Microsoft VS Code\\\\bin\\\\code"))\`.
|
|
522
543
|
- \`nix.lib.mkDefault()\`, \`nix.lib.mkForce()\`, \`nix.lib.mkBefore()\`,
|
|
523
544
|
\`nix.lib.mkAfter()\`, \`nix.lib.optionalAttrs()\`, and
|
|
524
545
|
\`nix.lib.optionalString()\` expose common library operations.
|
package/dist/types/windows.d.ts
CHANGED
|
@@ -80,6 +80,12 @@ export interface WinWslDistro {
|
|
|
80
80
|
host?: string;
|
|
81
81
|
/** First-run setup for Winix-created distros; never run for adopted distros. */
|
|
82
82
|
setup?: WinWslSetup;
|
|
83
|
+
/**
|
|
84
|
+
* Internal: setup.ref was inferred from the config checkout's branch, so it
|
|
85
|
+
* is excluded from the completed-setup fingerprint (switching branches must
|
|
86
|
+
* not invalidate an already-completed distro).
|
|
87
|
+
*/
|
|
88
|
+
setupRefFromCheckout?: boolean;
|
|
83
89
|
}
|
|
84
90
|
export interface WinWslSetup {
|
|
85
91
|
/** Opts into executing trusted repository/npm code inside the distro. HTTPS only; never embed credentials. */
|
package/package.json
CHANGED