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