@adrifer/winix 0.1.2-preview.2 → 0.1.2-preview.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/nix.d.ts +109 -0
- package/dist/helpers/nix.js +238 -0
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -267,6 +267,42 @@ nix.script`
|
|
|
267
267
|
nix.lib.mkForce(["https://cache.nixos.org/"])
|
|
268
268
|
```
|
|
269
269
|
|
|
270
|
+
For prebuilt single-binary CLI releases (the `azd`, `gh`, `kubectl`,
|
|
271
|
+
`1password` family), use `nix.binaryRelease()` instead of hand-rolling
|
|
272
|
+
the `stdenvNoCC.mkDerivation` boilerplate:
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
home.packages(
|
|
276
|
+
nix.binaryRelease({
|
|
277
|
+
name: "azure-dev-cli",
|
|
278
|
+
version: "1.25.5",
|
|
279
|
+
binary: "azd",
|
|
280
|
+
urlTemplate:
|
|
281
|
+
"https://github.com/Azure/azure-dev/releases/download/azure-dev-cli_{version}/{file}",
|
|
282
|
+
platforms: {
|
|
283
|
+
"x86_64-linux": { file: "azd-linux-amd64.tar.gz", hash: "sha256-..." },
|
|
284
|
+
"aarch64-linux": { file: "azd-linux-arm64.tar.gz", hash: "sha256-..." },
|
|
285
|
+
"x86_64-darwin": { file: "azd-darwin-amd64.zip", hash: "sha256-..." },
|
|
286
|
+
"aarch64-darwin":{ file: "azd-darwin-arm64.zip", hash: "sha256-..." },
|
|
287
|
+
},
|
|
288
|
+
meta: {
|
|
289
|
+
description: "Azure Developer CLI",
|
|
290
|
+
homepage: "https://github.com/Azure/azure-dev",
|
|
291
|
+
license: "mit",
|
|
292
|
+
},
|
|
293
|
+
}),
|
|
294
|
+
);
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Supports per-platform `{platform}` URL placeholders (for vendors whose
|
|
298
|
+
URLs aren't just `${file}`), shell completions via `installShellFiles`,
|
|
299
|
+
optional `autoPatchelfHook` on Linux, and a validated `meta.license`
|
|
300
|
+
(rejects SPDX-style ids like `MIT`/`Apache-2.0` at TS-eval time so misuse
|
|
301
|
+
surfaces immediately, not at Nix build time). Pass `nix.expr(...)` for
|
|
302
|
+
licenses that aren't a simple `pkgs.lib.licenses.<id>` lookup. See
|
|
303
|
+
[`spec/proposals/binary-release.md`](spec/proposals/binary-release.md)
|
|
304
|
+
for the full reference.
|
|
305
|
+
|
|
270
306
|
For bigger migrations, import existing Nix modules:
|
|
271
307
|
|
|
272
308
|
```ts
|
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,50 @@ export interface NixNamespace {
|
|
|
14
14
|
optionalString(condition: NixCondition, value: NixStringPart): NixExpr;
|
|
15
15
|
isDarwin: NixExpr;
|
|
16
16
|
isLinux: NixExpr;
|
|
17
|
+
/**
|
|
18
|
+
* Build a `stdenvNoCC.mkDerivation` for a prebuilt single-binary CLI
|
|
19
|
+
* release (the `azd`, `gh`, `kubectl`, `1password` family).
|
|
20
|
+
*
|
|
21
|
+
* Picks the right `(file, hash)` per `pkgs.stdenv.hostPlatform.system`,
|
|
22
|
+
* substitutes `{version}`, `{file}`, and (optionally) `{platform}` into
|
|
23
|
+
* `urlTemplate`, fetches with `pkgs.fetchurl`, unpacks tarballs/zips,
|
|
24
|
+
* and `install -Dm755`s the binary into `$out/bin/<binary>`.
|
|
25
|
+
*
|
|
26
|
+
* Optional extensions:
|
|
27
|
+
* - `completions` — emits `installShellCompletion` for `bash`/`fish`/`zsh`.
|
|
28
|
+
* - `linuxPatchelf` — enables `autoPatchelfHook` on Linux only.
|
|
29
|
+
* - `linuxBuildInputs` — extra runtime libs the auto-patchelf hook needs.
|
|
30
|
+
* - `dontStripDarwin` — keep the binary's Mach-O signature intact (default `true`).
|
|
31
|
+
*
|
|
32
|
+
* `meta.license` accepts a nixpkgs `pkgs.lib.licenses` attribute name
|
|
33
|
+
* (e.g. `"mit"`, `"asl20"`, `"unfree"`) or a `NixExpr`. SPDX-style ids
|
|
34
|
+
* like `"MIT"` or `"Apache-2.0"` are rejected at TS-eval time.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* nix.binaryRelease({
|
|
39
|
+
* name: "azure-dev-cli",
|
|
40
|
+
* version: "1.25.5",
|
|
41
|
+
* binary: "azd",
|
|
42
|
+
* urlTemplate:
|
|
43
|
+
* "https://github.com/Azure/azure-dev/releases/download/azure-dev-cli_{version}/{file}",
|
|
44
|
+
* platforms: {
|
|
45
|
+
* "x86_64-linux": { file: "azd-linux-amd64.tar.gz", hash: "sha256-..." },
|
|
46
|
+
* "aarch64-linux": { file: "azd-linux-arm64.tar.gz", hash: "sha256-..." },
|
|
47
|
+
* "x86_64-darwin": { file: "azd-darwin-amd64.zip", hash: "sha256-..." },
|
|
48
|
+
* "aarch64-darwin":{ file: "azd-darwin-arm64.zip", hash: "sha256-..." },
|
|
49
|
+
* },
|
|
50
|
+
* meta: {
|
|
51
|
+
* description: "Azure Developer CLI",
|
|
52
|
+
* homepage: "https://github.com/Azure/azure-dev",
|
|
53
|
+
* license: "mit",
|
|
54
|
+
* },
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @see {@link BinaryReleaseOpts} for the full options interface
|
|
59
|
+
*/
|
|
60
|
+
binaryRelease(opts: BinaryReleaseOpts): NixExpr;
|
|
17
61
|
lib: {
|
|
18
62
|
mkDefault(value: NixValue): NixExpr;
|
|
19
63
|
mkForce(value: NixValue): NixExpr;
|
|
@@ -23,6 +67,71 @@ export interface NixNamespace {
|
|
|
23
67
|
optionalString(condition: NixCondition, value: NixStringPart): NixExpr;
|
|
24
68
|
};
|
|
25
69
|
}
|
|
70
|
+
/** Supported `(os, arch)` strings for `nix.binaryRelease`. */
|
|
71
|
+
export type BinaryReleaseArch = "x86_64-linux" | "aarch64-linux" | "x86_64-darwin" | "aarch64-darwin";
|
|
72
|
+
export interface BinaryReleasePlatform {
|
|
73
|
+
/** Filename to download (substituted into `urlTemplate`'s `{file}`). */
|
|
74
|
+
file: string;
|
|
75
|
+
/** SRI hash (`sha256-...`) of the downloaded archive. */
|
|
76
|
+
hash: string;
|
|
77
|
+
/** Optional: name of the extracted binary, if it differs from the outer `binary`. */
|
|
78
|
+
binary?: string;
|
|
79
|
+
/** Optional: vendor-specific platform tag substituted into `urlTemplate`'s `{platform}`
|
|
80
|
+
* (e.g. `"linux_amd64"`, `"apple_universal"`). */
|
|
81
|
+
platform?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface BinaryReleaseMeta {
|
|
84
|
+
description: string;
|
|
85
|
+
homepage?: string;
|
|
86
|
+
/** nixpkgs `lib.licenses` attribute name (e.g. `"mit"`, `"asl20"`,
|
|
87
|
+
* `"unfree"`). **Not** an SPDX identifier: `"MIT"` and `"Apache-2.0"`
|
|
88
|
+
* will be rejected. Pass a `NixExpr` (e.g. `nix.expr("pkgs.lib.licenses.unfree")`)
|
|
89
|
+
* for licenses that aren't a simple attribute lookup. */
|
|
90
|
+
license?: string | NixExpr;
|
|
91
|
+
/** Defaults to the outer `binary`. */
|
|
92
|
+
mainProgram?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface BinaryReleaseCompletions {
|
|
95
|
+
/** Command (or absolute path) that emits a bash completion script when run. */
|
|
96
|
+
bash?: string;
|
|
97
|
+
/** Command (or absolute path) that emits a fish completion script when run. */
|
|
98
|
+
fish?: string;
|
|
99
|
+
/** Command (or absolute path) that emits a zsh completion script when run. */
|
|
100
|
+
zsh?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface BinaryReleaseOpts {
|
|
103
|
+
/** `pname` for the derivation. */
|
|
104
|
+
name: string;
|
|
105
|
+
/** `version` for the derivation. */
|
|
106
|
+
version: string;
|
|
107
|
+
/** Final binary name placed in `$out/bin/<binary>`. */
|
|
108
|
+
binary: string;
|
|
109
|
+
/** URL with `{version}`, `{file}` and optional `{platform}` placeholders.
|
|
110
|
+
* Must contain `{file}`. */
|
|
111
|
+
urlTemplate: string;
|
|
112
|
+
/** One entry per supported `(os, arch)`. At least one required. */
|
|
113
|
+
platforms: Partial<Record<BinaryReleaseArch, BinaryReleasePlatform>>;
|
|
114
|
+
/** Extra install lines appended after the main `install -Dm755`. */
|
|
115
|
+
extraInstall?: string;
|
|
116
|
+
/** Opt-in: add `autoPatchelfHook` to `nativeBuildInputs` on Linux. Use
|
|
117
|
+
* this for ELF binaries that link against shared libraries. Pass any
|
|
118
|
+
* required runtime libraries via `linuxBuildInputs`. */
|
|
119
|
+
linuxPatchelf?: boolean;
|
|
120
|
+
/** Extra `buildInputs` to expose on Linux only, typically shared libs
|
|
121
|
+
* needed by `autoPatchelfHook` (e.g. `["stdenv.cc.cc"]`). Values are
|
|
122
|
+
* emitted as raw Nix expressions under `pkgs.` unless they are already
|
|
123
|
+
* `NixExpr`. */
|
|
124
|
+
linuxBuildInputs?: (string | NixExpr)[];
|
|
125
|
+
/** Default `true`: emits `dontStrip = pkgs.stdenv.hostPlatform.isDarwin;`
|
|
126
|
+
* to avoid breaking signed Darwin binaries. Set `false` to opt out. */
|
|
127
|
+
dontStripDarwin?: boolean;
|
|
128
|
+
/** Shell completion script generation. Each entry is the command (or
|
|
129
|
+
* absolute path) that prints the completion script for that shell.
|
|
130
|
+
* Adds `installShellFiles` to `nativeBuildInputs` and runs
|
|
131
|
+
* `installShellCompletion` in `postInstall`. */
|
|
132
|
+
completions?: BinaryReleaseCompletions;
|
|
133
|
+
meta: BinaryReleaseMeta;
|
|
134
|
+
}
|
|
26
135
|
export interface PkgHelper {
|
|
27
136
|
(name: string): NixExpr;
|
|
28
137
|
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,234 @@ 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 || typeof opts !== "object") {
|
|
71
|
+
throw new Error("nix.binaryRelease: `opts` is required");
|
|
72
|
+
}
|
|
73
|
+
if (!opts.name)
|
|
74
|
+
throw new Error("nix.binaryRelease: `name` is required");
|
|
75
|
+
if (!opts.version)
|
|
76
|
+
throw new Error("nix.binaryRelease: `version` is required");
|
|
77
|
+
if (!opts.binary)
|
|
78
|
+
throw new Error("nix.binaryRelease: `binary` is required");
|
|
79
|
+
if (!opts.urlTemplate)
|
|
80
|
+
throw new Error("nix.binaryRelease: `urlTemplate` is required");
|
|
81
|
+
if (!opts.urlTemplate.includes("{file}") && !opts.urlTemplate.includes("{platform}")) {
|
|
82
|
+
throw new Error("nix.binaryRelease: `urlTemplate` must contain `{file}` or `{platform}`");
|
|
83
|
+
}
|
|
84
|
+
if (!opts.meta || !opts.meta.description) {
|
|
85
|
+
throw new Error("nix.binaryRelease: `meta.description` is required");
|
|
86
|
+
}
|
|
87
|
+
if (opts.platforms === undefined || opts.platforms === null) {
|
|
88
|
+
throw new Error("nix.binaryRelease: `platforms` is required");
|
|
89
|
+
}
|
|
90
|
+
if (!isPlainObject(opts.platforms)) {
|
|
91
|
+
throw new Error("nix.binaryRelease: `platforms` must be an object");
|
|
92
|
+
}
|
|
93
|
+
if (opts.meta.license !== undefined &&
|
|
94
|
+
typeof opts.meta.license === "string" &&
|
|
95
|
+
!isNixAttrName(opts.meta.license)) {
|
|
96
|
+
throw new Error(`nix.binaryRelease: \`meta.license\` string "${opts.meta.license}" is not a valid nixpkgs attribute name. ` +
|
|
97
|
+
`Use a \`pkgs.lib.licenses\` attr name like "mit" or "asl20", or pass \`nix.expr("...")\` for custom expressions.`);
|
|
98
|
+
}
|
|
99
|
+
const entries = Object.entries(opts.platforms);
|
|
100
|
+
const filtered = entries.filter((entry) => entry[1] !== undefined);
|
|
101
|
+
if (filtered.length === 0) {
|
|
102
|
+
throw new Error("nix.binaryRelease: at least one platform is required");
|
|
103
|
+
}
|
|
104
|
+
for (const [arch, platform] of filtered) {
|
|
105
|
+
if (!KNOWN_BINARY_RELEASE_ARCHES.includes(arch)) {
|
|
106
|
+
throw new Error(`nix.binaryRelease: unknown platform key "${arch}"`);
|
|
107
|
+
}
|
|
108
|
+
if (!platform.file) {
|
|
109
|
+
throw new Error(`nix.binaryRelease: platforms.${arch}.file is required`);
|
|
110
|
+
}
|
|
111
|
+
if (!platform.hash) {
|
|
112
|
+
throw new Error(`nix.binaryRelease: platforms.${arch}.hash is required`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const usesPlatformPlaceholder = opts.urlTemplate.includes("{platform}");
|
|
116
|
+
if (usesPlatformPlaceholder) {
|
|
117
|
+
for (const [arch, platform] of filtered) {
|
|
118
|
+
if (!platform.platform) {
|
|
119
|
+
throw new Error(`nix.binaryRelease: "${arch}" must define \`platform\` because \`urlTemplate\` uses \`{platform}\``);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const sourcesAttrs = filtered
|
|
124
|
+
.map(([arch, platform]) => {
|
|
125
|
+
const parts = [
|
|
126
|
+
`file = ${JSON.stringify(platform.file)};`,
|
|
127
|
+
`hash = ${JSON.stringify(platform.hash)};`,
|
|
128
|
+
`binary = ${JSON.stringify(platform.binary ?? opts.binary)};`,
|
|
129
|
+
];
|
|
130
|
+
if (usesPlatformPlaceholder) {
|
|
131
|
+
parts.push(`platform = ${JSON.stringify(platform.platform)};`);
|
|
132
|
+
}
|
|
133
|
+
return ` ${arch} = { ${parts.join(" ")} };`;
|
|
134
|
+
})
|
|
135
|
+
.join("\n");
|
|
136
|
+
const urlExpr = renderUrlTemplate(opts.urlTemplate);
|
|
137
|
+
const mainProgram = opts.meta.mainProgram ?? opts.binary;
|
|
138
|
+
const license = opts.meta.license;
|
|
139
|
+
const licenseExpr = license === undefined
|
|
140
|
+
? undefined
|
|
141
|
+
: isNixExpr(license)
|
|
142
|
+
? license.expr
|
|
143
|
+
: `pkgs.lib.licenses.${license}`;
|
|
144
|
+
const metaLines = [
|
|
145
|
+
` description = ${JSON.stringify(opts.meta.description)};`,
|
|
146
|
+
];
|
|
147
|
+
if (opts.meta.homepage !== undefined) {
|
|
148
|
+
metaLines.push(` homepage = ${JSON.stringify(opts.meta.homepage)};`);
|
|
149
|
+
}
|
|
150
|
+
if (licenseExpr !== undefined) {
|
|
151
|
+
metaLines.push(` license = ${licenseExpr};`);
|
|
152
|
+
}
|
|
153
|
+
metaLines.push(` mainProgram = ${JSON.stringify(mainProgram)};`);
|
|
154
|
+
metaLines.push(` platforms = builtins.attrNames sources;`);
|
|
155
|
+
const extraInstallBlock = opts.extraInstall
|
|
156
|
+
? `\n ${dedent(opts.extraInstall).split("\n").join("\n ")}`
|
|
157
|
+
: "";
|
|
158
|
+
const completionLines = renderCompletions(opts.completions);
|
|
159
|
+
const completionsBlock = completionLines.length === 0
|
|
160
|
+
? ""
|
|
161
|
+
: `\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 '';`;
|
|
162
|
+
const nativeInputs = [];
|
|
163
|
+
if (opts.linuxPatchelf) {
|
|
164
|
+
nativeInputs.push("pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.autoPatchelfHook ]");
|
|
165
|
+
}
|
|
166
|
+
if (opts.completions && Object.values(opts.completions).some(Boolean)) {
|
|
167
|
+
nativeInputs.push("[ pkgs.installShellFiles ]");
|
|
168
|
+
}
|
|
169
|
+
// `unzip` is needed for `.zip` archives on every platform, not just
|
|
170
|
+
// darwin (e.g. a Linux release that ships a single .zip). Adding it
|
|
171
|
+
// unconditionally is cheap and avoids a runtime failure in `unpackPhase`.
|
|
172
|
+
nativeInputs.push("[ pkgs.unzip ]");
|
|
173
|
+
const nativeBuildInputsExpr = nativeInputs.length === 1
|
|
174
|
+
? nativeInputs[0]
|
|
175
|
+
: nativeInputs.join("\n ++ ");
|
|
176
|
+
const linuxBuildInputs = opts.linuxBuildInputs && opts.linuxBuildInputs.length > 0
|
|
177
|
+
? `\n\n buildInputs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ ${opts.linuxBuildInputs.map(renderBuildInput).join(" ")} ];`
|
|
178
|
+
: "";
|
|
179
|
+
const dontStripDarwin = opts.dontStripDarwin !== false;
|
|
180
|
+
const dontStripLine = dontStripDarwin
|
|
181
|
+
? `\n\n dontStrip = pkgs.stdenv.hostPlatform.isDarwin;`
|
|
182
|
+
: "";
|
|
183
|
+
const text = `(let
|
|
184
|
+
version = ${JSON.stringify(opts.version)};
|
|
185
|
+
sources = {
|
|
186
|
+
${sourcesAttrs}
|
|
187
|
+
};
|
|
188
|
+
source = sources.\${pkgs.stdenv.hostPlatform.system};
|
|
189
|
+
in pkgs.stdenvNoCC.mkDerivation {
|
|
190
|
+
pname = ${JSON.stringify(opts.name)};
|
|
191
|
+
inherit version;
|
|
192
|
+
|
|
193
|
+
src = pkgs.fetchurl {
|
|
194
|
+
url = ${urlExpr};
|
|
195
|
+
hash = source.hash;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
nativeBuildInputs = ${nativeBuildInputsExpr};${linuxBuildInputs}${dontStripLine}
|
|
199
|
+
|
|
200
|
+
unpackPhase = ''
|
|
201
|
+
runHook preUnpack
|
|
202
|
+
mkdir source
|
|
203
|
+
case "$src" in
|
|
204
|
+
*.zip) unzip -q "$src" -d source ;;
|
|
205
|
+
*.tar.gz) tar -xzf "$src" -C source ;;
|
|
206
|
+
*.tgz) tar -xzf "$src" -C source ;;
|
|
207
|
+
*) echo "nix.binaryRelease: unsupported archive extension for $src" >&2; exit 1 ;;
|
|
208
|
+
esac
|
|
209
|
+
sourceRoot=source
|
|
210
|
+
runHook postUnpack
|
|
211
|
+
'';
|
|
212
|
+
|
|
213
|
+
installPhase = ''
|
|
214
|
+
runHook preInstall
|
|
215
|
+
install -Dm755 "\${source.binary}" "$out/bin/${opts.binary}"${extraInstallBlock}
|
|
216
|
+
runHook postInstall
|
|
217
|
+
'';${completionsBlock}
|
|
218
|
+
|
|
219
|
+
meta = {
|
|
220
|
+
${metaLines.join("\n")}
|
|
221
|
+
};
|
|
222
|
+
})`;
|
|
223
|
+
return expr(text);
|
|
224
|
+
}
|
|
225
|
+
function renderBuildInput(value) {
|
|
226
|
+
if (isNixExpr(value))
|
|
227
|
+
return value.expr;
|
|
228
|
+
return `pkgs.${value}`;
|
|
229
|
+
}
|
|
230
|
+
function renderCompletions(completions) {
|
|
231
|
+
if (!completions)
|
|
232
|
+
return [];
|
|
233
|
+
const lines = [];
|
|
234
|
+
for (const shell of ["bash", "fish", "zsh"]) {
|
|
235
|
+
const cmd = completions[shell];
|
|
236
|
+
if (!cmd)
|
|
237
|
+
continue;
|
|
238
|
+
lines.push(`${cmd} > ${opts_completion_filename(shell)}`);
|
|
239
|
+
}
|
|
240
|
+
return lines;
|
|
241
|
+
}
|
|
242
|
+
function opts_completion_filename(shell) {
|
|
243
|
+
return `completion.${shell === "zsh" ? "zsh" : shell}`;
|
|
244
|
+
}
|
|
245
|
+
function shellsForInstall(completions) {
|
|
246
|
+
if (!completions)
|
|
247
|
+
return "";
|
|
248
|
+
const present = ["bash", "fish", "zsh"].filter((s) => completions[s]);
|
|
249
|
+
return present.map((s) => opts_completion_filename(s)).join(" ");
|
|
250
|
+
}
|
|
251
|
+
function renderUrlTemplate(template) {
|
|
252
|
+
// Convert a {placeholder}-style template into a Nix double-quoted string
|
|
253
|
+
// with antiquotations. `{version}` -> `${version}`; `{file}` -> `${source.file}`;
|
|
254
|
+
// `{platform}` -> `${source.platform}`.
|
|
255
|
+
// Unknown placeholders are left as literal `{key}` in the output.
|
|
256
|
+
const parts = [];
|
|
257
|
+
const regex = /\{(version|file|platform)\}/g;
|
|
258
|
+
let lastIndex = 0;
|
|
259
|
+
let match;
|
|
260
|
+
while ((match = regex.exec(template)) !== null) {
|
|
261
|
+
if (match.index > lastIndex) {
|
|
262
|
+
parts.push(escapeNixDoubleQuoted(template.slice(lastIndex, match.index)));
|
|
263
|
+
}
|
|
264
|
+
const key = match[1];
|
|
265
|
+
parts.push(key === "version"
|
|
266
|
+
? "${version}"
|
|
267
|
+
: key === "file"
|
|
268
|
+
? "${source.file}"
|
|
269
|
+
: "${source.platform}");
|
|
270
|
+
lastIndex = regex.lastIndex;
|
|
271
|
+
}
|
|
272
|
+
if (lastIndex < template.length) {
|
|
273
|
+
parts.push(escapeNixDoubleQuoted(template.slice(lastIndex)));
|
|
274
|
+
}
|
|
275
|
+
return `"${parts.join("")}"`;
|
|
276
|
+
}
|
|
277
|
+
function dedent(value) {
|
|
278
|
+
const lines = value.replace(/^\n/, "").replace(/\n\s*$/, "").split("\n");
|
|
279
|
+
let min = Infinity;
|
|
280
|
+
for (const line of lines) {
|
|
281
|
+
if (line.trim() === "")
|
|
282
|
+
continue;
|
|
283
|
+
const indent = line.match(/^[ \t]*/)?.[0].length ?? 0;
|
|
284
|
+
if (indent < min)
|
|
285
|
+
min = indent;
|
|
286
|
+
}
|
|
287
|
+
if (!Number.isFinite(min) || min === 0)
|
|
288
|
+
return lines.join("\n");
|
|
289
|
+
return lines.map((line) => (line.length >= min ? line.slice(min) : line)).join("\n");
|
|
290
|
+
}
|
|
62
291
|
function stringPartToNix(value) {
|
|
63
292
|
return isNixExpr(value) ? value.expr : JSON.stringify(value);
|
|
64
293
|
}
|
|
@@ -140,6 +369,15 @@ function isNixExpr(value) {
|
|
|
140
369
|
function isPlainObject(value) {
|
|
141
370
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
142
371
|
}
|
|
372
|
+
// A valid `pkgs.lib.licenses.<id>` attribute name. nixpkgs convention
|
|
373
|
+
// is lowercase-first (e.g. `mit`, `asl20`, `gpl3Only`, `unfree`). This
|
|
374
|
+
// deliberately rejects SPDX-style ids like `MIT` or `Apache-2.0` so the
|
|
375
|
+
// helper surfaces the error at TS-eval time with a clear message rather
|
|
376
|
+
// than producing invalid Nix or a confusing attribute lookup error.
|
|
377
|
+
const NIX_LICENSE_ATTR_NAME = /^[a-z][A-Za-z0-9_]*$/;
|
|
378
|
+
function isNixAttrName(value) {
|
|
379
|
+
return NIX_LICENSE_ATTR_NAME.test(value);
|
|
380
|
+
}
|
|
143
381
|
const NIX_KEYWORDS = new Set([
|
|
144
382
|
"assert",
|
|
145
383
|
"else",
|
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