Improve schema, only update direct inputs

This commit is contained in:
Sandro Jäckel 2024-10-14 01:21:30 +02:00
parent 46609cab40
commit 31094498b3
No known key found for this signature in database
GPG key ID: 3AF5A43A3EECC2E5
2 changed files with 9 additions and 9 deletions

View file

@ -24,11 +24,6 @@ export function extractPackageFile(
const flakeLock = flakeLockParsed.data;
if (flakeLock.version !== 7) {
logger.debug({ packageFile }, 'Unsupported flake lock version');
return null;
}
for (const depName of Object.keys(flakeLock.nodes ?? {})) {
// the root input is a magic string for the entrypoint and only references other flake inputs
if (depName === 'root') {
@ -40,6 +35,11 @@ export function extractPackageFile(
continue;
}
// skip all locked nodes which are not in the flake.nix and cannot be updated
if (!(depName in (flakeLock.nodes['root'].inputs ?? []))) {
continue;
}
const flakeInput = flakeLock.nodes[depName];
const flakeLocked = flakeInput.locked;
const flakeOriginal = flakeInput.original;
@ -52,7 +52,7 @@ export function extractPackageFile(
continue;
}
// indirect inputs cannot be updated via normal means
// indirect inputs cannot be reliable updated because they depend on the flake registry
if (flakeOriginal.type === 'indirect') {
continue;
}

View file

@ -32,7 +32,7 @@ export const OriginalInput = z.object({
});
export const NixInput = z.object({
inputs: z.record(z.string(), z.string()).optional(),
inputs: z.record(z.string(), z.string().or(z.array(z.string()))).optional(),
locked: LockedInput.optional(),
original: OriginalInput.optional(),
});
@ -40,8 +40,8 @@ export const NixInput = z.object({
export const NixFlakeLock = Json.pipe(
z.object({
nodes: z.record(z.string(), NixInput).optional(),
root: z.string(),
version: z.number(),
root: z.literal('root').optional(),
version: z.literal(7),
}),
);