@adrifer/winix 0.1.2-preview.2 → 0.1.2-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/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/nix.d.ts +63 -0
- package/dist/helpers/nix.js +204 -0
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/helpers/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, Account
|
|
|
3
3
|
export { platforms } from "./platforms.js";
|
|
4
4
|
export type { DarwinPlatformOpts, NixosPlatformOpts, PlatformsHelper } from "./platforms.js";
|
|
5
5
|
export { nix } from "./nix.js";
|
|
6
|
-
export type { NixNamespace, PkgHelper, ScriptHelper } from "./nix.js";
|
|
6
|
+
export type { BinaryReleaseArch, BinaryReleaseCompletions, BinaryReleaseMeta, BinaryReleaseOpts, BinaryReleasePlatform, NixNamespace, PkgHelper, ScriptHelper, } from "./nix.js";
|
|
7
7
|
export { overlay } from "./overlay.js";
|
|
8
8
|
export type { OverlayHelper } from "./overlay.js";
|
|
9
9
|
export { home } from "./home.js";
|
package/dist/helpers/nix.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface NixNamespace {
|
|
|
14
14
|
optionalString(condition: NixCondition, value: NixStringPart): NixExpr;
|
|
15
15
|
isDarwin: NixExpr;
|
|
16
16
|
isLinux: NixExpr;
|
|
17
|
+
binaryRelease(opts: BinaryReleaseOpts): NixExpr;
|
|
17
18
|
lib: {
|
|
18
19
|
mkDefault(value: NixValue): NixExpr;
|
|
19
20
|
mkForce(value: NixValue): NixExpr;
|
|
@@ -23,6 +24,68 @@ export interface NixNamespace {
|
|
|
23
24
|
optionalString(condition: NixCondition, value: NixStringPart): NixExpr;
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
/** Supported `(os, arch)` strings for `nix.binaryRelease`. */
|
|
28
|
+
export type BinaryReleaseArch = "x86_64-linux" | "aarch64-linux" | "x86_64-darwin" | "aarch64-darwin";
|
|
29
|
+
export interface BinaryReleasePlatform {
|
|
30
|
+
/** Filename to download (substituted into `urlTemplate`'s `{file}`). */
|
|
31
|
+
file: string;
|
|
32
|
+
/** SRI hash (`sha256-...`) of the downloaded archive. */
|
|
33
|
+
hash: string;
|
|
34
|
+
/** Optional: name of the extracted binary, if it differs from the outer `binary`. */
|
|
35
|
+
binary?: string;
|
|
36
|
+
/** Optional: vendor-specific platform tag substituted into `urlTemplate`'s `{platform}`
|
|
37
|
+
* (e.g. `"linux_amd64"`, `"apple_universal"`). */
|
|
38
|
+
platform?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface BinaryReleaseMeta {
|
|
41
|
+
description: string;
|
|
42
|
+
homepage?: string;
|
|
43
|
+
/** SPDX-style license id (e.g. `"mit"`, `"asl20"`) or a raw `NixExpr`. */
|
|
44
|
+
license?: string | NixExpr;
|
|
45
|
+
/** Defaults to the outer `binary`. */
|
|
46
|
+
mainProgram?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface BinaryReleaseCompletions {
|
|
49
|
+
/** Command (or absolute path) that emits a bash completion script when run. */
|
|
50
|
+
bash?: string;
|
|
51
|
+
/** Command (or absolute path) that emits a fish completion script when run. */
|
|
52
|
+
fish?: string;
|
|
53
|
+
/** Command (or absolute path) that emits a zsh completion script when run. */
|
|
54
|
+
zsh?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface BinaryReleaseOpts {
|
|
57
|
+
/** `pname` for the derivation. */
|
|
58
|
+
name: string;
|
|
59
|
+
/** `version` for the derivation. */
|
|
60
|
+
version: string;
|
|
61
|
+
/** Final binary name placed in `$out/bin/<binary>`. */
|
|
62
|
+
binary: string;
|
|
63
|
+
/** URL with `{version}`, `{file}` and optional `{platform}` placeholders.
|
|
64
|
+
* Must contain `{file}`. */
|
|
65
|
+
urlTemplate: string;
|
|
66
|
+
/** One entry per supported `(os, arch)`. At least one required. */
|
|
67
|
+
platforms: Partial<Record<BinaryReleaseArch, BinaryReleasePlatform>>;
|
|
68
|
+
/** Extra install lines appended after the main `install -Dm755`. */
|
|
69
|
+
extraInstall?: string;
|
|
70
|
+
/** Opt-in: add `autoPatchelfHook` to `nativeBuildInputs` on Linux. Use
|
|
71
|
+
* this for ELF binaries that link against shared libraries. Pass any
|
|
72
|
+
* required runtime libraries via `linuxBuildInputs`. */
|
|
73
|
+
linuxPatchelf?: boolean;
|
|
74
|
+
/** Extra `buildInputs` to expose on Linux only, typically shared libs
|
|
75
|
+
* needed by `autoPatchelfHook` (e.g. `["stdenv.cc.cc"]`). Values are
|
|
76
|
+
* emitted as raw Nix expressions under `pkgs.` unless they are already
|
|
77
|
+
* `NixExpr`. */
|
|
78
|
+
linuxBuildInputs?: (string | NixExpr)[];
|
|
79
|
+
/** Default `true`: emits `dontStrip = pkgs.stdenv.hostPlatform.isDarwin;`
|
|
80
|
+
* to avoid breaking signed Darwin binaries. Set `false` to opt out. */
|
|
81
|
+
dontStripDarwin?: boolean;
|
|
82
|
+
/** Shell completion script generation. Each entry is the command (or
|
|
83
|
+
* absolute path) that prints the completion script for that shell.
|
|
84
|
+
* Adds `installShellFiles` to `nativeBuildInputs` and runs
|
|
85
|
+
* `installShellCompletion` in `postInstall`. */
|
|
86
|
+
completions?: BinaryReleaseCompletions;
|
|
87
|
+
meta: BinaryReleaseMeta;
|
|
88
|
+
}
|
|
26
89
|
export interface PkgHelper {
|
|
27
90
|
(name: string): NixExpr;
|
|
28
91
|
stable(name: string): NixExpr;
|
package/dist/helpers/nix.js
CHANGED
|
@@ -47,6 +47,7 @@ export const nix = {
|
|
|
47
47
|
optionalString,
|
|
48
48
|
isDarwin: expr("pkgs.stdenv.isDarwin"),
|
|
49
49
|
isLinux: expr("pkgs.stdenv.isLinux"),
|
|
50
|
+
binaryRelease,
|
|
50
51
|
lib: {
|
|
51
52
|
mkDefault: (value) => nixLibCall("mkDefault", value),
|
|
52
53
|
mkForce: (value) => nixLibCall("mkForce", value),
|
|
@@ -59,6 +60,209 @@ export const nix = {
|
|
|
59
60
|
function nixLibCall(name, value) {
|
|
60
61
|
return expr(`lib.${name} ${nixLiteral(value)}`);
|
|
61
62
|
}
|
|
63
|
+
const KNOWN_BINARY_RELEASE_ARCHES = [
|
|
64
|
+
"x86_64-linux",
|
|
65
|
+
"aarch64-linux",
|
|
66
|
+
"x86_64-darwin",
|
|
67
|
+
"aarch64-darwin",
|
|
68
|
+
];
|
|
69
|
+
function binaryRelease(opts) {
|
|
70
|
+
if (!opts.name)
|
|
71
|
+
throw new Error("nix.binaryRelease: `name` is required");
|
|
72
|
+
if (!opts.version)
|
|
73
|
+
throw new Error("nix.binaryRelease: `version` is required");
|
|
74
|
+
if (!opts.binary)
|
|
75
|
+
throw new Error("nix.binaryRelease: `binary` is required");
|
|
76
|
+
if (!opts.urlTemplate)
|
|
77
|
+
throw new Error("nix.binaryRelease: `urlTemplate` is required");
|
|
78
|
+
if (!opts.urlTemplate.includes("{file}") && !opts.urlTemplate.includes("{platform}")) {
|
|
79
|
+
throw new Error("nix.binaryRelease: `urlTemplate` must contain `{file}` or `{platform}`");
|
|
80
|
+
}
|
|
81
|
+
if (!opts.meta || !opts.meta.description) {
|
|
82
|
+
throw new Error("nix.binaryRelease: `meta.description` is required");
|
|
83
|
+
}
|
|
84
|
+
const entries = Object.entries(opts.platforms);
|
|
85
|
+
const filtered = entries.filter((entry) => entry[1] !== undefined);
|
|
86
|
+
if (filtered.length === 0) {
|
|
87
|
+
throw new Error("nix.binaryRelease: at least one platform is required");
|
|
88
|
+
}
|
|
89
|
+
for (const [arch] of filtered) {
|
|
90
|
+
if (!KNOWN_BINARY_RELEASE_ARCHES.includes(arch)) {
|
|
91
|
+
throw new Error(`nix.binaryRelease: unknown platform key "${arch}"`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const usesPlatformPlaceholder = opts.urlTemplate.includes("{platform}");
|
|
95
|
+
if (usesPlatformPlaceholder) {
|
|
96
|
+
for (const [arch, platform] of filtered) {
|
|
97
|
+
if (!platform.platform) {
|
|
98
|
+
throw new Error(`nix.binaryRelease: "${arch}" must define \`platform\` because \`urlTemplate\` uses \`{platform}\``);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const sourcesAttrs = filtered
|
|
103
|
+
.map(([arch, platform]) => {
|
|
104
|
+
const parts = [
|
|
105
|
+
`file = ${JSON.stringify(platform.file)};`,
|
|
106
|
+
`hash = ${JSON.stringify(platform.hash)};`,
|
|
107
|
+
`binary = ${JSON.stringify(platform.binary ?? opts.binary)};`,
|
|
108
|
+
];
|
|
109
|
+
if (usesPlatformPlaceholder) {
|
|
110
|
+
parts.push(`platform = ${JSON.stringify(platform.platform)};`);
|
|
111
|
+
}
|
|
112
|
+
return ` ${arch} = { ${parts.join(" ")} };`;
|
|
113
|
+
})
|
|
114
|
+
.join("\n");
|
|
115
|
+
const urlExpr = renderUrlTemplate(opts.urlTemplate);
|
|
116
|
+
const mainProgram = opts.meta.mainProgram ?? opts.binary;
|
|
117
|
+
const license = opts.meta.license;
|
|
118
|
+
const licenseExpr = license === undefined
|
|
119
|
+
? undefined
|
|
120
|
+
: isNixExpr(license)
|
|
121
|
+
? license.expr
|
|
122
|
+
: `pkgs.lib.licenses.${license}`;
|
|
123
|
+
const metaLines = [
|
|
124
|
+
` description = ${JSON.stringify(opts.meta.description)};`,
|
|
125
|
+
];
|
|
126
|
+
if (opts.meta.homepage !== undefined) {
|
|
127
|
+
metaLines.push(` homepage = ${JSON.stringify(opts.meta.homepage)};`);
|
|
128
|
+
}
|
|
129
|
+
if (licenseExpr !== undefined) {
|
|
130
|
+
metaLines.push(` license = ${licenseExpr};`);
|
|
131
|
+
}
|
|
132
|
+
metaLines.push(` mainProgram = ${JSON.stringify(mainProgram)};`);
|
|
133
|
+
metaLines.push(` platforms = builtins.attrNames sources;`);
|
|
134
|
+
const extraInstallBlock = opts.extraInstall
|
|
135
|
+
? `\n ${dedent(opts.extraInstall).split("\n").join("\n ")}`
|
|
136
|
+
: "";
|
|
137
|
+
const completionLines = renderCompletions(opts.completions);
|
|
138
|
+
const completionsBlock = completionLines.length === 0
|
|
139
|
+
? ""
|
|
140
|
+
: `\n\n postInstall = pkgs.lib.optionalString (pkgs.stdenv.buildPlatform.canExecute pkgs.stdenv.hostPlatform) ''\n HOME=$TMPDIR\n${completionLines.map((l) => ` ${l}`).join("\n")}\n installShellCompletion ${shellsForInstall(opts.completions)}\n '';`;
|
|
141
|
+
const nativeInputs = [];
|
|
142
|
+
if (opts.linuxPatchelf) {
|
|
143
|
+
nativeInputs.push("pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.autoPatchelfHook ]");
|
|
144
|
+
}
|
|
145
|
+
if (opts.completions && Object.values(opts.completions).some(Boolean)) {
|
|
146
|
+
nativeInputs.push("[ pkgs.installShellFiles ]");
|
|
147
|
+
}
|
|
148
|
+
nativeInputs.push("pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [ pkgs.unzip ]");
|
|
149
|
+
const nativeBuildInputsExpr = nativeInputs.length === 1
|
|
150
|
+
? nativeInputs[0]
|
|
151
|
+
: nativeInputs.join("\n ++ ");
|
|
152
|
+
const linuxBuildInputs = opts.linuxBuildInputs && opts.linuxBuildInputs.length > 0
|
|
153
|
+
? `\n\n buildInputs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ ${opts.linuxBuildInputs.map(renderBuildInput).join(" ")} ];`
|
|
154
|
+
: "";
|
|
155
|
+
const dontStripDarwin = opts.dontStripDarwin !== false;
|
|
156
|
+
const dontStripLine = dontStripDarwin
|
|
157
|
+
? `\n\n dontStrip = pkgs.stdenv.hostPlatform.isDarwin;`
|
|
158
|
+
: "";
|
|
159
|
+
const text = `(let
|
|
160
|
+
version = ${JSON.stringify(opts.version)};
|
|
161
|
+
sources = {
|
|
162
|
+
${sourcesAttrs}
|
|
163
|
+
};
|
|
164
|
+
source = sources.\${pkgs.stdenv.hostPlatform.system};
|
|
165
|
+
in pkgs.stdenvNoCC.mkDerivation {
|
|
166
|
+
pname = ${JSON.stringify(opts.name)};
|
|
167
|
+
inherit version;
|
|
168
|
+
|
|
169
|
+
src = pkgs.fetchurl {
|
|
170
|
+
url = ${urlExpr};
|
|
171
|
+
hash = source.hash;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
nativeBuildInputs = ${nativeBuildInputsExpr};${linuxBuildInputs}${dontStripLine}
|
|
175
|
+
|
|
176
|
+
unpackPhase = ''
|
|
177
|
+
runHook preUnpack
|
|
178
|
+
mkdir source
|
|
179
|
+
case "$src" in
|
|
180
|
+
*.zip) unzip -q "$src" -d source ;;
|
|
181
|
+
*.tar.gz) tar -xzf "$src" -C source ;;
|
|
182
|
+
*.tgz) tar -xzf "$src" -C source ;;
|
|
183
|
+
esac
|
|
184
|
+
sourceRoot=source
|
|
185
|
+
runHook postUnpack
|
|
186
|
+
'';
|
|
187
|
+
|
|
188
|
+
installPhase = ''
|
|
189
|
+
runHook preInstall
|
|
190
|
+
install -Dm755 "\${source.binary}" "$out/bin/${opts.binary}"${extraInstallBlock}
|
|
191
|
+
runHook postInstall
|
|
192
|
+
'';${completionsBlock}
|
|
193
|
+
|
|
194
|
+
meta = {
|
|
195
|
+
${metaLines.join("\n")}
|
|
196
|
+
};
|
|
197
|
+
})`;
|
|
198
|
+
return expr(text);
|
|
199
|
+
}
|
|
200
|
+
function renderBuildInput(value) {
|
|
201
|
+
if (isNixExpr(value))
|
|
202
|
+
return value.expr;
|
|
203
|
+
return `pkgs.${value}`;
|
|
204
|
+
}
|
|
205
|
+
function renderCompletions(completions) {
|
|
206
|
+
if (!completions)
|
|
207
|
+
return [];
|
|
208
|
+
const lines = [];
|
|
209
|
+
for (const shell of ["bash", "fish", "zsh"]) {
|
|
210
|
+
const cmd = completions[shell];
|
|
211
|
+
if (!cmd)
|
|
212
|
+
continue;
|
|
213
|
+
lines.push(`${cmd} > ${opts_completion_filename(shell)}`);
|
|
214
|
+
}
|
|
215
|
+
return lines;
|
|
216
|
+
}
|
|
217
|
+
function opts_completion_filename(shell) {
|
|
218
|
+
return `completion.${shell === "zsh" ? "zsh" : shell}`;
|
|
219
|
+
}
|
|
220
|
+
function shellsForInstall(completions) {
|
|
221
|
+
if (!completions)
|
|
222
|
+
return "";
|
|
223
|
+
const present = ["bash", "fish", "zsh"].filter((s) => completions[s]);
|
|
224
|
+
return present.map((s) => opts_completion_filename(s)).join(" ");
|
|
225
|
+
}
|
|
226
|
+
function renderUrlTemplate(template) {
|
|
227
|
+
// Convert a {placeholder}-style template into a Nix double-quoted string
|
|
228
|
+
// with antiquotations. `{version}` -> `${version}`; `{file}` -> `${source.file}`;
|
|
229
|
+
// `{platform}` -> `${source.platform}`.
|
|
230
|
+
// Unknown placeholders are left as literal `{key}` in the output.
|
|
231
|
+
const parts = [];
|
|
232
|
+
const regex = /\{(version|file|platform)\}/g;
|
|
233
|
+
let lastIndex = 0;
|
|
234
|
+
let match;
|
|
235
|
+
while ((match = regex.exec(template)) !== null) {
|
|
236
|
+
if (match.index > lastIndex) {
|
|
237
|
+
parts.push(escapeNixDoubleQuoted(template.slice(lastIndex, match.index)));
|
|
238
|
+
}
|
|
239
|
+
const key = match[1];
|
|
240
|
+
parts.push(key === "version"
|
|
241
|
+
? "${version}"
|
|
242
|
+
: key === "file"
|
|
243
|
+
? "${source.file}"
|
|
244
|
+
: "${source.platform}");
|
|
245
|
+
lastIndex = regex.lastIndex;
|
|
246
|
+
}
|
|
247
|
+
if (lastIndex < template.length) {
|
|
248
|
+
parts.push(escapeNixDoubleQuoted(template.slice(lastIndex)));
|
|
249
|
+
}
|
|
250
|
+
return `"${parts.join("")}"`;
|
|
251
|
+
}
|
|
252
|
+
function dedent(value) {
|
|
253
|
+
const lines = value.replace(/^\n/, "").replace(/\n\s*$/, "").split("\n");
|
|
254
|
+
let min = Infinity;
|
|
255
|
+
for (const line of lines) {
|
|
256
|
+
if (line.trim() === "")
|
|
257
|
+
continue;
|
|
258
|
+
const indent = line.match(/^[ \t]*/)?.[0].length ?? 0;
|
|
259
|
+
if (indent < min)
|
|
260
|
+
min = indent;
|
|
261
|
+
}
|
|
262
|
+
if (!Number.isFinite(min) || min === 0)
|
|
263
|
+
return lines.join("\n");
|
|
264
|
+
return lines.map((line) => (line.length >= min ? line.slice(min) : line)).join("\n");
|
|
265
|
+
}
|
|
62
266
|
function stringPartToNix(value) {
|
|
63
267
|
return isNixExpr(value) ? value.expr : JSON.stringify(value);
|
|
64
268
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export type { EvaluatedHost } from "./evaluator/index.js";
|
|
|
6
6
|
export { generateNix } from "./backends/nix/index.js";
|
|
7
7
|
export type { NixOutput } from "./backends/nix/index.js";
|
|
8
8
|
export { account, darwin, home, nix, nixos, overlay, platforms } from "./helpers/index.js";
|
|
9
|
-
export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, AccountNamespace, AccountOpts, AccountUserFactory, AccountUserRef, ActivationOpts, DarwinHelper, DarwinPlatformOpts, DarwinProgramOptions, DarwinServiceOptions, HomeHelper, HomeProgramOptions, HomeServiceOptions, LaunchdHelper, NixNamespace, NixosHelper, NixosPlatformOpts, NixosProgramOptions, NixosServiceOptions, OverlayHelper, PkgHelper, PlatformsHelper, ScriptHelper, SysctlSettings, SystemdHelper, VirtualisationHelper } from "./helpers/index.js";
|
|
9
|
+
export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, AccountNamespace, AccountOpts, AccountUserFactory, AccountUserRef, ActivationOpts, BinaryReleaseArch, BinaryReleaseCompletions, BinaryReleaseMeta, BinaryReleaseOpts, BinaryReleasePlatform, DarwinHelper, DarwinPlatformOpts, DarwinProgramOptions, DarwinServiceOptions, HomeHelper, HomeProgramOptions, HomeServiceOptions, LaunchdHelper, NixNamespace, NixosHelper, NixosPlatformOpts, NixosProgramOptions, NixosServiceOptions, OverlayHelper, PkgHelper, PlatformsHelper, ScriptHelper, SysctlSettings, SystemdHelper, VirtualisationHelper } from "./helpers/index.js";
|
package/package.json
CHANGED