fix: structuredAttrs
This commit is contained in:
@@ -90,6 +90,35 @@ const extractArgs = (attrs: NixAttrs, outContext: NixStringContext): string[] =>
|
|||||||
return argsList.map((a) => coerceToString(a, StringCoercionMode.ToString, false, outContext));
|
return argsList.map((a) => coerceToString(a, StringCoercionMode.ToString, false, outContext));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const structuredAttrsExcludedKeys = new Set([
|
||||||
|
"__structuredAttrs",
|
||||||
|
"__ignoreNulls",
|
||||||
|
"__contentAddressed",
|
||||||
|
"impure",
|
||||||
|
"args",
|
||||||
|
]);
|
||||||
|
|
||||||
|
const specialAttrs = new Set([
|
||||||
|
"name",
|
||||||
|
"builder",
|
||||||
|
"system",
|
||||||
|
"args",
|
||||||
|
"outputs",
|
||||||
|
"__structuredAttrs",
|
||||||
|
"__ignoreNulls",
|
||||||
|
"__contentAddressed",
|
||||||
|
"impure",
|
||||||
|
]);
|
||||||
|
|
||||||
|
const sortedJsonStringify = (obj: Record<string, any>): string => {
|
||||||
|
const sortedKeys = Object.keys(obj).sort();
|
||||||
|
const sortedObj: Record<string, any> = {};
|
||||||
|
for (const key of sortedKeys) {
|
||||||
|
sortedObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
return JSON.stringify(sortedObj);
|
||||||
|
};
|
||||||
|
|
||||||
const extractEnv = (
|
const extractEnv = (
|
||||||
attrs: NixAttrs,
|
attrs: NixAttrs,
|
||||||
structuredAttrs: boolean,
|
structuredAttrs: boolean,
|
||||||
@@ -97,24 +126,12 @@ const extractEnv = (
|
|||||||
outContext: NixStringContext,
|
outContext: NixStringContext,
|
||||||
drvName: string,
|
drvName: string,
|
||||||
): Map<string, string> => {
|
): Map<string, string> => {
|
||||||
const specialAttrs = new Set([
|
|
||||||
"name",
|
|
||||||
"builder",
|
|
||||||
"system",
|
|
||||||
"args",
|
|
||||||
"outputs",
|
|
||||||
"__structuredAttrs",
|
|
||||||
"__ignoreNulls",
|
|
||||||
"__contentAddressed",
|
|
||||||
"impure",
|
|
||||||
]);
|
|
||||||
|
|
||||||
const env = new Map<string, string>();
|
const env = new Map<string, string>();
|
||||||
|
|
||||||
if (structuredAttrs) {
|
if (structuredAttrs) {
|
||||||
const jsonAttrs: Record<string, any> = {};
|
const jsonAttrs: Record<string, any> = {};
|
||||||
for (const [key, value] of Object.entries(attrs)) {
|
for (const [key, value] of Object.entries(attrs)) {
|
||||||
if (!specialAttrs.has(key)) {
|
if (!structuredAttrsExcludedKeys.has(key)) {
|
||||||
const forcedValue = force(value);
|
const forcedValue = force(value);
|
||||||
if (ignoreNulls && forcedValue === null) {
|
if (ignoreNulls && forcedValue === null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -165,7 +182,7 @@ const extractEnv = (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
env.set("__json", JSON.stringify(jsonAttrs));
|
env.set("__json", sortedJsonStringify(jsonAttrs));
|
||||||
} else {
|
} else {
|
||||||
for (const [key, value] of Object.entries(attrs)) {
|
for (const [key, value] of Object.entries(attrs)) {
|
||||||
if (!specialAttrs.has(key)) {
|
if (!specialAttrs.has(key)) {
|
||||||
@@ -236,11 +253,13 @@ export const derivationStrict = (args: NixValue): NixAttrs => {
|
|||||||
const drvArgs = extractArgs(attrs, collectedContext);
|
const drvArgs = extractArgs(attrs, collectedContext);
|
||||||
const env = extractEnv(attrs, structuredAttrs, ignoreNulls, collectedContext, drvName);
|
const env = extractEnv(attrs, structuredAttrs, ignoreNulls, collectedContext, drvName);
|
||||||
|
|
||||||
env.set("name", drvName);
|
if (!structuredAttrs) {
|
||||||
env.set("builder", builder);
|
env.set("name", drvName);
|
||||||
env.set("system", platform);
|
env.set("builder", builder);
|
||||||
if (outputs.length > 1 || outputs[0] !== "out") {
|
env.set("system", platform);
|
||||||
env.set("outputs", outputs.join(" "));
|
if (outputs.length > 1 || outputs[0] !== "out") {
|
||||||
|
env.set("outputs", outputs.join(" "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { inputDrvs, inputSrcs } = extractInputDrvsAndSrcs(collectedContext);
|
const { inputDrvs, inputSrcs } = extractInputDrvsAndSrcs(collectedContext);
|
||||||
@@ -351,18 +370,6 @@ export const derivationStrict = (args: NixValue): NixAttrs => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const specialAttrs = new Set([
|
|
||||||
"name",
|
|
||||||
"builder",
|
|
||||||
"system",
|
|
||||||
"args",
|
|
||||||
"outputs",
|
|
||||||
"__structuredAttrs",
|
|
||||||
"__ignoreNulls",
|
|
||||||
"__contentAddressed",
|
|
||||||
"impure",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const derivation = (args: NixValue): NixAttrs => {
|
export const derivation = (args: NixValue): NixAttrs => {
|
||||||
const attrs = forceAttrs(args);
|
const attrs = forceAttrs(args);
|
||||||
|
|
||||||
@@ -385,7 +392,7 @@ export const derivation = (args: NixValue): NixAttrs => {
|
|||||||
|
|
||||||
const outputsList = outputs.map(outputToAttrListElement);
|
const outputsList = outputs.map(outputToAttrListElement);
|
||||||
|
|
||||||
for (const { name: outputName, value } of outputsList) {
|
for (const { name: outputName } of outputsList) {
|
||||||
commonAttrs[outputName] = createThunk(
|
commonAttrs[outputName] = createThunk(
|
||||||
() => outputsList.find((o) => o.name === outputName)!.value,
|
() => outputsList.find((o) => o.name === outputName)!.value,
|
||||||
`output_${outputName}`,
|
`output_${outputName}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user