From 752feae9acd3ed21bac6fa8ae16d6e775bad651e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 11 Oct 2024 16:34:30 +0200 Subject: [PATCH 01/53] feat(nix): rework to work with all flake inputs --- .../manager/nix/__fixtures__/flake.1.lock | 7 ++ .../manager/nix/__fixtures__/flake.2.lock | 27 +++++ .../manager/nix/__fixtures__/flake.3.lock | 26 +++++ .../manager/nix/__fixtures__/flake.4.lock | 44 ++++++++ .../manager/nix/__fixtures__/flake.5.lock | 27 +++++ .../manager/nix/__fixtures__/flake.6.lock | 27 +++++ lib/modules/manager/nix/artifacts.spec.ts | 29 +++-- lib/modules/manager/nix/artifacts.ts | 4 +- lib/modules/manager/nix/extract.spec.ts | 101 ++++++++++-------- lib/modules/manager/nix/extract.ts | 93 +++++++++++++--- lib/modules/manager/nix/index.ts | 4 +- lib/modules/manager/nix/readme.md | 2 +- lib/modules/manager/nix/types.ts | 39 +++++++ 13 files changed, 352 insertions(+), 78 deletions(-) create mode 100644 lib/modules/manager/nix/__fixtures__/flake.1.lock create mode 100644 lib/modules/manager/nix/__fixtures__/flake.2.lock create mode 100644 lib/modules/manager/nix/__fixtures__/flake.3.lock create mode 100644 lib/modules/manager/nix/__fixtures__/flake.4.lock create mode 100644 lib/modules/manager/nix/__fixtures__/flake.5.lock create mode 100644 lib/modules/manager/nix/__fixtures__/flake.6.lock create mode 100644 lib/modules/manager/nix/types.ts diff --git a/lib/modules/manager/nix/__fixtures__/flake.1.lock b/lib/modules/manager/nix/__fixtures__/flake.1.lock new file mode 100644 index 00000000000000..5999137c97311a --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.1.lock @@ -0,0 +1,7 @@ +{ + "nodes": { + "root": {} + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/__fixtures__/flake.2.lock b/lib/modules/manager/nix/__fixtures__/flake.2.lock new file mode 100644 index 00000000000000..8bbf80d08a6d05 --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.2.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/__fixtures__/flake.3.lock b/lib/modules/manager/nix/__fixtures__/flake.3.lock new file mode 100644 index 00000000000000..4e715e4b122a14 --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.3.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728650607, + "narHash": "sha256-0lOnVTzRXzpk5uxbHLm3Ti3tyPAvirAIQDfwEUd8arg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "612ee628421ba2c1abca4c99684862f76cb3b089", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/__fixtures__/flake.4.lock b/lib/modules/manager/nix/__fixtures__/flake.4.lock new file mode 100644 index 00000000000000..a11067f50b38fd --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.4.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1672057183, + "narHash": "sha256-GN7/10DNNvs1FPj9tlZA2qgNdFuYKKuS3qlHTqAxasQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b139e44d78c36c69bcbb825b20dbfa51e7738347", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixpkgs-unstable", + "type": "indirect" + } + }, + "patchelf": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1718457448, + "narHash": "sha256-FSoxTcRZMGHNJh8dNtKOkcUtjhmhU6yQXcZZfUPLhQM=", + "ref": "refs/heads/master", + "rev": "a0f54334df36770b335c051e540ba40afcbf8378", + "revCount": 844, + "type": "git", + "url": "https://github.com/NixOS/patchelf.git" + }, + "original": { + "type": "git", + "url": "https://github.com/NixOS/patchelf.git" + } + }, + "root": { + "inputs": { + "patchelf": "patchelf" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/__fixtures__/flake.5.lock b/lib/modules/manager/nix/__fixtures__/flake.5.lock new file mode 100644 index 00000000000000..9e6349fa1f1baa --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.5.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "ijq": { + "flake": false, + "locked": { + "lastModified": 1723569650, + "narHash": "sha256-Ho/sAhEUeSug52JALgjrKVUPCBe8+PovbJj/lniKxp8=", + "owner": "~gpanders", + "repo": "ijq", + "rev": "88f0d9ae98942bf49cba302c42b2a0f6e05f9b58", + "type": "sourcehut" + }, + "original": { + "owner": "~gpanders", + "repo": "ijq", + "type": "sourcehut" + } + }, + "root": { + "inputs": { + "ijq": "ijq" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/__fixtures__/flake.6.lock b/lib/modules/manager/nix/__fixtures__/flake.6.lock new file mode 100644 index 00000000000000..3b4e21a8331a78 --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.6.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "home-manager": { + "flake": false, + "locked": { + "lastModified": 1728650932, + "narHash": "sha256-mGKzqdsRyLnGNl6WjEr7+sghGgBtYHhJQ4mjpgRTCsU=", + "owner": "rycee", + "repo": "home-manager", + "rev": "65ae9c147349829d3df0222151f53f79821c5134", + "type": "gitlab" + }, + "original": { + "owner": "rycee", + "repo": "home-manager", + "type": "gitlab" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/artifacts.spec.ts b/lib/modules/manager/nix/artifacts.spec.ts index 7b741ee82208f4..d9cca2268fdde9 100644 --- a/lib/modules/manager/nix/artifacts.spec.ts +++ b/lib/modules/manager/nix/artifacts.spec.ts @@ -36,17 +36,14 @@ process.env.CONTAINERBASE = 'true'; const config: UpdateArtifactsConfig = {}; const lockMaintenanceConfig = { ...config, isLockFileMaintenance: true }; const updateInputCmd = `nix \ - --extra-experimental-features nix-command \ - --extra-experimental-features flakes \ +--extra-experimental-features 'nix-command flakes' \ flake lock --update-input nixpkgs`; const updateInputTokenCmd = `nix \ - --extra-experimental-features nix-command \ - --extra-experimental-features flakes \ +--extra-experimental-features 'nix-command flakes' \ --extra-access-tokens github.com=token \ flake lock --update-input nixpkgs`; const lockfileMaintenanceCmd = `nix \ - --extra-experimental-features nix-command \ - --extra-experimental-features flakes \ +--extra-experimental-features 'nix-command flakes' \ flake update`; describe('modules/manager/nix/artifacts', () => { @@ -66,7 +63,7 @@ describe('modules/manager/nix/artifacts', () => { it('returns if no flake.lock found', async () => { const execSnapshots = mockExecAll(); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [], newPackageFileContent: '', config, @@ -86,7 +83,7 @@ describe('modules/manager/nix/artifacts', () => { ); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config, @@ -107,7 +104,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { ...config, constraints: { python: '3.7' } }, @@ -137,7 +134,7 @@ describe('modules/manager/nix/artifacts', () => { hostRules.find.mockReturnValueOnce({ token: 'token' }); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { ...config, constraints: { python: '3.7' } }, @@ -167,7 +164,7 @@ describe('modules/manager/nix/artifacts', () => { hostRules.find.mockReturnValueOnce({ token: 'x-access-token:token' }); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { ...config, constraints: { python: '3.7' } }, @@ -196,7 +193,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config: { ...config, constraints: { nix: '2.10.0' } }, @@ -241,7 +238,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config: { ...config, constraints: { nix: '2.10.0' } }, @@ -269,7 +266,7 @@ describe('modules/manager/nix/artifacts', () => { const execSnapshots = mockExecSequence([new Error('exec error')]); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config, @@ -294,7 +291,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config: lockMaintenanceConfig, @@ -323,7 +320,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new lock'); const res = await updateArtifacts({ - packageFileName: 'flake.nix', + packageFileName: 'flake.lock', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { diff --git a/lib/modules/manager/nix/artifacts.ts b/lib/modules/manager/nix/artifacts.ts index 411cfb160d6f97..4180f37bbc6f35 100644 --- a/lib/modules/manager/nix/artifacts.ts +++ b/lib/modules/manager/nix/artifacts.ts @@ -22,9 +22,7 @@ export async function updateArtifacts({ return null; } - let cmd = `nix \ - --extra-experimental-features nix-command \ - --extra-experimental-features flakes `; + let cmd = `nix --extra-experimental-features 'nix-command flakes' `; const token = findGithubToken( hostRules.find({ diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 9645744c2a9208..b43320f7692dc4 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -1,74 +1,89 @@ import { GitRefsDatasource } from '../../datasource/git-refs'; -import { id as nixpkgsVersioning } from '../../versioning/nixpkgs'; +import { Fixtures } from '../../../../test/fixtures'; import { extractPackageFile } from '.'; +const flake1Lock = Fixtures.get('flake.1.lock'); +const flake2Lock = Fixtures.get('flake.2.lock'); +const flake3Lock = Fixtures.get('flake.3.lock'); +const flake4Lock = Fixtures.get('flake.4.lock'); +const flake5Lock = Fixtures.get('flake.5.lock'); +const flake6Lock = Fixtures.get('flake.6.lock'); + describe('modules/manager/nix/extract', () => { - it('returns null when no nixpkgs', () => { - const content = `{ - inputs = {}; -}`; - const res = extractPackageFile(content); + it('returns null when no inputs', () => { + const res = extractPackageFile(flake1Lock, 'flake.lock'); expect(res).toBeNull(); }); - it('returns nixpkgs', () => { - const content = `{ - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; - }; -}`; - - const res = extractPackageFile(content); + it('returns nixpkgs input', () => { + const res = extractPackageFile(flake2Lock, 'flake.lock'); expect(res?.deps).toEqual([ { depName: 'nixpkgs', - currentValue: 'nixos-21.11', + currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', datasource: GitRefsDatasource.id, packageName: 'https://github.com/NixOS/nixpkgs', - versioning: nixpkgsVersioning, }, ]); }); - it('is case insensitive', () => { - const content = `{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; - }; -}`; + it('includes nixpkgs with no explicit ref', () => { + const res = extractPackageFile(flake3Lock, 'flake.lock'); - const res = extractPackageFile(content); + expect(res).toMatchObject({ + deps: [ + { + currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', + datasource: 'git-refs', + depName: 'nixpkgs', + packageName: 'https://github.com/NixOS/nixpkgs', + }, + ], + }); + }); - expect(res?.deps).toEqual([ - { - depName: 'nixpkgs', - currentValue: 'nixos-21.11', - datasource: GitRefsDatasource.id, - packageName: 'https://github.com/NixOS/nixpkgs', - versioning: nixpkgsVersioning, - }, - ]); + it('includes patchelf from HEAD', () => { + const res = extractPackageFile(flake4Lock, 'flake.lock'); + + expect(res).toMatchObject({ + deps: [ + { + currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', + datasource: 'git-refs', + depName: 'patchelf', + packageName: 'https://github.com/NixOS/patchelf.git', + }, + ], + }); }); - it('includes nixpkgs with no explicit ref', () => { - const content = `{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs"; - }; -}`; + it('includes ijq from sourcehut without a flake', () => { + const res = extractPackageFile(flake5Lock, 'flake.lock'); + + expect(res).toMatchObject({ + deps: [ + { + currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', + datasource: 'git-refs', + depName: 'ijq', + packageName: 'https://git.sr.ht/~gpanders/ijq', + }, + ], + }); + }); - const res = extractPackageFile(content); + it('includes home-manager from gitlab', () => { + const res = extractPackageFile(flake6Lock, 'flake.lock'); expect(res).toMatchObject({ deps: [ { - currentValue: undefined, + currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', datasource: 'git-refs', - depName: 'nixpkgs', - packageName: 'https://github.com/NixOS/nixpkgs', - versioning: 'nixpkgs', + depName: 'home-manager', + packageName: 'https://gitlab.com/rycee/home-manager', }, ], }); diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 5170e23a07dfe0..a046b72182ff9c 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -1,23 +1,90 @@ -import { regEx } from '../../../util/regex'; import { GitRefsDatasource } from '../../datasource/git-refs'; +import { logger } from '../../../logger'; import { id as nixpkgsVersioning } from '../../versioning/nixpkgs'; import type { PackageDependency, PackageFileContent } from '../types'; +import { InputType, NixFlakeLock } from './types'; -const nixpkgsRegex = regEx(/"github:nixos\/nixpkgs(\/(?[a-z0-9-.]+))?"/i); +// TODO: add support to update nixpkgs branches in flakes.nix using nixpkgsVersioning + +export function extractPackageFile( + content: string, + packageFile: string, +): PackageFileContent | null { + logger.trace(`nix.extractPackageFile(${packageFile})`); -export function extractPackageFile(content: string): PackageFileContent | null { const deps: PackageDependency[] = []; + let lock: NixFlakeLock; + + try { + lock = JSON.parse(content); + } catch { + logger.debug({ packageFile }, `Invalid JSON`); + return null; + } + + if (lock.version !== 7) { + logger.debug({ packageFile }, 'Unsupported flake lock version'); + return null; + } + + for (const depName of Object.keys(lock.nodes ?? {})) { + // the root input is a magic string for the entrypoint and only references other flake inputs + if (depName === 'root') { + continue; + } + + const flakeInput = lock.nodes[depName]; + const flakeLocked = flakeInput.locked; + const flakeOriginal = flakeInput.original; + + if (flakeLocked === undefined || flakeOriginal === undefined) { + logger.debug( + { packageFile }, + `Found empty flake input '${JSON.stringify(flakeInput)}', skipping`, + ); + continue; + } + + // indirect inputs cannot be updated via normal means + if (flakeOriginal.type === InputType.indirect) { + continue; + } - const match = nixpkgsRegex.exec(content); - if (match?.groups) { - const { ref } = match.groups; - deps.push({ - depName: 'nixpkgs', - currentValue: ref, - datasource: GitRefsDatasource.id, - packageName: 'https://github.com/NixOS/nixpkgs', - versioning: nixpkgsVersioning, - }); + if (flakeLocked.type === InputType.github) { + deps.push({ + depName, + currentDigest: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: `https://github.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, + }); + } else if (flakeLocked.type === InputType.gitlab) { + deps.push({ + depName, + currentDigest: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: `https://gitlab.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, + }); + } else if (flakeOriginal.type === InputType.git) { + deps.push({ + depName, + currentDigest: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: flakeOriginal.url, + }); + } else if (flakeLocked.type === InputType.sourcehut) { + deps.push({ + depName, + currentDigest: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: `https://git.sr.ht/${flakeOriginal.owner}/${flakeOriginal.repo}`, + }); + } else { + logger.debug( + { packageFile }, + `Unknown flake.lock type "${flakeLocked.type}", skipping`, + ); + continue; + } } if (deps.length) { diff --git a/lib/modules/manager/nix/index.ts b/lib/modules/manager/nix/index.ts index 7cdfa48cdeb1bd..9444bce8d06616 100644 --- a/lib/modules/manager/nix/index.ts +++ b/lib/modules/manager/nix/index.ts @@ -6,8 +6,8 @@ export { updateArtifacts } from './artifacts'; export const supportsLockFileMaintenance = true; export const defaultConfig = { - fileMatch: ['(^|/)flake\\.nix$'], - commitMessageTopic: 'nixpkgs', + fileMatch: ['(^|/)flake\\.lock'], + commitMessageTopic: 'nix', commitMessageExtra: 'to {{newValue}}', enabled: false, }; diff --git a/lib/modules/manager/nix/readme.md b/lib/modules/manager/nix/readme.md index 3a196a34445c0e..c1357a8519bd20 100644 --- a/lib/modules/manager/nix/readme.md +++ b/lib/modules/manager/nix/readme.md @@ -1,4 +1,4 @@ The [`nix`](https://github.com/NixOS/nix) manager supports: - [`lockFileMaintenance`](../../../configuration-options.md#lockfilemaintenance) updates for `flake.lock` -- [nixpkgs](https://github.com/NixOS/nixpkgs) updates +- input updates for `flake.lock` diff --git a/lib/modules/manager/nix/types.ts b/lib/modules/manager/nix/types.ts new file mode 100644 index 00000000000000..c0d65791e4ce7e --- /dev/null +++ b/lib/modules/manager/nix/types.ts @@ -0,0 +1,39 @@ +export interface NixFlakeLock { + readonly nodes: Record; + readonly root: string; + readonly version: number; +} + +export interface NixInput { + readonly inputs?: Record; + readonly locked?: LockedInput; + readonly original?: OriginalInput; +} + +export interface LockedInput { + readonly lastModified: number; + readonly narHash: string; + readonly owner?: string; + readonly repo?: string; + readonly ref?: string; + readonly rev: string; + readonly revCount: number; + readonly type: InputType; + readonly url?: string; +} + +export interface OriginalInput { + readonly owner?: string; + readonly repo?: string; + readonly ref?: string; + readonly type: InputType; + readonly url?: string; +} + +export enum InputType { + git = 'git', + github = 'github', + gitlab = 'gitlab', + indirect = 'indirect', + sourcehut = 'sourcehut', +} From 44aeba3d9678337a8b8504edf61959c60152f194 Mon Sep 17 00:00:00 2001 From: Sandro Date: Fri, 11 Oct 2024 19:13:34 +0200 Subject: [PATCH 02/53] Add another field to lockedInput --- lib/modules/manager/nix/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modules/manager/nix/types.ts b/lib/modules/manager/nix/types.ts index c0d65791e4ce7e..f3f82b84dc8aa6 100644 --- a/lib/modules/manager/nix/types.ts +++ b/lib/modules/manager/nix/types.ts @@ -11,6 +11,7 @@ export interface NixInput { } export interface LockedInput { + readonly host?: string; readonly lastModified: number; readonly narHash: string; readonly owner?: string; From 0dc2ab1e2f3ad64eaa28348442490af07f886ebb Mon Sep 17 00:00:00 2001 From: Sandro Date: Sat, 12 Oct 2024 04:06:43 +0200 Subject: [PATCH 03/53] Remove unused import --- lib/modules/manager/nix/extract.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index a046b72182ff9c..2402271154dc8d 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -1,6 +1,5 @@ import { GitRefsDatasource } from '../../datasource/git-refs'; import { logger } from '../../../logger'; -import { id as nixpkgsVersioning } from '../../versioning/nixpkgs'; import type { PackageDependency, PackageFileContent } from '../types'; import { InputType, NixFlakeLock } from './types'; From 24f0a849b4b81bb62e6153961e636b3519740f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 12 Oct 2024 04:51:41 +0200 Subject: [PATCH 04/53] Transport branch to not generate updates for every commit on HEAD --- lib/modules/manager/nix/extract.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 2402271154dc8d..bf05d3f469b0cd 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -52,28 +52,36 @@ export function extractPackageFile( if (flakeLocked.type === InputType.github) { deps.push({ depName, + currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: `https://github.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); } else if (flakeLocked.type === InputType.gitlab) { deps.push({ depName, + currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: `https://gitlab.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); } else if (flakeOriginal.type === InputType.git) { deps.push({ depName, + currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: flakeOriginal.url, }); } else if (flakeLocked.type === InputType.sourcehut) { deps.push({ depName, + currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: `https://git.sr.ht/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); From bc97524a93e60e1540efd69a9bab51531c627846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 12 Oct 2024 22:13:20 +0200 Subject: [PATCH 05/53] Use zod --- lib/modules/manager/nix/extract.spec.ts | 98 ++++++++++--------------- lib/modules/manager/nix/extract.ts | 37 ++++++---- lib/modules/manager/nix/schema.ts | 39 ++++++++++ lib/modules/manager/nix/types.ts | 40 ---------- 4 files changed, 99 insertions(+), 115 deletions(-) create mode 100644 lib/modules/manager/nix/schema.ts delete mode 100644 lib/modules/manager/nix/types.ts diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index b43320f7692dc4..f4bc1c21676bff 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -10,16 +10,12 @@ const flake5Lock = Fixtures.get('flake.5.lock'); const flake6Lock = Fixtures.get('flake.6.lock'); describe('modules/manager/nix/extract', () => { - it('returns null when no inputs', () => { - const res = extractPackageFile(flake1Lock, 'flake.lock'); - - expect(res).toBeNull(); + it('returns null when no inputs', async () => { + expect(await extractPackageFile(flake1Lock, 'flake.lock')).toBeNull(); }); - it('returns nixpkgs input', () => { - const res = extractPackageFile(flake2Lock, 'flake.lock'); - - expect(res?.deps).toEqual([ + it('returns nixpkgs input', async () => { + expect((await extractPackageFile(flake2Lock, 'flake.lock'))?.deps).toEqual([ { depName: 'nixpkgs', currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', @@ -29,63 +25,47 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes nixpkgs with no explicit ref', () => { - const res = extractPackageFile(flake3Lock, 'flake.lock'); - - expect(res).toMatchObject({ - deps: [ - { - currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', - datasource: 'git-refs', - depName: 'nixpkgs', - packageName: 'https://github.com/NixOS/nixpkgs', + it('includes nixpkgs with no explicit ref', async () => { + expect((await extractPackageFile(flake3Lock, 'flake.lock'))?.deps).toMatchObject([ + { + currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', + datasource: 'git-refs', + depName: 'nixpkgs', + packageName: 'https://github.com/NixOS/nixpkgs', }, - ], - }); + ]); }); - it('includes patchelf from HEAD', () => { - const res = extractPackageFile(flake4Lock, 'flake.lock'); - - expect(res).toMatchObject({ - deps: [ - { - currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', - datasource: 'git-refs', - depName: 'patchelf', - packageName: 'https://github.com/NixOS/patchelf.git', - }, - ], - }); + it('includes patchelf from HEAD', async () => { + expect((await extractPackageFile(flake4Lock, 'flake.lock'))?.deps).toMatchObject([ + { + currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', + datasource: 'git-refs', + depName: 'patchelf', + packageName: 'https://github.com/NixOS/patchelf.git', + }, + ]); }); - it('includes ijq from sourcehut without a flake', () => { - const res = extractPackageFile(flake5Lock, 'flake.lock'); - - expect(res).toMatchObject({ - deps: [ - { - currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', - datasource: 'git-refs', - depName: 'ijq', - packageName: 'https://git.sr.ht/~gpanders/ijq', - }, - ], - }); + it('includes ijq from sourcehut without a flake', async () => { + expect((await extractPackageFile(flake5Lock, 'flake.lock'))?.deps).toMatchObject([ + { + currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', + datasource: 'git-refs', + depName: 'ijq', + packageName: 'https://git.sr.ht/~gpanders/ijq', + }, + ]); }); - it('includes home-manager from gitlab', () => { - const res = extractPackageFile(flake6Lock, 'flake.lock'); - - expect(res).toMatchObject({ - deps: [ - { - currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', - datasource: 'git-refs', - depName: 'home-manager', - packageName: 'https://gitlab.com/rycee/home-manager', - }, - ], - }); + it('includes home-manager from gitlab', async () => { + expect((await extractPackageFile(flake6Lock, 'flake.lock'))?.deps).toMatchObject([ + { + currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', + datasource: 'git-refs', + depName: 'home-manager', + packageName: 'https://gitlab.com/rycee/home-manager', + }, + ]); }); }); diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index bf05d3f469b0cd..2a14626d542c1a 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -1,38 +1,43 @@ import { GitRefsDatasource } from '../../datasource/git-refs'; import { logger } from '../../../logger'; import type { PackageDependency, PackageFileContent } from '../types'; -import { InputType, NixFlakeLock } from './types'; +import { NixFlakeLock } from './schema'; // TODO: add support to update nixpkgs branches in flakes.nix using nixpkgsVersioning -export function extractPackageFile( +export async function extractPackageFile( content: string, packageFile: string, -): PackageFileContent | null { +): Promise { logger.trace(`nix.extractPackageFile(${packageFile})`); const deps: PackageDependency[] = []; - let lock: NixFlakeLock; - try { - lock = JSON.parse(content); - } catch { - logger.debug({ packageFile }, `Invalid JSON`); + const flakeLockParsed = await NixFlakeLock.safeParse(content); + if (!flakeLockParsed.success) { + logger.debug({ packageFile, error: flakeLockParsed.error }, `invalid flake.lock file`); return null; } - if (lock.version !== 7) { + const flakeLock = flakeLockParsed.data; + + if (flakeLock.version !== 7) { logger.debug({ packageFile }, 'Unsupported flake lock version'); return null; } - for (const depName of Object.keys(lock.nodes ?? {})) { + 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') { continue; } - const flakeInput = lock.nodes[depName]; + // skip if there are no inputs + if (flakeLock.nodes === undefined) { + continue; + } + + const flakeInput = flakeLock.nodes[depName]; const flakeLocked = flakeInput.locked; const flakeOriginal = flakeInput.original; @@ -45,11 +50,11 @@ export function extractPackageFile( } // indirect inputs cannot be updated via normal means - if (flakeOriginal.type === InputType.indirect) { + if (flakeOriginal.type === 'indirect') { continue; } - if (flakeLocked.type === InputType.github) { + if (flakeLocked.type === 'github') { deps.push({ depName, currentValue: flakeOriginal.ref, @@ -58,7 +63,7 @@ export function extractPackageFile( datasource: GitRefsDatasource.id, packageName: `https://github.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); - } else if (flakeLocked.type === InputType.gitlab) { + } else if (flakeLocked.type === 'gitlab') { deps.push({ depName, currentValue: flakeOriginal.ref, @@ -67,7 +72,7 @@ export function extractPackageFile( datasource: GitRefsDatasource.id, packageName: `https://gitlab.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); - } else if (flakeOriginal.type === InputType.git) { + } else if (flakeOriginal.type === 'git') { deps.push({ depName, currentValue: flakeOriginal.ref, @@ -76,7 +81,7 @@ export function extractPackageFile( datasource: GitRefsDatasource.id, packageName: flakeOriginal.url, }); - } else if (flakeLocked.type === InputType.sourcehut) { + } else if (flakeLocked.type === 'sourcehut') { deps.push({ depName, currentValue: flakeOriginal.ref, diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts new file mode 100644 index 00000000000000..08ff0a73ab1735 --- /dev/null +++ b/lib/modules/manager/nix/schema.ts @@ -0,0 +1,39 @@ +import { z } from 'zod'; +import { Json } from '../../../util/schema-utils'; + +export const InputType = z.enum(['git', 'github', 'gitlab', 'indirect', 'sourcehut']); + +export const LockedInput = z.object({ + host: z.string().optional(), + lastModified: z.number(), + narHash: z.string(), + owner: z.string().optional(), + repo: z.string().optional(), + ref: z.string().optional(), + rev: z.string(), + revCount: z.number().optional(), + type: InputType, + url: z.string().optional(), +}); + +export const OriginalInput = z.object({ + owner: z.string().optional(), + repo: z.string().optional(), + ref: z.string().optional(), + type: InputType, + url: z.string().optional(), +}); + +export const NixInput = z.object({ + inputs: z.record(z.string(), z.string()).optional(), + locked: LockedInput.optional(), + original: OriginalInput.optional(), +}); + +export const NixFlakeLock = Json.pipe(z.object({ + nodes: z.record(z.string(), NixInput).optional(), + root: z.string(), + version: z.number(), +})); + +export type NixFlakeLock = z.infer; diff --git a/lib/modules/manager/nix/types.ts b/lib/modules/manager/nix/types.ts deleted file mode 100644 index f3f82b84dc8aa6..00000000000000 --- a/lib/modules/manager/nix/types.ts +++ /dev/null @@ -1,40 +0,0 @@ -export interface NixFlakeLock { - readonly nodes: Record; - readonly root: string; - readonly version: number; -} - -export interface NixInput { - readonly inputs?: Record; - readonly locked?: LockedInput; - readonly original?: OriginalInput; -} - -export interface LockedInput { - readonly host?: string; - readonly lastModified: number; - readonly narHash: string; - readonly owner?: string; - readonly repo?: string; - readonly ref?: string; - readonly rev: string; - readonly revCount: number; - readonly type: InputType; - readonly url?: string; -} - -export interface OriginalInput { - readonly owner?: string; - readonly repo?: string; - readonly ref?: string; - readonly type: InputType; - readonly url?: string; -} - -export enum InputType { - git = 'git', - github = 'github', - gitlab = 'gitlab', - indirect = 'indirect', - sourcehut = 'sourcehut', -} From 3de4d4b18cb2e3bbbede6940079e46fc7f129d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 12 Oct 2024 22:15:20 +0200 Subject: [PATCH 06/53] Fix test --- lib/modules/manager/nix/extract.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index f4bc1c21676bff..f188194ca23eb2 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -19,8 +19,10 @@ describe('modules/manager/nix/extract', () => { { depName: 'nixpkgs', currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', + currentValue: "nixos-unstable", datasource: GitRefsDatasource.id, packageName: 'https://github.com/NixOS/nixpkgs', + replaceString: "9f4128e00b0ae8ec65918efeba59db998750ead6", }, ]); }); From ae85dccfffc89905fe45077448e91c645becc562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 12 Oct 2024 22:22:57 +0200 Subject: [PATCH 07/53] Fix all the lints --- lib/modules/manager/nix/extract.spec.ts | 26 ++++++++++++------------- lib/modules/manager/nix/extract.ts | 8 ++++---- lib/modules/manager/nix/schema.ts | 20 +++++++++++++------ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index f188194ca23eb2..37d526afd3e393 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -1,5 +1,5 @@ -import { GitRefsDatasource } from '../../datasource/git-refs'; import { Fixtures } from '../../../../test/fixtures'; +import { GitRefsDatasource } from '../../datasource/git-refs'; import { extractPackageFile } from '.'; const flake1Lock = Fixtures.get('flake.1.lock'); @@ -10,12 +10,12 @@ const flake5Lock = Fixtures.get('flake.5.lock'); const flake6Lock = Fixtures.get('flake.6.lock'); describe('modules/manager/nix/extract', () => { - it('returns null when no inputs', async () => { - expect(await extractPackageFile(flake1Lock, 'flake.lock')).toBeNull(); + it('returns null when no inputs', () => { + expect(extractPackageFile(flake1Lock, 'flake.lock')).toBeNull(); }); - it('returns nixpkgs input', async () => { - expect((await extractPackageFile(flake2Lock, 'flake.lock'))?.deps).toEqual([ + it('returns nixpkgs input', () => { + expect((extractPackageFile(flake2Lock, 'flake.lock'))?.deps).toEqual([ { depName: 'nixpkgs', currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', @@ -27,8 +27,8 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes nixpkgs with no explicit ref', async () => { - expect((await extractPackageFile(flake3Lock, 'flake.lock'))?.deps).toMatchObject([ + it('includes nixpkgs with no explicit ref', () => { + expect((extractPackageFile(flake3Lock, 'flake.lock'))?.deps).toMatchObject([ { currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', datasource: 'git-refs', @@ -38,8 +38,8 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes patchelf from HEAD', async () => { - expect((await extractPackageFile(flake4Lock, 'flake.lock'))?.deps).toMatchObject([ + it('includes patchelf from HEAD', () => { + expect((extractPackageFile(flake4Lock, 'flake.lock'))?.deps).toMatchObject([ { currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', datasource: 'git-refs', @@ -49,8 +49,8 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes ijq from sourcehut without a flake', async () => { - expect((await extractPackageFile(flake5Lock, 'flake.lock'))?.deps).toMatchObject([ + it('includes ijq from sourcehut without a flake', () => { + expect((extractPackageFile(flake5Lock, 'flake.lock'))?.deps).toMatchObject([ { currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', datasource: 'git-refs', @@ -60,8 +60,8 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes home-manager from gitlab', async () => { - expect((await extractPackageFile(flake6Lock, 'flake.lock'))?.deps).toMatchObject([ + it('includes home-manager from gitlab', () => { + expect((extractPackageFile(flake6Lock, 'flake.lock'))?.deps).toMatchObject([ { currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', datasource: 'git-refs', diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 2a14626d542c1a..a19024f7c55cf7 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -1,19 +1,19 @@ -import { GitRefsDatasource } from '../../datasource/git-refs'; import { logger } from '../../../logger'; +import { GitRefsDatasource } from '../../datasource/git-refs'; import type { PackageDependency, PackageFileContent } from '../types'; import { NixFlakeLock } from './schema'; // TODO: add support to update nixpkgs branches in flakes.nix using nixpkgsVersioning -export async function extractPackageFile( +export function extractPackageFile( content: string, packageFile: string, -): Promise { +): PackageFileContent | null { logger.trace(`nix.extractPackageFile(${packageFile})`); const deps: PackageDependency[] = []; - const flakeLockParsed = await NixFlakeLock.safeParse(content); + const flakeLockParsed = NixFlakeLock.safeParse(content); if (!flakeLockParsed.success) { logger.debug({ packageFile, error: flakeLockParsed.error }, `invalid flake.lock file`); return null; diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index 08ff0a73ab1735..fabf2fa32fd066 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -1,7 +1,13 @@ import { z } from 'zod'; import { Json } from '../../../util/schema-utils'; -export const InputType = z.enum(['git', 'github', 'gitlab', 'indirect', 'sourcehut']); +export const InputType = z.enum([ + 'git', + 'github', + 'gitlab', + 'indirect', + 'sourcehut', +]); export const LockedInput = z.object({ host: z.string().optional(), @@ -30,10 +36,12 @@ export const NixInput = z.object({ original: OriginalInput.optional(), }); -export const NixFlakeLock = Json.pipe(z.object({ - nodes: z.record(z.string(), NixInput).optional(), - root: z.string(), - version: z.number(), -})); +export const NixFlakeLock = Json.pipe( + z.object({ + nodes: z.record(z.string(), NixInput).optional(), + root: z.string(), + version: z.number(), + }), +); export type NixFlakeLock = z.infer; From 0e0e5e07f57457f644a6e46b63d32b7a611994ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 12 Oct 2024 22:33:22 +0200 Subject: [PATCH 08/53] Format, try to bump coverage --- .../manager/nix/__fixtures__/flake.7.lock | 3 +++ lib/modules/manager/nix/extract.spec.ts | 21 ++++++++++++------- lib/modules/manager/nix/extract.ts | 5 ++++- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 lib/modules/manager/nix/__fixtures__/flake.7.lock diff --git a/lib/modules/manager/nix/__fixtures__/flake.7.lock b/lib/modules/manager/nix/__fixtures__/flake.7.lock new file mode 100644 index 00000000000000..e94fe1b7cf9e4b --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.7.lock @@ -0,0 +1,3 @@ +{ + "version": 6 +} diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 37d526afd3e393..e54ac96903e48e 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -8,6 +8,7 @@ const flake3Lock = Fixtures.get('flake.3.lock'); const flake4Lock = Fixtures.get('flake.4.lock'); const flake5Lock = Fixtures.get('flake.5.lock'); const flake6Lock = Fixtures.get('flake.6.lock'); +const flake7Lock = Fixtures.get('flake.7.lock'); describe('modules/manager/nix/extract', () => { it('returns null when no inputs', () => { @@ -15,31 +16,31 @@ describe('modules/manager/nix/extract', () => { }); it('returns nixpkgs input', () => { - expect((extractPackageFile(flake2Lock, 'flake.lock'))?.deps).toEqual([ + expect(extractPackageFile(flake2Lock, 'flake.lock')?.deps).toEqual([ { depName: 'nixpkgs', currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', - currentValue: "nixos-unstable", + currentValue: 'nixos-unstable', datasource: GitRefsDatasource.id, packageName: 'https://github.com/NixOS/nixpkgs', - replaceString: "9f4128e00b0ae8ec65918efeba59db998750ead6", + replaceString: '9f4128e00b0ae8ec65918efeba59db998750ead6', }, ]); }); it('includes nixpkgs with no explicit ref', () => { - expect((extractPackageFile(flake3Lock, 'flake.lock'))?.deps).toMatchObject([ + expect(extractPackageFile(flake3Lock, 'flake.lock')?.deps).toMatchObject([ { currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', datasource: 'git-refs', depName: 'nixpkgs', packageName: 'https://github.com/NixOS/nixpkgs', - }, + }, ]); }); it('includes patchelf from HEAD', () => { - expect((extractPackageFile(flake4Lock, 'flake.lock'))?.deps).toMatchObject([ + expect(extractPackageFile(flake4Lock, 'flake.lock')?.deps).toMatchObject([ { currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', datasource: 'git-refs', @@ -50,7 +51,7 @@ describe('modules/manager/nix/extract', () => { }); it('includes ijq from sourcehut without a flake', () => { - expect((extractPackageFile(flake5Lock, 'flake.lock'))?.deps).toMatchObject([ + expect(extractPackageFile(flake5Lock, 'flake.lock')?.deps).toMatchObject([ { currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', datasource: 'git-refs', @@ -61,7 +62,7 @@ describe('modules/manager/nix/extract', () => { }); it('includes home-manager from gitlab', () => { - expect((extractPackageFile(flake6Lock, 'flake.lock'))?.deps).toMatchObject([ + expect(extractPackageFile(flake6Lock, 'flake.lock')?.deps).toMatchObject([ { currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', datasource: 'git-refs', @@ -70,4 +71,8 @@ describe('modules/manager/nix/extract', () => { }, ]); }); + + it('test other version', () => { + expect(extractPackageFile(flake7Lock, 'flake.lock')).toBeNull(); + }); }); diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index a19024f7c55cf7..d4489cb01bc67e 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -15,7 +15,10 @@ export function extractPackageFile( const flakeLockParsed = NixFlakeLock.safeParse(content); if (!flakeLockParsed.success) { - logger.debug({ packageFile, error: flakeLockParsed.error }, `invalid flake.lock file`); + logger.debug( + { packageFile, error: flakeLockParsed.error }, + `invalid flake.lock file`, + ); return null; } From 46609cab403dc18970304c903d15503a622120ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sun, 13 Oct 2024 22:50:59 +0200 Subject: [PATCH 09/53] Add test case for shallow and submodules --- .../manager/nix/__fixtures__/flake.8.lock | 28 +++++++++++++++++++ lib/modules/manager/nix/extract.spec.ts | 12 ++++++++ lib/modules/manager/nix/schema.ts | 1 + 3 files changed, 41 insertions(+) create mode 100644 lib/modules/manager/nix/__fixtures__/flake.8.lock diff --git a/lib/modules/manager/nix/__fixtures__/flake.8.lock b/lib/modules/manager/nix/__fixtures__/flake.8.lock new file mode 100644 index 00000000000000..ae61fdc2725739 --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.8.lock @@ -0,0 +1,28 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "ref": "nixos-unstable", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "shallow": true, + "type": "git", + "url": "https://github.com/NixOS/nixpkgs" + }, + "original": { + "ref": "nixos-unstable", + "shallow": true, + "type": "git", + "url": "https://github.com/NixOS/nixpkgs" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index e54ac96903e48e..8118d3bd8673e6 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -9,6 +9,7 @@ const flake4Lock = Fixtures.get('flake.4.lock'); const flake5Lock = Fixtures.get('flake.5.lock'); const flake6Lock = Fixtures.get('flake.6.lock'); const flake7Lock = Fixtures.get('flake.7.lock'); +const flake8Lock = Fixtures.get('flake.8.lock'); describe('modules/manager/nix/extract', () => { it('returns null when no inputs', () => { @@ -75,4 +76,15 @@ describe('modules/manager/nix/extract', () => { it('test other version', () => { expect(extractPackageFile(flake7Lock, 'flake.lock')).toBeNull(); }); + + it('includes nixpkgs with ref and shallow arguments', () => { + expect(extractPackageFile(flake8Lock, 'flake.lock')?.deps).toMatchObject([ + { + currentDigest: '5633bcff0c6162b9e4b5f1264264611e950c8ec7', + datasource: 'git-refs', + depName: 'nixpkgs', + packageName: 'https://github.com/NixOS/nixpkgs', + }, + ]); + }); }); diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index fabf2fa32fd066..559ee84c68a96e 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -18,6 +18,7 @@ export const LockedInput = z.object({ ref: z.string().optional(), rev: z.string(), revCount: z.number().optional(), + shallow: z.boolean().optional(), type: InputType, url: z.string().optional(), }); From 31094498b3be103c45df7cd17623202c9c3628b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 14 Oct 2024 01:21:30 +0200 Subject: [PATCH 10/53] Improve schema, only update direct inputs --- lib/modules/manager/nix/extract.ts | 12 ++++++------ lib/modules/manager/nix/schema.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index d4489cb01bc67e..c7cfff9ee83044 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -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; } diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index 559ee84c68a96e..b3121e88346e27 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -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), }), ); From 9146253594cdd63bb8844de2db824b664b132b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 14 Oct 2024 14:31:33 +0200 Subject: [PATCH 11/53] Add test for indirect type --- .../manager/nix/__fixtures__/flake.9.lock | 25 +++++++++++++++++++ lib/modules/manager/nix/extract.spec.ts | 5 ++++ 2 files changed, 30 insertions(+) create mode 100644 lib/modules/manager/nix/__fixtures__/flake.9.lock diff --git a/lib/modules/manager/nix/__fixtures__/flake.9.lock b/lib/modules/manager/nix/__fixtures__/flake.9.lock new file mode 100644 index 00000000000000..30daa36f36423b --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.9.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 8118d3bd8673e6..6cbce8b4ddd85c 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -10,6 +10,7 @@ const flake5Lock = Fixtures.get('flake.5.lock'); const flake6Lock = Fixtures.get('flake.6.lock'); const flake7Lock = Fixtures.get('flake.7.lock'); const flake8Lock = Fixtures.get('flake.8.lock'); +const flake9Lock = Fixtures.get('flake.9.lock'); describe('modules/manager/nix/extract', () => { it('returns null when no inputs', () => { @@ -87,4 +88,8 @@ describe('modules/manager/nix/extract', () => { }, ]); }); + + it('includes nixpkgs but using indirect type that cannot be updated', () => { + expect(extractPackageFile(flake9Lock, 'flake.lock')).toBeNull(); + }); }); From f0c2dceddc6d10e482a6730d8ce01312ffffcffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 14 Oct 2024 14:31:59 +0200 Subject: [PATCH 12/53] Check nodes explicitly to be null instead of relying on fallback Cleaner, don't check twice and increases cov --- lib/modules/manager/nix/extract.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index c7cfff9ee83044..e778bc6bf40180 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -24,17 +24,17 @@ export function extractPackageFile( const flakeLock = flakeLockParsed.data; - for (const depName of Object.keys(flakeLock.nodes ?? {})) { + // skip if there are no inputs + if (flakeLock.nodes === undefined) { + 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') { continue; } - // skip if there are no inputs - if (flakeLock.nodes === undefined) { - continue; - } - // skip all locked nodes which are not in the flake.nix and cannot be updated if (!(depName in (flakeLock.nodes['root'].inputs ?? []))) { continue; From 7edb75439692e6e5172c00849597e9197822df4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 14 Oct 2024 14:32:23 +0200 Subject: [PATCH 13/53] Use switch instead of if else chain --- lib/modules/manager/nix/extract.ts | 90 ++++++++++++++++-------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index e778bc6bf40180..8674b2dcd78ead 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -57,48 +57,54 @@ export function extractPackageFile( continue; } - if (flakeLocked.type === 'github') { - deps.push({ - depName, - currentValue: flakeOriginal.ref, - currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, - datasource: GitRefsDatasource.id, - packageName: `https://github.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, - }); - } else if (flakeLocked.type === 'gitlab') { - deps.push({ - depName, - currentValue: flakeOriginal.ref, - currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, - datasource: GitRefsDatasource.id, - packageName: `https://gitlab.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, - }); - } else if (flakeOriginal.type === 'git') { - deps.push({ - depName, - currentValue: flakeOriginal.ref, - currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, - datasource: GitRefsDatasource.id, - packageName: flakeOriginal.url, - }); - } else if (flakeLocked.type === 'sourcehut') { - deps.push({ - depName, - currentValue: flakeOriginal.ref, - currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, - datasource: GitRefsDatasource.id, - packageName: `https://git.sr.ht/${flakeOriginal.owner}/${flakeOriginal.repo}`, - }); - } else { - logger.debug( - { packageFile }, - `Unknown flake.lock type "${flakeLocked.type}", skipping`, - ); - continue; + switch (flakeLocked.type) { + case 'github': + deps.push({ + depName, + currentValue: flakeOriginal.ref, + currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: `https://github.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, + }); + break; + case 'gitlab': + deps.push({ + depName, + currentValue: flakeOriginal.ref, + currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: `https://gitlab.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, + }); + break; + case 'git': + deps.push({ + depName, + currentValue: flakeOriginal.ref, + currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: flakeOriginal.url, + }); + break; + case 'sourcehut': + deps.push({ + depName, + currentValue: flakeOriginal.ref, + currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: `https://git.sr.ht/${flakeOriginal.owner}/${flakeOriginal.repo}`, + }); + break; + // istanbul ignore next: just a safeguard + default: + logger.debug( + { packageFile }, + `Unknown flake.lock type "${flakeLocked.type}", skipping`, + ); + break; } } From d3a54c74585e283d21b40037823d4972f84c7841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 14 Oct 2024 14:34:55 +0200 Subject: [PATCH 14/53] Ignore cov line because it testing it makes no sense --- lib/modules/manager/nix/extract.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 8674b2dcd78ead..18e3ce43b71767 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -44,6 +44,7 @@ export function extractPackageFile( const flakeLocked = flakeInput.locked; const flakeOriginal = flakeInput.original; + // istanbul ignore if: if we are not in a root node then original and locked always exist which cannot be easily expressed in the type if (flakeLocked === undefined || flakeOriginal === undefined) { logger.debug( { packageFile }, From 101306e57c72a65720677a8b8256e829f164def8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 21 Oct 2024 13:48:20 +0200 Subject: [PATCH 15/53] Nodes are not optional --- lib/modules/manager/nix/__fixtures__/flake.7.lock | 4 ++++ lib/modules/manager/nix/extract.ts | 5 ----- lib/modules/manager/nix/schema.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/modules/manager/nix/__fixtures__/flake.7.lock b/lib/modules/manager/nix/__fixtures__/flake.7.lock index e94fe1b7cf9e4b..fd1d70458c955d 100644 --- a/lib/modules/manager/nix/__fixtures__/flake.7.lock +++ b/lib/modules/manager/nix/__fixtures__/flake.7.lock @@ -1,3 +1,7 @@ { + "nodes": { + "root": {} + }, + "root": "root", "version": 6 } diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 18e3ce43b71767..be8344ee6b936a 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -24,11 +24,6 @@ export function extractPackageFile( const flakeLock = flakeLockParsed.data; - // skip if there are no inputs - if (flakeLock.nodes === undefined) { - 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') { diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index b3121e88346e27..dbc1a5238bd719 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -39,7 +39,7 @@ export const NixInput = z.object({ export const NixFlakeLock = Json.pipe( z.object({ - nodes: z.record(z.string(), NixInput).optional(), + nodes: z.record(z.string(), NixInput), root: z.literal('root').optional(), version: z.literal(7), }), From 51b6353056a278361763fe96ba1674ddf1e91358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 21 Oct 2024 13:48:36 +0200 Subject: [PATCH 16/53] Fix custom hosts --- .../manager/nix/__fixtures__/flake.10.lock | 81 +++++++++++++++++++ lib/modules/manager/nix/extract.spec.ts | 13 +++ lib/modules/manager/nix/extract.ts | 6 +- lib/modules/manager/nix/schema.ts | 1 + 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 lib/modules/manager/nix/__fixtures__/flake.10.lock diff --git a/lib/modules/manager/nix/__fixtures__/flake.10.lock b/lib/modules/manager/nix/__fixtures__/flake.10.lock new file mode 100644 index 00000000000000..49f892f42cd3db --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.10.lock @@ -0,0 +1,81 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-extra-pkgs": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "host": "github.corp.example.com", + "lastModified": 1728666512, + "narHash": "sha256-p+l16Zzyl2DXG695yks6KQP7NkjsnEksu5GBvtL1QYg=", + "owner": "my-org", + "repo": "nixpkgs-extra-pkgs", + "rev": "6bf2706348447df6f8b86b1c3e54f87b0afda84f", + "type": "github" + }, + "original": { + "host": "github.corp.example.com", + "owner": "my-org", + "repo": "nixpkgs-extra-pkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs-extra-pkgs": "nixpkgs-extra-pkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 6cbce8b4ddd85c..938496e08b199c 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -11,6 +11,7 @@ const flake6Lock = Fixtures.get('flake.6.lock'); const flake7Lock = Fixtures.get('flake.7.lock'); const flake8Lock = Fixtures.get('flake.8.lock'); const flake9Lock = Fixtures.get('flake.9.lock'); +const flake10Lock = Fixtures.get('flake.10.lock'); describe('modules/manager/nix/extract', () => { it('returns null when no inputs', () => { @@ -92,4 +93,16 @@ describe('modules/manager/nix/extract', () => { it('includes nixpkgs but using indirect type that cannot be updated', () => { expect(extractPackageFile(flake9Lock, 'flake.lock')).toBeNull(); }); + + it('includes flake from GitHub Enterprise', () => { + expect(extractPackageFile(flake10Lock, 'flake.lock')?.deps).toMatchObject([ + { + currentDigest: '6bf2706348447df6f8b86b1c3e54f87b0afda84f', + datasource: 'git-refs', + depName: 'nixpkgs-extra-pkgs', + packageName: + 'https://github.corp.example.com/my-org/nixpkgs-extra-pkgs', + }, + ]); + }); }); diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index be8344ee6b936a..ac239bf3c3edf9 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -61,7 +61,7 @@ export function extractPackageFile( currentDigest: flakeLocked.rev, replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, - packageName: `https://github.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, + packageName: `https://${flakeOriginal.host ?? 'github.com'}/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); break; case 'gitlab': @@ -71,7 +71,7 @@ export function extractPackageFile( currentDigest: flakeLocked.rev, replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, - packageName: `https://gitlab.com/${flakeOriginal.owner}/${flakeOriginal.repo}`, + packageName: `https://${flakeOriginal.host ?? 'gitlab.com'}/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); break; case 'git': @@ -91,7 +91,7 @@ export function extractPackageFile( currentDigest: flakeLocked.rev, replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, - packageName: `https://git.sr.ht/${flakeOriginal.owner}/${flakeOriginal.repo}`, + packageName: `https://${flakeOriginal.host ?? 'git.sr.ht'}/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); break; // istanbul ignore next: just a safeguard diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index dbc1a5238bd719..e2e2cf2ea5e136 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -24,6 +24,7 @@ export const LockedInput = z.object({ }); export const OriginalInput = z.object({ + host: z.string().optional(), owner: z.string().optional(), repo: z.string().optional(), ref: z.string().optional(), From 5cf966264cc1d9180e9390ca9007775156351d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 23 Oct 2024 16:41:43 +0200 Subject: [PATCH 17/53] Ignore coverage for impossible line --- lib/modules/manager/nix/extract.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index ac239bf3c3edf9..44f62d8f1e4eb0 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -31,6 +31,7 @@ export function extractPackageFile( } // skip all locked nodes which are not in the flake.nix and cannot be updated + // istanbul ignore next: a valid flake.lock file will never run into this if (!(depName in (flakeLock.nodes['root'].inputs ?? []))) { continue; } From 62d60c6071cf70906caee7cbdd8a6a00e61f3c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 23 Oct 2024 17:15:32 +0200 Subject: [PATCH 18/53] Add tarball type --- .../manager/nix/__fixtures__/flake.11.lock | 87 +++++++++++++++++++ lib/modules/manager/nix/extract.spec.ts | 12 +++ lib/modules/manager/nix/extract.ts | 20 +++++ lib/modules/manager/nix/schema.ts | 1 + 4 files changed, 120 insertions(+) create mode 100644 lib/modules/manager/nix/__fixtures__/flake.11.lock diff --git a/lib/modules/manager/nix/__fixtures__/flake.11.lock b/lib/modules/manager/nix/__fixtures__/flake.11.lock new file mode 100644 index 00000000000000..edf8d7df1fe302 --- /dev/null +++ b/lib/modules/manager/nix/__fixtures__/flake.11.lock @@ -0,0 +1,87 @@ +{ + "nodes": { + "data-mesher": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1727355895, + "narHash": "sha256-grZIaLgk5GgoDuTt49RTCLBh458H4YJdIAU4B3onXRw=", + "rev": "c7e39452affcc0f89e023091524e38b3aaf109e9", + "type": "tarball", + "url": "https://git.clan.lol/api/v1/repos/clan/data-mesher/archive/c7e39452affcc0f89e023091524e38b3aaf109e9.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://git.clan.lol/clan/data-mesher/archive/main.tar.gz" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "data-mesher", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1726153070, + "narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1726871744, + "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "data-mesher": "data-mesher" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "data-mesher", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1726734507, + "narHash": "sha256-VUH5O5AcOSxb0uL/m34dDkxFKP6WLQ6y4I1B4+N3L2w=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "ee41a466c2255a3abe6bc50fc6be927cdee57a9f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 938496e08b199c..39cd19a1b0af97 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -12,6 +12,7 @@ const flake7Lock = Fixtures.get('flake.7.lock'); const flake8Lock = Fixtures.get('flake.8.lock'); const flake9Lock = Fixtures.get('flake.9.lock'); const flake10Lock = Fixtures.get('flake.10.lock'); +const flake11Lock = Fixtures.get('flake.11.lock'); describe('modules/manager/nix/extract', () => { it('returns null when no inputs', () => { @@ -105,4 +106,15 @@ describe('modules/manager/nix/extract', () => { }, ]); }); + + it('includes flake with tarball type', () => { + expect(extractPackageFile(flake11Lock, 'flake.lock')?.deps).toMatchObject([ + { + currentDigest: 'c7e39452affcc0f89e023091524e38b3aaf109e9', + datasource: 'git-refs', + depName: 'data-mesher', + packageName: 'https://git.clan.lol/clan/data-mesher', + }, + ]); + }); }); diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 44f62d8f1e4eb0..fe4e4c723ee51f 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -1,10 +1,17 @@ import { logger } from '../../../logger'; +import { regEx } from '../../../util/regex'; import { GitRefsDatasource } from '../../datasource/git-refs'; import type { PackageDependency, PackageFileContent } from '../types'; import { NixFlakeLock } from './schema'; // TODO: add support to update nixpkgs branches in flakes.nix using nixpkgsVersioning +// as documented upstream +// https://github.com/NixOS/nix/blob/master/doc/manual/source/protocols/tarball-fetcher.md#gitea-and-forgejo-support +const lockableHTTPTarballProtocol = regEx( + '^https://(.+)/(.+)/(.+)/archive/(.+).tar.gz$', +); + export function extractPackageFile( content: string, packageFile: string, @@ -95,6 +102,19 @@ export function extractPackageFile( packageName: `https://${flakeOriginal.host ?? 'git.sr.ht'}/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); break; + case 'tarball': + deps.push({ + depName, + currentValue: flakeLocked.ref, + currentDigest: flakeLocked.rev, + replaceString: flakeLocked.rev, + datasource: GitRefsDatasource.id, + packageName: (flakeOriginal.url ?? '').replace( + lockableHTTPTarballProtocol, + 'https://$1/$2/$3', + ), + }); + break; // istanbul ignore next: just a safeguard default: logger.debug( diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index e2e2cf2ea5e136..86520713290c37 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -7,6 +7,7 @@ export const InputType = z.enum([ 'gitlab', 'indirect', 'sourcehut', + 'tarball', ]); export const LockedInput = z.object({ From 04793300a9e349ac93128869add2f994bb8bf557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 23 Oct 2024 22:09:26 +0200 Subject: [PATCH 19/53] Inline tests --- .../manager/nix/__fixtures__/flake.1.lock | 7 - .../manager/nix/__fixtures__/flake.10.lock | 81 ---- .../manager/nix/__fixtures__/flake.11.lock | 87 ---- .../manager/nix/__fixtures__/flake.2.lock | 27 -- .../manager/nix/__fixtures__/flake.3.lock | 26 -- .../manager/nix/__fixtures__/flake.4.lock | 44 -- .../manager/nix/__fixtures__/flake.5.lock | 27 -- .../manager/nix/__fixtures__/flake.6.lock | 27 -- .../manager/nix/__fixtures__/flake.7.lock | 7 - .../manager/nix/__fixtures__/flake.8.lock | 28 -- .../manager/nix/__fixtures__/flake.9.lock | 25 -- lib/modules/manager/nix/extract.spec.ts | 398 +++++++++++++++++- 12 files changed, 386 insertions(+), 398 deletions(-) delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.1.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.10.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.11.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.2.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.3.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.4.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.5.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.6.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.7.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.8.lock delete mode 100644 lib/modules/manager/nix/__fixtures__/flake.9.lock diff --git a/lib/modules/manager/nix/__fixtures__/flake.1.lock b/lib/modules/manager/nix/__fixtures__/flake.1.lock deleted file mode 100644 index 5999137c97311a..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.1.lock +++ /dev/null @@ -1,7 +0,0 @@ -{ - "nodes": { - "root": {} - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.10.lock b/lib/modules/manager/nix/__fixtures__/flake.10.lock deleted file mode 100644 index 49f892f42cd3db..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.10.lock +++ /dev/null @@ -1,81 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-extra-pkgs": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - }, - "locked": { - "host": "github.corp.example.com", - "lastModified": 1728666512, - "narHash": "sha256-p+l16Zzyl2DXG695yks6KQP7NkjsnEksu5GBvtL1QYg=", - "owner": "my-org", - "repo": "nixpkgs-extra-pkgs", - "rev": "6bf2706348447df6f8b86b1c3e54f87b0afda84f", - "type": "github" - }, - "original": { - "host": "github.corp.example.com", - "owner": "my-org", - "repo": "nixpkgs-extra-pkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs-extra-pkgs": "nixpkgs-extra-pkgs" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.11.lock b/lib/modules/manager/nix/__fixtures__/flake.11.lock deleted file mode 100644 index edf8d7df1fe302..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.11.lock +++ /dev/null @@ -1,87 +0,0 @@ -{ - "nodes": { - "data-mesher": { - "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs", - "treefmt-nix": "treefmt-nix" - }, - "locked": { - "lastModified": 1727355895, - "narHash": "sha256-grZIaLgk5GgoDuTt49RTCLBh458H4YJdIAU4B3onXRw=", - "rev": "c7e39452affcc0f89e023091524e38b3aaf109e9", - "type": "tarball", - "url": "https://git.clan.lol/api/v1/repos/clan/data-mesher/archive/c7e39452affcc0f89e023091524e38b3aaf109e9.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://git.clan.lol/clan/data-mesher/archive/main.tar.gz" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "data-mesher", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1726153070, - "narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1726871744, - "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "data-mesher": "data-mesher" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "data-mesher", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1726734507, - "narHash": "sha256-VUH5O5AcOSxb0uL/m34dDkxFKP6WLQ6y4I1B4+N3L2w=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "ee41a466c2255a3abe6bc50fc6be927cdee57a9f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.2.lock b/lib/modules/manager/nix/__fixtures__/flake.2.lock deleted file mode 100644 index 8bbf80d08a6d05..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.2.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1720031269, - "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.3.lock b/lib/modules/manager/nix/__fixtures__/flake.3.lock deleted file mode 100644 index 4e715e4b122a14..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.3.lock +++ /dev/null @@ -1,26 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1728650607, - "narHash": "sha256-0lOnVTzRXzpk5uxbHLm3Ti3tyPAvirAIQDfwEUd8arg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "612ee628421ba2c1abca4c99684862f76cb3b089", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.4.lock b/lib/modules/manager/nix/__fixtures__/flake.4.lock deleted file mode 100644 index a11067f50b38fd..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.4.lock +++ /dev/null @@ -1,44 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1672057183, - "narHash": "sha256-GN7/10DNNvs1FPj9tlZA2qgNdFuYKKuS3qlHTqAxasQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "b139e44d78c36c69bcbb825b20dbfa51e7738347", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixpkgs-unstable", - "type": "indirect" - } - }, - "patchelf": { - "inputs": { - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1718457448, - "narHash": "sha256-FSoxTcRZMGHNJh8dNtKOkcUtjhmhU6yQXcZZfUPLhQM=", - "ref": "refs/heads/master", - "rev": "a0f54334df36770b335c051e540ba40afcbf8378", - "revCount": 844, - "type": "git", - "url": "https://github.com/NixOS/patchelf.git" - }, - "original": { - "type": "git", - "url": "https://github.com/NixOS/patchelf.git" - } - }, - "root": { - "inputs": { - "patchelf": "patchelf" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.5.lock b/lib/modules/manager/nix/__fixtures__/flake.5.lock deleted file mode 100644 index 9e6349fa1f1baa..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.5.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "ijq": { - "flake": false, - "locked": { - "lastModified": 1723569650, - "narHash": "sha256-Ho/sAhEUeSug52JALgjrKVUPCBe8+PovbJj/lniKxp8=", - "owner": "~gpanders", - "repo": "ijq", - "rev": "88f0d9ae98942bf49cba302c42b2a0f6e05f9b58", - "type": "sourcehut" - }, - "original": { - "owner": "~gpanders", - "repo": "ijq", - "type": "sourcehut" - } - }, - "root": { - "inputs": { - "ijq": "ijq" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.6.lock b/lib/modules/manager/nix/__fixtures__/flake.6.lock deleted file mode 100644 index 3b4e21a8331a78..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.6.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "home-manager": { - "flake": false, - "locked": { - "lastModified": 1728650932, - "narHash": "sha256-mGKzqdsRyLnGNl6WjEr7+sghGgBtYHhJQ4mjpgRTCsU=", - "owner": "rycee", - "repo": "home-manager", - "rev": "65ae9c147349829d3df0222151f53f79821c5134", - "type": "gitlab" - }, - "original": { - "owner": "rycee", - "repo": "home-manager", - "type": "gitlab" - } - }, - "root": { - "inputs": { - "home-manager": "home-manager" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.7.lock b/lib/modules/manager/nix/__fixtures__/flake.7.lock deleted file mode 100644 index fd1d70458c955d..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.7.lock +++ /dev/null @@ -1,7 +0,0 @@ -{ - "nodes": { - "root": {} - }, - "root": "root", - "version": 6 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.8.lock b/lib/modules/manager/nix/__fixtures__/flake.8.lock deleted file mode 100644 index ae61fdc2725739..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.8.lock +++ /dev/null @@ -1,28 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "ref": "nixos-unstable", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", - "shallow": true, - "type": "git", - "url": "https://github.com/NixOS/nixpkgs" - }, - "original": { - "ref": "nixos-unstable", - "shallow": true, - "type": "git", - "url": "https://github.com/NixOS/nixpkgs" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/__fixtures__/flake.9.lock b/lib/modules/manager/nix/__fixtures__/flake.9.lock deleted file mode 100644 index 30daa36f36423b..00000000000000 --- a/lib/modules/manager/nix/__fixtures__/flake.9.lock +++ /dev/null @@ -1,25 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1728538411, - "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 39cd19a1b0af97..b891f16609ce28 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -1,18 +1,392 @@ -import { Fixtures } from '../../../../test/fixtures'; import { GitRefsDatasource } from '../../datasource/git-refs'; import { extractPackageFile } from '.'; -const flake1Lock = Fixtures.get('flake.1.lock'); -const flake2Lock = Fixtures.get('flake.2.lock'); -const flake3Lock = Fixtures.get('flake.3.lock'); -const flake4Lock = Fixtures.get('flake.4.lock'); -const flake5Lock = Fixtures.get('flake.5.lock'); -const flake6Lock = Fixtures.get('flake.6.lock'); -const flake7Lock = Fixtures.get('flake.7.lock'); -const flake8Lock = Fixtures.get('flake.8.lock'); -const flake9Lock = Fixtures.get('flake.9.lock'); -const flake10Lock = Fixtures.get('flake.10.lock'); -const flake11Lock = Fixtures.get('flake.11.lock'); +const flake1Lock = `{ + "nodes": { + "root": {} + }, + "root": "root", + "version": 7 +}` +const flake2Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +}` +const flake3Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728650607, + "narHash": "sha256-0lOnVTzRXzpk5uxbHLm3Ti3tyPAvirAIQDfwEUd8arg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "612ee628421ba2c1abca4c99684862f76cb3b089", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +}` +const flake4Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1672057183, + "narHash": "sha256-GN7/10DNNvs1FPj9tlZA2qgNdFuYKKuS3qlHTqAxasQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b139e44d78c36c69bcbb825b20dbfa51e7738347", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixpkgs-unstable", + "type": "indirect" + } + }, + "patchelf": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1718457448, + "narHash": "sha256-FSoxTcRZMGHNJh8dNtKOkcUtjhmhU6yQXcZZfUPLhQM=", + "ref": "refs/heads/master", + "rev": "a0f54334df36770b335c051e540ba40afcbf8378", + "revCount": 844, + "type": "git", + "url": "https://github.com/NixOS/patchelf.git" + }, + "original": { + "type": "git", + "url": "https://github.com/NixOS/patchelf.git" + } + }, + "root": { + "inputs": { + "patchelf": "patchelf" + } + } + }, + "root": "root", + "version": 7 +}` +const flake5Lock = `{ + "nodes": { + "ijq": { + "flake": false, + "locked": { + "lastModified": 1723569650, + "narHash": "sha256-Ho/sAhEUeSug52JALgjrKVUPCBe8+PovbJj/lniKxp8=", + "owner": "~gpanders", + "repo": "ijq", + "rev": "88f0d9ae98942bf49cba302c42b2a0f6e05f9b58", + "type": "sourcehut" + }, + "original": { + "owner": "~gpanders", + "repo": "ijq", + "type": "sourcehut" + } + }, + "root": { + "inputs": { + "ijq": "ijq" + } + } + }, + "root": "root", + "version": 7 +}` +const flake6Lock = `{ + "nodes": { + "home-manager": { + "flake": false, + "locked": { + "lastModified": 1728650932, + "narHash": "sha256-mGKzqdsRyLnGNl6WjEr7+sghGgBtYHhJQ4mjpgRTCsU=", + "owner": "rycee", + "repo": "home-manager", + "rev": "65ae9c147349829d3df0222151f53f79821c5134", + "type": "gitlab" + }, + "original": { + "owner": "rycee", + "repo": "home-manager", + "type": "gitlab" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager" + } + } + }, + "root": "root", + "version": 7 +}` +const flake7Lock = `{ + "nodes": { + "root": {} + }, + "root": "root", + "version": 6 +}` +const flake8Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "ref": "nixos-unstable", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "shallow": true, + "type": "git", + "url": "https://github.com/NixOS/nixpkgs" + }, + "original": { + "ref": "nixos-unstable", + "shallow": true, + "type": "git", + "url": "https://github.com/NixOS/nixpkgs" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +}` +const flake9Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +}` +const flake10Lock = `{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-extra-pkgs": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "host": "github.corp.example.com", + "lastModified": 1728666512, + "narHash": "sha256-p+l16Zzyl2DXG695yks6KQP7NkjsnEksu5GBvtL1QYg=", + "owner": "my-org", + "repo": "nixpkgs-extra-pkgs", + "rev": "6bf2706348447df6f8b86b1c3e54f87b0afda84f", + "type": "github" + }, + "original": { + "host": "github.corp.example.com", + "owner": "my-org", + "repo": "nixpkgs-extra-pkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs-extra-pkgs": "nixpkgs-extra-pkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +}` +const flake11Lock = `{ + "nodes": { + "data-mesher": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1727355895, + "narHash": "sha256-grZIaLgk5GgoDuTt49RTCLBh458H4YJdIAU4B3onXRw=", + "rev": "c7e39452affcc0f89e023091524e38b3aaf109e9", + "type": "tarball", + "url": "https://git.clan.lol/api/v1/repos/clan/data-mesher/archive/c7e39452affcc0f89e023091524e38b3aaf109e9.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://git.clan.lol/clan/data-mesher/archive/main.tar.gz" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "data-mesher", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1726153070, + "narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1726871744, + "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "data-mesher": "data-mesher" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "data-mesher", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1726734507, + "narHash": "sha256-VUH5O5AcOSxb0uL/m34dDkxFKP6WLQ6y4I1B4+N3L2w=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "ee41a466c2255a3abe6bc50fc6be927cdee57a9f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +}` describe('modules/manager/nix/extract', () => { it('returns null when no inputs', () => { From 4bcf310a8d30e3f2eb7b8d12b886e6c6308249ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 23 Oct 2024 23:09:24 +0200 Subject: [PATCH 20/53] Revert fileMatch change --- lib/modules/manager/nix/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/index.ts b/lib/modules/manager/nix/index.ts index 9444bce8d06616..c9055734fc2fcf 100644 --- a/lib/modules/manager/nix/index.ts +++ b/lib/modules/manager/nix/index.ts @@ -6,7 +6,7 @@ export { updateArtifacts } from './artifacts'; export const supportsLockFileMaintenance = true; export const defaultConfig = { - fileMatch: ['(^|/)flake\\.lock'], + fileMatch: ['(^|/)flake\\.nix$'], commitMessageTopic: 'nix', commitMessageExtra: 'to {{newValue}}', enabled: false, From 0ecdb091f8299db6b8458b779d4f955235084121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Thu, 24 Oct 2024 17:50:03 +0200 Subject: [PATCH 21/53] Ignore none relevant cov failure --- lib/modules/manager/nix/extract.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index fe4e4c723ee51f..958b97380f7e81 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -109,6 +109,7 @@ export function extractPackageFile( currentDigest: flakeLocked.rev, replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, + // istanbul ignore next: type tarball always contains this link packageName: (flakeOriginal.url ?? '').replace( lockableHTTPTarballProtocol, 'https://$1/$2/$3', From ce71499d9478148e3e201611452143922aff95fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 2 Nov 2024 02:12:26 +0100 Subject: [PATCH 22/53] Review #1 --- lib/modules/manager/nix/artifacts.spec.ts | 29 +++++++++++++---------- lib/modules/manager/nix/artifacts.ts | 4 +++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/modules/manager/nix/artifacts.spec.ts b/lib/modules/manager/nix/artifacts.spec.ts index d9cca2268fdde9..7b741ee82208f4 100644 --- a/lib/modules/manager/nix/artifacts.spec.ts +++ b/lib/modules/manager/nix/artifacts.spec.ts @@ -36,14 +36,17 @@ process.env.CONTAINERBASE = 'true'; const config: UpdateArtifactsConfig = {}; const lockMaintenanceConfig = { ...config, isLockFileMaintenance: true }; const updateInputCmd = `nix \ ---extra-experimental-features 'nix-command flakes' \ + --extra-experimental-features nix-command \ + --extra-experimental-features flakes \ flake lock --update-input nixpkgs`; const updateInputTokenCmd = `nix \ ---extra-experimental-features 'nix-command flakes' \ + --extra-experimental-features nix-command \ + --extra-experimental-features flakes \ --extra-access-tokens github.com=token \ flake lock --update-input nixpkgs`; const lockfileMaintenanceCmd = `nix \ ---extra-experimental-features 'nix-command flakes' \ + --extra-experimental-features nix-command \ + --extra-experimental-features flakes \ flake update`; describe('modules/manager/nix/artifacts', () => { @@ -63,7 +66,7 @@ describe('modules/manager/nix/artifacts', () => { it('returns if no flake.lock found', async () => { const execSnapshots = mockExecAll(); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [], newPackageFileContent: '', config, @@ -83,7 +86,7 @@ describe('modules/manager/nix/artifacts', () => { ); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config, @@ -104,7 +107,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { ...config, constraints: { python: '3.7' } }, @@ -134,7 +137,7 @@ describe('modules/manager/nix/artifacts', () => { hostRules.find.mockReturnValueOnce({ token: 'token' }); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { ...config, constraints: { python: '3.7' } }, @@ -164,7 +167,7 @@ describe('modules/manager/nix/artifacts', () => { hostRules.find.mockReturnValueOnce({ token: 'x-access-token:token' }); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { ...config, constraints: { python: '3.7' } }, @@ -193,7 +196,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config: { ...config, constraints: { nix: '2.10.0' } }, @@ -238,7 +241,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config: { ...config, constraints: { nix: '2.10.0' } }, @@ -266,7 +269,7 @@ describe('modules/manager/nix/artifacts', () => { const execSnapshots = mockExecSequence([new Error('exec error')]); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config, @@ -291,7 +294,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new flake.lock'); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: '{}', config: lockMaintenanceConfig, @@ -320,7 +323,7 @@ describe('modules/manager/nix/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('new lock'); const res = await updateArtifacts({ - packageFileName: 'flake.lock', + packageFileName: 'flake.nix', updatedDeps: [{ depName: 'nixpkgs' }], newPackageFileContent: 'some new content', config: { diff --git a/lib/modules/manager/nix/artifacts.ts b/lib/modules/manager/nix/artifacts.ts index 4180f37bbc6f35..411cfb160d6f97 100644 --- a/lib/modules/manager/nix/artifacts.ts +++ b/lib/modules/manager/nix/artifacts.ts @@ -22,7 +22,9 @@ export async function updateArtifacts({ return null; } - let cmd = `nix --extra-experimental-features 'nix-command flakes' `; + let cmd = `nix \ + --extra-experimental-features nix-command \ + --extra-experimental-features flakes `; const token = findGithubToken( hostRules.find({ From c8363e5ecca9edc19479f9cd282536755532cac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 2 Nov 2024 02:20:59 +0100 Subject: [PATCH 23/53] Review pt. 2 --- lib/modules/manager/nix/schema.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index 86520713290c37..0d4961e80d0e67 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -11,17 +11,9 @@ export const InputType = z.enum([ ]); export const LockedInput = z.object({ - host: z.string().optional(), - lastModified: z.number(), - narHash: z.string(), - owner: z.string().optional(), - repo: z.string().optional(), ref: z.string().optional(), rev: z.string(), - revCount: z.number().optional(), - shallow: z.boolean().optional(), type: InputType, - url: z.string().optional(), }); export const OriginalInput = z.object({ @@ -42,7 +34,6 @@ export const NixInput = z.object({ export const NixFlakeLock = Json.pipe( z.object({ nodes: z.record(z.string(), NixInput), - root: z.literal('root').optional(), version: z.literal(7), }), ); From e2a3f507364262937392f91fb221d76e676d3855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 2 Nov 2024 03:36:08 +0100 Subject: [PATCH 24/53] Use getSiblingFileName --- lib/modules/manager/nix/extract.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 958b97380f7e81..b4e7151c532946 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -1,4 +1,5 @@ import { logger } from '../../../logger'; +import { getSiblingFileName } from '../../../util/fs'; import { regEx } from '../../../util/regex'; import { GitRefsDatasource } from '../../datasource/git-refs'; import type { PackageDependency, PackageFileContent } from '../types'; @@ -16,14 +17,16 @@ export function extractPackageFile( content: string, packageFile: string, ): PackageFileContent | null { - logger.trace(`nix.extractPackageFile(${packageFile})`); + const packageLockFile = getSiblingFileName(packageFile, 'flake.lock'); + + logger.trace(`nix.extractPackageFile(${packageLockFile})`); const deps: PackageDependency[] = []; const flakeLockParsed = NixFlakeLock.safeParse(content); if (!flakeLockParsed.success) { logger.debug( - { packageFile, error: flakeLockParsed.error }, + { packageLockFile, error: flakeLockParsed.error }, `invalid flake.lock file`, ); return null; @@ -50,7 +53,7 @@ export function extractPackageFile( // istanbul ignore if: if we are not in a root node then original and locked always exist which cannot be easily expressed in the type if (flakeLocked === undefined || flakeOriginal === undefined) { logger.debug( - { packageFile }, + { packageLockFile }, `Found empty flake input '${JSON.stringify(flakeInput)}', skipping`, ); continue; @@ -119,7 +122,7 @@ export function extractPackageFile( // istanbul ignore next: just a safeguard default: logger.debug( - { packageFile }, + { packageLockFile }, `Unknown flake.lock type "${flakeLocked.type}", skipping`, ); break; From 870297a7c8e8c70de0160e77734f99d30f5b02a6 Mon Sep 17 00:00:00 2001 From: Sandro Date: Wed, 6 Nov 2024 16:40:10 +0100 Subject: [PATCH 25/53] Apply suggestions from code review Co-authored-by: Michael Kriese --- lib/modules/manager/nix/extract.ts | 2 +- lib/modules/manager/nix/schema.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index b4e7151c532946..f0707648c4829d 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -41,7 +41,7 @@ export function extractPackageFile( } // skip all locked nodes which are not in the flake.nix and cannot be updated - // istanbul ignore next: a valid flake.lock file will never run into this + // istanbul ignore if: a valid flake.lock file will never run into this if (!(depName in (flakeLock.nodes['root'].inputs ?? []))) { continue; } diff --git a/lib/modules/manager/nix/schema.ts b/lib/modules/manager/nix/schema.ts index 0d4961e80d0e67..af8e0e33e95dbf 100644 --- a/lib/modules/manager/nix/schema.ts +++ b/lib/modules/manager/nix/schema.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; import { Json } from '../../../util/schema-utils'; -export const InputType = z.enum([ +const InputType = z.enum([ 'git', 'github', 'gitlab', @@ -10,13 +10,13 @@ export const InputType = z.enum([ 'tarball', ]); -export const LockedInput = z.object({ +const LockedInput = z.object({ ref: z.string().optional(), rev: z.string(), type: InputType, }); -export const OriginalInput = z.object({ +const OriginalInput = z.object({ host: z.string().optional(), owner: z.string().optional(), repo: z.string().optional(), @@ -25,7 +25,7 @@ export const OriginalInput = z.object({ url: z.string().optional(), }); -export const NixInput = z.object({ +const NixInput = z.object({ inputs: z.record(z.string(), z.string().or(z.array(z.string()))).optional(), locked: LockedInput.optional(), original: OriginalInput.optional(), From 23a0c059f6b2e813d53597b3f3ac339728858d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 6 Nov 2024 16:41:52 +0100 Subject: [PATCH 26/53] Log missing root node --- lib/modules/manager/nix/extract.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index f0707648c4829d..cbb8dd95dcf075 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -43,6 +43,10 @@ export function extractPackageFile( // skip all locked nodes which are not in the flake.nix and cannot be updated // istanbul ignore if: a valid flake.lock file will never run into this if (!(depName in (flakeLock.nodes['root'].inputs ?? []))) { + logger.debug( + { packageLockFile, error: flakeLockParsed.error }, + `invalid flake.lock file because cannot find "root" node`, + ); continue; } From c3252ff5df0d34379f60420e1416085caba9f8f2 Mon Sep 17 00:00:00 2001 From: Sandro Date: Wed, 6 Nov 2024 16:43:44 +0100 Subject: [PATCH 27/53] Update lib/modules/manager/nix/extract.ts Co-authored-by: Michael Kriese --- lib/modules/manager/nix/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index cbb8dd95dcf075..eb0afd56d71ed1 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -10,7 +10,7 @@ import { NixFlakeLock } from './schema'; // as documented upstream // https://github.com/NixOS/nix/blob/master/doc/manual/source/protocols/tarball-fetcher.md#gitea-and-forgejo-support const lockableHTTPTarballProtocol = regEx( - '^https://(.+)/(.+)/(.+)/archive/(.+).tar.gz$', + '^https://([^/]+)/([^/]+)/([^/]+)/archive/(.+).tar.gz$', ); export function extractPackageFile( From 3f0e8d949f4d2e16f626b8d565447dd5ca476907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 6 Nov 2024 16:46:23 +0100 Subject: [PATCH 28/53] Use named groups --- lib/modules/manager/nix/extract.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index eb0afd56d71ed1..226dbb15f49559 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -10,7 +10,7 @@ import { NixFlakeLock } from './schema'; // as documented upstream // https://github.com/NixOS/nix/blob/master/doc/manual/source/protocols/tarball-fetcher.md#gitea-and-forgejo-support const lockableHTTPTarballProtocol = regEx( - '^https://([^/]+)/([^/]+)/([^/]+)/archive/(.+).tar.gz$', + '^https://(?[^/]+)/(?[^/]+)/(?[^/]+)/archive/(?.+).tar.gz$', ); export function extractPackageFile( @@ -119,7 +119,7 @@ export function extractPackageFile( // istanbul ignore next: type tarball always contains this link packageName: (flakeOriginal.url ?? '').replace( lockableHTTPTarballProtocol, - 'https://$1/$2/$3', + 'https://$/$/$', ), }); break; From db6a562a5a453761c373a286d9108f55ca2d8313 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Wed, 6 Nov 2024 17:26:20 +0100 Subject: [PATCH 29/53] prettier-fix --- lib/modules/manager/nix/extract.spec.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index b891f16609ce28..3f32ff943cd934 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -7,7 +7,7 @@ const flake1Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake2Lock = `{ "nodes": { "nixpkgs": { @@ -34,7 +34,7 @@ const flake2Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake3Lock = `{ "nodes": { "nixpkgs": { @@ -60,7 +60,7 @@ const flake3Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake4Lock = `{ "nodes": { "nixpkgs": { @@ -104,7 +104,7 @@ const flake4Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake5Lock = `{ "nodes": { "ijq": { @@ -131,7 +131,7 @@ const flake5Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake6Lock = `{ "nodes": { "home-manager": { @@ -158,14 +158,14 @@ const flake6Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake7Lock = `{ "nodes": { "root": {} }, "root": "root", "version": 6 -}` +}`; const flake8Lock = `{ "nodes": { "nixpkgs": { @@ -193,7 +193,7 @@ const flake8Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake9Lock = `{ "nodes": { "nixpkgs": { @@ -218,7 +218,7 @@ const flake9Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake10Lock = `{ "nodes": { "flake-utils": { @@ -299,7 +299,7 @@ const flake10Lock = `{ }, "root": "root", "version": 7 -}` +}`; const flake11Lock = `{ "nodes": { "data-mesher": { @@ -386,7 +386,7 @@ const flake11Lock = `{ }, "root": "root", "version": 7 -}` +}`; describe('modules/manager/nix/extract', () => { it('returns null when no inputs', () => { From 27fc2cff70ee438128023603e08389c82abf259b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 8 Nov 2024 17:35:14 +0100 Subject: [PATCH 30/53] Fix istanbul ignore --- lib/modules/manager/nix/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 226dbb15f49559..36774b918d5411 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -41,7 +41,7 @@ export function extractPackageFile( } // skip all locked nodes which are not in the flake.nix and cannot be updated - // istanbul ignore if: a valid flake.lock file will never run into this + // istanbul ignore next: a valid flake.lock file will never run into this if (!(depName in (flakeLock.nodes['root'].inputs ?? []))) { logger.debug( { packageLockFile, error: flakeLockParsed.error }, From 96fd373ed8e0086d36fe357b22d29c362dd84f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 8 Nov 2024 20:29:43 +0100 Subject: [PATCH 31/53] Try to fix coverage --- lib/modules/manager/nix/extract.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 36774b918d5411..9dd5799d343196 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -116,8 +116,10 @@ export function extractPackageFile( currentDigest: flakeLocked.rev, replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, - // istanbul ignore next: type tarball always contains this link - packageName: (flakeOriginal.url ?? '').replace( + // type tarball always contains this link + packageName: ( + flakeOriginal.url ?? /* istanbul ignore next */ '' + ).replace( lockableHTTPTarballProtocol, 'https://$/$/$', ), From 7eed106edf4bf56a7ef9e0fe7bea485433cbf10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 27 Nov 2024 23:44:40 +0100 Subject: [PATCH 32/53] Work around istanbul issue --- lib/modules/manager/nix/extract.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 9dd5799d343196..7c678511426b06 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -41,8 +41,8 @@ export function extractPackageFile( } // skip all locked nodes which are not in the flake.nix and cannot be updated - // istanbul ignore next: a valid flake.lock file will never run into this - if (!(depName in (flakeLock.nodes['root'].inputs ?? []))) { + const rootInputs = flakeLock.nodes['root'].inputs; + if (!rootInputs || !(depName in rootInputs)) { logger.debug( { packageLockFile, error: flakeLockParsed.error }, `invalid flake.lock file because cannot find "root" node`, From f9c72474df022c80a1e5cd11f3525d646aba5d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Thu, 5 Dec 2024 17:51:01 +0100 Subject: [PATCH 33/53] Revert "Revert fileMatch change" This reverts commit 4bcf310a8d30e3f2eb7b8d12b886e6c6308249ba. --- lib/modules/manager/nix/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/index.ts b/lib/modules/manager/nix/index.ts index c9055734fc2fcf..9444bce8d06616 100644 --- a/lib/modules/manager/nix/index.ts +++ b/lib/modules/manager/nix/index.ts @@ -6,7 +6,7 @@ export { updateArtifacts } from './artifacts'; export const supportsLockFileMaintenance = true; export const defaultConfig = { - fileMatch: ['(^|/)flake\\.nix$'], + fileMatch: ['(^|/)flake\\.lock'], commitMessageTopic: 'nix', commitMessageExtra: 'to {{newValue}}', enabled: false, From 149b2f6fc0cd135c196df3f270e3fedb741786b1 Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Thu, 5 Dec 2024 16:31:43 +0000 Subject: [PATCH 34/53] fix bug where 'flake.nix' was being parsed, not 'flake.lock' --- lib/modules/manager/nix/extract.spec.ts | 58 +++++++++++++++---------- lib/modules/manager/nix/extract.ts | 13 +++--- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 3f32ff943cd934..51af3c983fb218 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -1,6 +1,9 @@ +import { fs } from '../../../../test/util'; import { GitRefsDatasource } from '../../datasource/git-refs'; import { extractPackageFile } from '.'; +jest.mock('../../../util/fs'); + const flake1Lock = `{ "nodes": { "root": {} @@ -389,12 +392,14 @@ const flake11Lock = `{ }`; describe('modules/manager/nix/extract', () => { - it('returns null when no inputs', () => { - expect(extractPackageFile(flake1Lock, 'flake.lock')).toBeNull(); + it('returns null when no inputs', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake1Lock); + expect(await extractPackageFile('', 'flake.nix')).toBeNull(); }); - it('returns nixpkgs input', () => { - expect(extractPackageFile(flake2Lock, 'flake.lock')?.deps).toEqual([ + it('returns nixpkgs input', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake2Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toEqual([ { depName: 'nixpkgs', currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', @@ -406,8 +411,9 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes nixpkgs with no explicit ref', () => { - expect(extractPackageFile(flake3Lock, 'flake.lock')?.deps).toMatchObject([ + it('includes nixpkgs with no explicit ref', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake3Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ { currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', datasource: 'git-refs', @@ -417,8 +423,9 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes patchelf from HEAD', () => { - expect(extractPackageFile(flake4Lock, 'flake.lock')?.deps).toMatchObject([ + it('includes patchelf from HEAD', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake4Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ { currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', datasource: 'git-refs', @@ -428,8 +435,9 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes ijq from sourcehut without a flake', () => { - expect(extractPackageFile(flake5Lock, 'flake.lock')?.deps).toMatchObject([ + it('includes ijq from sourcehut without a flake', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake5Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ { currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', datasource: 'git-refs', @@ -439,8 +447,9 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes home-manager from gitlab', () => { - expect(extractPackageFile(flake6Lock, 'flake.lock')?.deps).toMatchObject([ + it('includes home-manager from gitlab', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake6Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ { currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', datasource: 'git-refs', @@ -450,12 +459,14 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('test other version', () => { - expect(extractPackageFile(flake7Lock, 'flake.lock')).toBeNull(); + it('test other version', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake7Lock); + expect(await extractPackageFile('', 'flake.nix')).toBeNull(); }); - it('includes nixpkgs with ref and shallow arguments', () => { - expect(extractPackageFile(flake8Lock, 'flake.lock')?.deps).toMatchObject([ + it('includes nixpkgs with ref and shallow arguments', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake8Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ { currentDigest: '5633bcff0c6162b9e4b5f1264264611e950c8ec7', datasource: 'git-refs', @@ -465,12 +476,14 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes nixpkgs but using indirect type that cannot be updated', () => { - expect(extractPackageFile(flake9Lock, 'flake.lock')).toBeNull(); + it('includes nixpkgs but using indirect type that cannot be updated', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake9Lock); + expect(await extractPackageFile('', 'flake.nix')).toBeNull(); }); - it('includes flake from GitHub Enterprise', () => { - expect(extractPackageFile(flake10Lock, 'flake.lock')?.deps).toMatchObject([ + it('includes flake from GitHub Enterprise', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake10Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ { currentDigest: '6bf2706348447df6f8b86b1c3e54f87b0afda84f', datasource: 'git-refs', @@ -481,8 +494,9 @@ describe('modules/manager/nix/extract', () => { ]); }); - it('includes flake with tarball type', () => { - expect(extractPackageFile(flake11Lock, 'flake.lock')?.deps).toMatchObject([ + it('includes flake with tarball type', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake11Lock); + expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ { currentDigest: 'c7e39452affcc0f89e023091524e38b3aaf109e9', datasource: 'git-refs', diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 7c678511426b06..96f6dc6938ed5b 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -1,5 +1,5 @@ import { logger } from '../../../logger'; -import { getSiblingFileName } from '../../../util/fs'; +import { getSiblingFileName, readLocalFile } from '../../../util/fs'; import { regEx } from '../../../util/regex'; import { GitRefsDatasource } from '../../datasource/git-refs'; import type { PackageDependency, PackageFileContent } from '../types'; @@ -13,19 +13,20 @@ const lockableHTTPTarballProtocol = regEx( '^https://(?[^/]+)/(?[^/]+)/(?[^/]+)/archive/(?.+).tar.gz$', ); -export function extractPackageFile( +export async function extractPackageFile( content: string, packageFile: string, -): PackageFileContent | null { +): Promise { const packageLockFile = getSiblingFileName(packageFile, 'flake.lock'); + const lockContents = await readLocalFile(packageLockFile); logger.trace(`nix.extractPackageFile(${packageLockFile})`); const deps: PackageDependency[] = []; - const flakeLockParsed = NixFlakeLock.safeParse(content); + const flakeLockParsed = NixFlakeLock.safeParse(lockContents); if (!flakeLockParsed.success) { - logger.debug( + logger.error( { packageLockFile, error: flakeLockParsed.error }, `invalid flake.lock file`, ); @@ -43,7 +44,7 @@ export function extractPackageFile( // skip all locked nodes which are not in the flake.nix and cannot be updated const rootInputs = flakeLock.nodes['root'].inputs; if (!rootInputs || !(depName in rootInputs)) { - logger.debug( + logger.error( { packageLockFile, error: flakeLockParsed.error }, `invalid flake.lock file because cannot find "root" node`, ); From 9fbea6b7e3243268f3cd88119c13540f968219e7 Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Thu, 5 Dec 2024 16:42:32 +0000 Subject: [PATCH 35/53] fix readLocalFile ref to use string-returning version with assumed utf8 --- lib/modules/manager/nix/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 96f6dc6938ed5b..b6990d9ca21229 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -18,7 +18,7 @@ export async function extractPackageFile( packageFile: string, ): Promise { const packageLockFile = getSiblingFileName(packageFile, 'flake.lock'); - const lockContents = await readLocalFile(packageLockFile); + const lockContents = await readLocalFile(packageLockFile, 'utf8'); logger.trace(`nix.extractPackageFile(${packageLockFile})`); From 70912bf17f9106b2a23cff99eefe508faa0aaa12 Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Thu, 5 Dec 2024 16:48:43 +0000 Subject: [PATCH 36/53] revert earlier debug->error log changes; improve invalid root node log msg --- lib/modules/manager/nix/extract.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index b6990d9ca21229..bccfcbdf2edd8c 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -26,7 +26,7 @@ export async function extractPackageFile( const flakeLockParsed = NixFlakeLock.safeParse(lockContents); if (!flakeLockParsed.success) { - logger.error( + logger.debug( { packageLockFile, error: flakeLockParsed.error }, `invalid flake.lock file`, ); @@ -44,9 +44,9 @@ export async function extractPackageFile( // skip all locked nodes which are not in the flake.nix and cannot be updated const rootInputs = flakeLock.nodes['root'].inputs; if (!rootInputs || !(depName in rootInputs)) { - logger.error( + logger.debug( { packageLockFile, error: flakeLockParsed.error }, - `invalid flake.lock file because cannot find "root" node`, + `flake.lock file cannot find "root" node or reference to ${depName}`, ); continue; } From d8f4cc5e90b5fc6ec217f8c9148bce28a397fa59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 7 Dec 2024 00:40:54 +0100 Subject: [PATCH 37/53] Reapply "Revert fileMatch change" This reverts commit f9c72474df022c80a1e5cd11f3525d646aba5d56. --- lib/modules/manager/nix/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/index.ts b/lib/modules/manager/nix/index.ts index fb32ad33d83bef..abbe3e6ec3e84f 100644 --- a/lib/modules/manager/nix/index.ts +++ b/lib/modules/manager/nix/index.ts @@ -8,7 +8,7 @@ export const supportsLockFileMaintenance = true; export const url = 'https://nix.dev'; export const defaultConfig = { - fileMatch: ['(^|/)flake\\.lock'], + fileMatch: ['(^|/)flake\\.nix$'], commitMessageTopic: 'nix', commitMessageExtra: 'to {{newValue}}', enabled: false, From 31d2a070aecd85cb30630321824e0df64c1f646c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 7 Dec 2024 00:55:08 +0100 Subject: [PATCH 38/53] Expect full output --- lib/modules/manager/nix/extract.spec.ts | 150 +++++++++++++----------- 1 file changed, 83 insertions(+), 67 deletions(-) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 51af3c983fb218..82f318f9c13b6a 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -399,64 +399,74 @@ describe('modules/manager/nix/extract', () => { it('returns nixpkgs input', async () => { fs.readLocalFile.mockResolvedValueOnce(flake2Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toEqual([ - { - depName: 'nixpkgs', - currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', - currentValue: 'nixos-unstable', - datasource: GitRefsDatasource.id, - packageName: 'https://github.com/NixOS/nixpkgs', - replaceString: '9f4128e00b0ae8ec65918efeba59db998750ead6', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toEqual({ + deps: [ + { + depName: 'nixpkgs', + currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6', + currentValue: 'nixos-unstable', + datasource: GitRefsDatasource.id, + packageName: 'https://github.com/NixOS/nixpkgs', + replaceString: '9f4128e00b0ae8ec65918efeba59db998750ead6', + }, + ], + }); }); it('includes nixpkgs with no explicit ref', async () => { fs.readLocalFile.mockResolvedValueOnce(flake3Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ - { - currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', - datasource: 'git-refs', - depName: 'nixpkgs', - packageName: 'https://github.com/NixOS/nixpkgs', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ + deps: [ + { + currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089', + datasource: 'git-refs', + depName: 'nixpkgs', + packageName: 'https://github.com/NixOS/nixpkgs', + }, + ], + }); }); it('includes patchelf from HEAD', async () => { fs.readLocalFile.mockResolvedValueOnce(flake4Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ - { - currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', - datasource: 'git-refs', - depName: 'patchelf', - packageName: 'https://github.com/NixOS/patchelf.git', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ + deps: [ + { + currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378', + datasource: 'git-refs', + depName: 'patchelf', + packageName: 'https://github.com/NixOS/patchelf.git', + }, + ], + }); }); it('includes ijq from sourcehut without a flake', async () => { fs.readLocalFile.mockResolvedValueOnce(flake5Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ - { - currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', - datasource: 'git-refs', - depName: 'ijq', - packageName: 'https://git.sr.ht/~gpanders/ijq', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ + deps: [ + { + currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58', + datasource: 'git-refs', + depName: 'ijq', + packageName: 'https://git.sr.ht/~gpanders/ijq', + }, + ], + }); }); it('includes home-manager from gitlab', async () => { fs.readLocalFile.mockResolvedValueOnce(flake6Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ - { - currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', - datasource: 'git-refs', - depName: 'home-manager', - packageName: 'https://gitlab.com/rycee/home-manager', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ + deps: [ + { + currentDigest: '65ae9c147349829d3df0222151f53f79821c5134', + datasource: 'git-refs', + depName: 'home-manager', + packageName: 'https://gitlab.com/rycee/home-manager', + }, + ], + }); }); it('test other version', async () => { @@ -466,14 +476,16 @@ describe('modules/manager/nix/extract', () => { it('includes nixpkgs with ref and shallow arguments', async () => { fs.readLocalFile.mockResolvedValueOnce(flake8Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ - { - currentDigest: '5633bcff0c6162b9e4b5f1264264611e950c8ec7', - datasource: 'git-refs', - depName: 'nixpkgs', - packageName: 'https://github.com/NixOS/nixpkgs', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ + deps: [ + { + currentDigest: '5633bcff0c6162b9e4b5f1264264611e950c8ec7', + datasource: 'git-refs', + depName: 'nixpkgs', + packageName: 'https://github.com/NixOS/nixpkgs', + }, + ], + }); }); it('includes nixpkgs but using indirect type that cannot be updated', async () => { @@ -483,26 +495,30 @@ describe('modules/manager/nix/extract', () => { it('includes flake from GitHub Enterprise', async () => { fs.readLocalFile.mockResolvedValueOnce(flake10Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ - { - currentDigest: '6bf2706348447df6f8b86b1c3e54f87b0afda84f', - datasource: 'git-refs', - depName: 'nixpkgs-extra-pkgs', - packageName: - 'https://github.corp.example.com/my-org/nixpkgs-extra-pkgs', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ + deps: [ + { + currentDigest: '6bf2706348447df6f8b86b1c3e54f87b0afda84f', + datasource: 'git-refs', + depName: 'nixpkgs-extra-pkgs', + packageName: + 'https://github.corp.example.com/my-org/nixpkgs-extra-pkgs', + }, + ], + }); }); it('includes flake with tarball type', async () => { fs.readLocalFile.mockResolvedValueOnce(flake11Lock); - expect((await extractPackageFile('', 'flake.nix'))?.deps).toMatchObject([ - { - currentDigest: 'c7e39452affcc0f89e023091524e38b3aaf109e9', - datasource: 'git-refs', - depName: 'data-mesher', - packageName: 'https://git.clan.lol/clan/data-mesher', - }, - ]); + expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ + deps: [ + { + currentDigest: 'c7e39452affcc0f89e023091524e38b3aaf109e9', + datasource: 'git-refs', + depName: 'data-mesher', + packageName: 'https://git.clan.lol/clan/data-mesher', + }, + ], + }); }); }); From ed2260553a802c0fa610b3c42b98335c0c78f57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 7 Dec 2024 00:59:23 +0100 Subject: [PATCH 39/53] Remove unused fallback --- lib/modules/manager/nix/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index bccfcbdf2edd8c..f51e2962b4bdca 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -119,7 +119,7 @@ export async function extractPackageFile( datasource: GitRefsDatasource.id, // type tarball always contains this link packageName: ( - flakeOriginal.url ?? /* istanbul ignore next */ '' + flakeOriginal.url! ).replace( lockableHTTPTarballProtocol, 'https://$/$/$', From c6591510b441eebb587fe7e7851c7a944c45978d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 7 Dec 2024 01:01:14 +0100 Subject: [PATCH 40/53] Use entries instead of keys --- lib/modules/manager/nix/extract.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index f51e2962b4bdca..99d1ae0563c5e6 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -35,7 +35,7 @@ export async function extractPackageFile( const flakeLock = flakeLockParsed.data; - for (const depName of Object.keys(flakeLock.nodes)) { + for (const [depName, flakeInput] of Object.entries(flakeLock.nodes)) { // the root input is a magic string for the entrypoint and only references other flake inputs if (depName === 'root') { continue; @@ -51,7 +51,6 @@ export async function extractPackageFile( continue; } - const flakeInput = flakeLock.nodes[depName]; const flakeLocked = flakeInput.locked; const flakeOriginal = flakeInput.original; From 87a43c9b66fefc871d4cfb6c21909c30a0d17279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 7 Dec 2024 01:02:04 +0100 Subject: [PATCH 41/53] Move const out of loop --- lib/modules/manager/nix/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 99d1ae0563c5e6..ac8919abefae99 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -34,6 +34,7 @@ export async function extractPackageFile( } const flakeLock = flakeLockParsed.data; + const rootInputs = flakeLock.nodes['root'].inputs; for (const [depName, flakeInput] of Object.entries(flakeLock.nodes)) { // the root input is a magic string for the entrypoint and only references other flake inputs @@ -42,7 +43,6 @@ export async function extractPackageFile( } // skip all locked nodes which are not in the flake.nix and cannot be updated - const rootInputs = flakeLock.nodes['root'].inputs; if (!rootInputs || !(depName in rootInputs)) { logger.debug( { packageLockFile, error: flakeLockParsed.error }, From d2c3b5edf4772c883cb832f523cacf0483db0a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 7 Dec 2024 01:03:27 +0100 Subject: [PATCH 42/53] Fix prettier --- lib/modules/manager/nix/extract.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index ac8919abefae99..7c7f2d8d523740 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -117,9 +117,7 @@ export async function extractPackageFile( replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, // type tarball always contains this link - packageName: ( - flakeOriginal.url! - ).replace( + packageName: (flakeOriginal.url!).replace( lockableHTTPTarballProtocol, 'https://$/$/$', ), From 3e11881f4b36af005ecc0078fa32a245c93f4090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Tue, 10 Dec 2024 00:07:44 +0100 Subject: [PATCH 43/53] Fix prettier --- lib/modules/manager/nix/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 7c7f2d8d523740..3984519406fca8 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -117,7 +117,7 @@ export async function extractPackageFile( replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, // type tarball always contains this link - packageName: (flakeOriginal.url!).replace( + packageName: flakeOriginal.url!.replace( lockableHTTPTarballProtocol, 'https://$/$/$', ), From 0a9af09b78af4d00f86afb8c24855e529f0b183c Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Tue, 10 Dec 2024 19:16:43 +0000 Subject: [PATCH 44/53] Add documentation on 'depName' and 'packageName' fields for nix --- lib/modules/manager/nix/readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/modules/manager/nix/readme.md b/lib/modules/manager/nix/readme.md index c1357a8519bd20..af3d80c5b0b05e 100644 --- a/lib/modules/manager/nix/readme.md +++ b/lib/modules/manager/nix/readme.md @@ -2,3 +2,8 @@ The [`nix`](https://github.com/NixOS/nix) manager supports: - [`lockFileMaintenance`](../../../configuration-options.md#lockfilemaintenance) updates for `flake.lock` - input updates for `flake.lock` + +For specifying `packageRules` it is important to know how `depName` and `packageName` are defined for nix updates: + +- The `depName` field is equal to the nix flake input name, eg. `nix.inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";` would have the `depName` of `nixpkgs` +- The `packageName` field is equal to the fully-qualified root URL of the package source, eg. `https://github.com/NixOS/nixpkgs` for the above example. From 7e76bfd6e3100af350270f45e6e6bc5ca8708cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Tue, 10 Dec 2024 20:18:01 +0100 Subject: [PATCH 45/53] Reduce noisy logs --- lib/modules/manager/nix/extract.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 3984519406fca8..ffbf6b7c5e6631 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -36,18 +36,19 @@ export async function extractPackageFile( const flakeLock = flakeLockParsed.data; const rootInputs = flakeLock.nodes['root'].inputs; + if (!rootInputs) { + logger.debug({ packageLockFile, error: flakeLockParsed.error }, `flake.lock is missing "root" node`); + return null; + } + for (const [depName, flakeInput] of Object.entries(flakeLock.nodes)) { // the root input is a magic string for the entrypoint and only references other flake inputs if (depName === 'root') { continue; } - // skip all locked nodes which are not in the flake.nix and cannot be updated - if (!rootInputs || !(depName in rootInputs)) { - logger.debug( - { packageLockFile, error: flakeLockParsed.error }, - `flake.lock file cannot find "root" node or reference to ${depName}`, - ); + // skip all locked nodes which cannot be updated + if (!(depName in rootInputs)) { continue; } From 0c1fc74f1674959ebc6dd4e7db791da254a785fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Tue, 10 Dec 2024 20:32:57 +0100 Subject: [PATCH 46/53] Fix prettier... --- lib/modules/manager/nix/extract.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index ffbf6b7c5e6631..e772ddea36bf09 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -37,7 +37,10 @@ export async function extractPackageFile( const rootInputs = flakeLock.nodes['root'].inputs; if (!rootInputs) { - logger.debug({ packageLockFile, error: flakeLockParsed.error }, `flake.lock is missing "root" node`); + logger.debug( + { packageLockFile, error: flakeLockParsed.error }, + `flake.lock is missing "root" node`, + ); return null; } From 27a61a256f702b7d192dd3c1afeafe7a96a79628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Thu, 23 Jan 2025 14:15:34 +0100 Subject: [PATCH 47/53] Move test fixtures next to tests --- lib/modules/manager/nix/extract.spec.ts | 768 ++++++++++++------------ 1 file changed, 389 insertions(+), 379 deletions(-) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 82f318f9c13b6a..49f3b90fd78bbb 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -11,385 +11,6 @@ const flake1Lock = `{ "root": "root", "version": 7 }`; -const flake2Lock = `{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1720031269, - "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake3Lock = `{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1728650607, - "narHash": "sha256-0lOnVTzRXzpk5uxbHLm3Ti3tyPAvirAIQDfwEUd8arg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "612ee628421ba2c1abca4c99684862f76cb3b089", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake4Lock = `{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1672057183, - "narHash": "sha256-GN7/10DNNvs1FPj9tlZA2qgNdFuYKKuS3qlHTqAxasQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "b139e44d78c36c69bcbb825b20dbfa51e7738347", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixpkgs-unstable", - "type": "indirect" - } - }, - "patchelf": { - "inputs": { - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1718457448, - "narHash": "sha256-FSoxTcRZMGHNJh8dNtKOkcUtjhmhU6yQXcZZfUPLhQM=", - "ref": "refs/heads/master", - "rev": "a0f54334df36770b335c051e540ba40afcbf8378", - "revCount": 844, - "type": "git", - "url": "https://github.com/NixOS/patchelf.git" - }, - "original": { - "type": "git", - "url": "https://github.com/NixOS/patchelf.git" - } - }, - "root": { - "inputs": { - "patchelf": "patchelf" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake5Lock = `{ - "nodes": { - "ijq": { - "flake": false, - "locked": { - "lastModified": 1723569650, - "narHash": "sha256-Ho/sAhEUeSug52JALgjrKVUPCBe8+PovbJj/lniKxp8=", - "owner": "~gpanders", - "repo": "ijq", - "rev": "88f0d9ae98942bf49cba302c42b2a0f6e05f9b58", - "type": "sourcehut" - }, - "original": { - "owner": "~gpanders", - "repo": "ijq", - "type": "sourcehut" - } - }, - "root": { - "inputs": { - "ijq": "ijq" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake6Lock = `{ - "nodes": { - "home-manager": { - "flake": false, - "locked": { - "lastModified": 1728650932, - "narHash": "sha256-mGKzqdsRyLnGNl6WjEr7+sghGgBtYHhJQ4mjpgRTCsU=", - "owner": "rycee", - "repo": "home-manager", - "rev": "65ae9c147349829d3df0222151f53f79821c5134", - "type": "gitlab" - }, - "original": { - "owner": "rycee", - "repo": "home-manager", - "type": "gitlab" - } - }, - "root": { - "inputs": { - "home-manager": "home-manager" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake7Lock = `{ - "nodes": { - "root": {} - }, - "root": "root", - "version": 6 -}`; -const flake8Lock = `{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "ref": "nixos-unstable", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", - "shallow": true, - "type": "git", - "url": "https://github.com/NixOS/nixpkgs" - }, - "original": { - "ref": "nixos-unstable", - "shallow": true, - "type": "git", - "url": "https://github.com/NixOS/nixpkgs" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake9Lock = `{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1728538411, - "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake10Lock = `{ - "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-extra-pkgs": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - }, - "locked": { - "host": "github.corp.example.com", - "lastModified": 1728666512, - "narHash": "sha256-p+l16Zzyl2DXG695yks6KQP7NkjsnEksu5GBvtL1QYg=", - "owner": "my-org", - "repo": "nixpkgs-extra-pkgs", - "rev": "6bf2706348447df6f8b86b1c3e54f87b0afda84f", - "type": "github" - }, - "original": { - "host": "github.corp.example.com", - "owner": "my-org", - "repo": "nixpkgs-extra-pkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs-extra-pkgs": "nixpkgs-extra-pkgs" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -}`; -const flake11Lock = `{ - "nodes": { - "data-mesher": { - "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs", - "treefmt-nix": "treefmt-nix" - }, - "locked": { - "lastModified": 1727355895, - "narHash": "sha256-grZIaLgk5GgoDuTt49RTCLBh458H4YJdIAU4B3onXRw=", - "rev": "c7e39452affcc0f89e023091524e38b3aaf109e9", - "type": "tarball", - "url": "https://git.clan.lol/api/v1/repos/clan/data-mesher/archive/c7e39452affcc0f89e023091524e38b3aaf109e9.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://git.clan.lol/clan/data-mesher/archive/main.tar.gz" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "data-mesher", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1726153070, - "narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1726871744, - "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "data-mesher": "data-mesher" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "data-mesher", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1726734507, - "narHash": "sha256-VUH5O5AcOSxb0uL/m34dDkxFKP6WLQ6y4I1B4+N3L2w=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "ee41a466c2255a3abe6bc50fc6be927cdee57a9f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -}`; describe('modules/manager/nix/extract', () => { it('returns null when no inputs', async () => { @@ -397,6 +18,34 @@ describe('modules/manager/nix/extract', () => { expect(await extractPackageFile('', 'flake.nix')).toBeNull(); }); + const flake2Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 + }`; + it('returns nixpkgs input', async () => { fs.readLocalFile.mockResolvedValueOnce(flake2Lock); expect(await extractPackageFile('', 'flake.nix')).toEqual({ @@ -413,6 +62,33 @@ describe('modules/manager/nix/extract', () => { }); }); + const flake3Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728650607, + "narHash": "sha256-0lOnVTzRXzpk5uxbHLm3Ti3tyPAvirAIQDfwEUd8arg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "612ee628421ba2c1abca4c99684862f76cb3b089", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes nixpkgs with no explicit ref', async () => { fs.readLocalFile.mockResolvedValueOnce(flake3Lock); expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ @@ -427,6 +103,51 @@ describe('modules/manager/nix/extract', () => { }); }); + const flake4Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1672057183, + "narHash": "sha256-GN7/10DNNvs1FPj9tlZA2qgNdFuYKKuS3qlHTqAxasQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b139e44d78c36c69bcbb825b20dbfa51e7738347", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixpkgs-unstable", + "type": "indirect" + } + }, + "patchelf": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1718457448, + "narHash": "sha256-FSoxTcRZMGHNJh8dNtKOkcUtjhmhU6yQXcZZfUPLhQM=", + "ref": "refs/heads/master", + "rev": "a0f54334df36770b335c051e540ba40afcbf8378", + "revCount": 844, + "type": "git", + "url": "https://github.com/NixOS/patchelf.git" + }, + "original": { + "type": "git", + "url": "https://github.com/NixOS/patchelf.git" + } + }, + "root": { + "inputs": { + "patchelf": "patchelf" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes patchelf from HEAD', async () => { fs.readLocalFile.mockResolvedValueOnce(flake4Lock); expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ @@ -441,6 +162,34 @@ describe('modules/manager/nix/extract', () => { }); }); + const flake5Lock = `{ + "nodes": { + "ijq": { + "flake": false, + "locked": { + "lastModified": 1723569650, + "narHash": "sha256-Ho/sAhEUeSug52JALgjrKVUPCBe8+PovbJj/lniKxp8=", + "owner": "~gpanders", + "repo": "ijq", + "rev": "88f0d9ae98942bf49cba302c42b2a0f6e05f9b58", + "type": "sourcehut" + }, + "original": { + "owner": "~gpanders", + "repo": "ijq", + "type": "sourcehut" + } + }, + "root": { + "inputs": { + "ijq": "ijq" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes ijq from sourcehut without a flake', async () => { fs.readLocalFile.mockResolvedValueOnce(flake5Lock); expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ @@ -455,6 +204,34 @@ describe('modules/manager/nix/extract', () => { }); }); + const flake6Lock = `{ + "nodes": { + "home-manager": { + "flake": false, + "locked": { + "lastModified": 1728650932, + "narHash": "sha256-mGKzqdsRyLnGNl6WjEr7+sghGgBtYHhJQ4mjpgRTCsU=", + "owner": "rycee", + "repo": "home-manager", + "rev": "65ae9c147349829d3df0222151f53f79821c5134", + "type": "gitlab" + }, + "original": { + "owner": "rycee", + "repo": "home-manager", + "type": "gitlab" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes home-manager from gitlab', async () => { fs.readLocalFile.mockResolvedValueOnce(flake6Lock); expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ @@ -469,11 +246,48 @@ describe('modules/manager/nix/extract', () => { }); }); + const flake7Lock = `{ + "nodes": { + "root": {} + }, + "root": "root", + "version": 6 + }`; + it('test other version', async () => { fs.readLocalFile.mockResolvedValueOnce(flake7Lock); expect(await extractPackageFile('', 'flake.nix')).toBeNull(); }); + const flake8Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "ref": "nixos-unstable", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "shallow": true, + "type": "git", + "url": "https://github.com/NixOS/nixpkgs" + }, + "original": { + "ref": "nixos-unstable", + "shallow": true, + "type": "git", + "url": "https://github.com/NixOS/nixpkgs" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes nixpkgs with ref and shallow arguments', async () => { fs.readLocalFile.mockResolvedValueOnce(flake8Lock); expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ @@ -488,11 +302,119 @@ describe('modules/manager/nix/extract', () => { }); }); + const flake9Lock = `{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes nixpkgs but using indirect type that cannot be updated', async () => { fs.readLocalFile.mockResolvedValueOnce(flake9Lock); expect(await extractPackageFile('', 'flake.nix')).toBeNull(); }); + const flake10Lock = `{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-extra-pkgs": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "host": "github.corp.example.com", + "lastModified": 1728666512, + "narHash": "sha256-p+l16Zzyl2DXG695yks6KQP7NkjsnEksu5GBvtL1QYg=", + "owner": "my-org", + "repo": "nixpkgs-extra-pkgs", + "rev": "6bf2706348447df6f8b86b1c3e54f87b0afda84f", + "type": "github" + }, + "original": { + "host": "github.corp.example.com", + "owner": "my-org", + "repo": "nixpkgs-extra-pkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs-extra-pkgs": "nixpkgs-extra-pkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes flake from GitHub Enterprise', async () => { fs.readLocalFile.mockResolvedValueOnce(flake10Lock); expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ @@ -508,6 +430,94 @@ describe('modules/manager/nix/extract', () => { }); }); + const flake11Lock = `{ + "nodes": { + "data-mesher": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1727355895, + "narHash": "sha256-grZIaLgk5GgoDuTt49RTCLBh458H4YJdIAU4B3onXRw=", + "rev": "c7e39452affcc0f89e023091524e38b3aaf109e9", + "type": "tarball", + "url": "https://git.clan.lol/api/v1/repos/clan/data-mesher/archive/c7e39452affcc0f89e023091524e38b3aaf109e9.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://git.clan.lol/clan/data-mesher/archive/main.tar.gz" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "data-mesher", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1726153070, + "narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1726871744, + "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "data-mesher": "data-mesher" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "data-mesher", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1726734507, + "narHash": "sha256-VUH5O5AcOSxb0uL/m34dDkxFKP6WLQ6y4I1B4+N3L2w=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "ee41a466c2255a3abe6bc50fc6be927cdee57a9f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 + }`; + it('includes flake with tarball type', async () => { fs.readLocalFile.mockResolvedValueOnce(flake11Lock); expect(await extractPackageFile('', 'flake.nix')).toMatchObject({ From 3aa851d31a763c3375084a1c1fca55264c62e697 Mon Sep 17 00:00:00 2001 From: Sandro Date: Thu, 23 Jan 2025 14:22:56 +0100 Subject: [PATCH 48/53] Update lib/modules/manager/nix/extract.ts Co-authored-by: Michael Kriese --- lib/modules/manager/nix/extract.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index e772ddea36bf09..1cc87b927dd997 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -61,8 +61,8 @@ export async function extractPackageFile( // istanbul ignore if: if we are not in a root node then original and locked always exist which cannot be easily expressed in the type if (flakeLocked === undefined || flakeOriginal === undefined) { logger.debug( - { packageLockFile }, - `Found empty flake input '${JSON.stringify(flakeInput)}', skipping`, + { packageLockFile, flakeInput }, + `Found empty flake input, skipping`, ); continue; } From 248998417dbf79228cec9075767a3c570f961ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Thu, 23 Jan 2025 14:35:04 +0100 Subject: [PATCH 49/53] Update comment --- lib/modules/manager/nix/extract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 1cc87b927dd997..d19502085941fd 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -50,7 +50,7 @@ export async function extractPackageFile( continue; } - // skip all locked nodes which cannot be updated + // skip all locked and transitivie nodes as they cannot be updated by regular means if (!(depName in rootInputs)) { continue; } From c80c07404941c5257d724c44ed0db5874827ded1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 25 Jan 2025 22:01:34 +0100 Subject: [PATCH 50/53] Drop unnecessary replaceString --- lib/modules/manager/nix/extract.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index d19502085941fd..7d0db62ba12d8a 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -78,7 +78,6 @@ export async function extractPackageFile( depName, currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: `https://${flakeOriginal.host ?? 'github.com'}/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); @@ -88,7 +87,6 @@ export async function extractPackageFile( depName, currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: `https://${flakeOriginal.host ?? 'gitlab.com'}/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); @@ -98,7 +96,6 @@ export async function extractPackageFile( depName, currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: flakeOriginal.url, }); @@ -108,7 +105,6 @@ export async function extractPackageFile( depName, currentValue: flakeOriginal.ref, currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, packageName: `https://${flakeOriginal.host ?? 'git.sr.ht'}/${flakeOriginal.owner}/${flakeOriginal.repo}`, }); @@ -118,7 +114,6 @@ export async function extractPackageFile( depName, currentValue: flakeLocked.ref, currentDigest: flakeLocked.rev, - replaceString: flakeLocked.rev, datasource: GitRefsDatasource.id, // type tarball always contains this link packageName: flakeOriginal.url!.replace( From 15d35086d50241727ff7dae3ee63d8baf595656b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 25 Jan 2025 22:34:04 +0100 Subject: [PATCH 51/53] Fix test --- lib/modules/manager/nix/extract.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 49f3b90fd78bbb..44aff202c559aa 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -56,7 +56,6 @@ describe('modules/manager/nix/extract', () => { currentValue: 'nixos-unstable', datasource: GitRefsDatasource.id, packageName: 'https://github.com/NixOS/nixpkgs', - replaceString: '9f4128e00b0ae8ec65918efeba59db998750ead6', }, ], }); From 5b12fed1a048640408ac8895da584bce584d7364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 25 Jan 2025 22:34:13 +0100 Subject: [PATCH 52/53] WIP: bring back nixpkgs update --- lib/modules/manager/nix/extract.spec.ts | 88 ++++++++++++++++++++++--- lib/modules/manager/nix/extract.ts | 23 ++++++- 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/lib/modules/manager/nix/extract.spec.ts b/lib/modules/manager/nix/extract.spec.ts index 44aff202c559aa..035a495eb0670f 100644 --- a/lib/modules/manager/nix/extract.spec.ts +++ b/lib/modules/manager/nix/extract.spec.ts @@ -1,18 +1,90 @@ import { fs } from '../../../../test/util'; import { GitRefsDatasource } from '../../datasource/git-refs'; +import { id as nixpkgsVersioning } from '../../versioning/nixpkgs'; import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); -const flake1Lock = `{ - "nodes": { - "root": {} - }, - "root": "root", - "version": 7 -}`; - describe('modules/manager/nix/extract', () => { + const flake1Lock = `{ + "nodes": { + "root": {} + }, + "root": "root", + "version": 7 + }`; + const flake1Nix = `{ + inputs = {}; + }`; + + it('returns null when no nixpkgs input exists', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake1Lock); + expect(await extractPackageFile(flake1Nix, 'flake.nix')).toBeNull(); + }); + + const flake2Nix = `{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; + }; + }`; + + it('match nixpkgs input', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake1Lock); + expect(await extractPackageFile(flake2Nix, 'flake.nix')).toEqual({ + deps: [ + { + depName: 'nixpkgs', + currentValue: 'nixos-21.11', + datasource: GitRefsDatasource.id, + packageName: 'https://github.com/NixOS/nixpkgs', + versioning: nixpkgsVersioning, + }, + ], + }); + }); + + const flake3Nix = `{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; + }; + }`; + + it('match nixpkgs input case insensitive', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake1Lock); + expect(await extractPackageFile(flake3Nix, 'flake.nix')).toEqual({ + deps: [ + { + depName: 'nixpkgs', + currentValue: 'nixos-21.11', + datasource: GitRefsDatasource.id, + packageName: 'https://github.com/NixOS/nixpkgs', + versioning: nixpkgsVersioning, + }, + ], + }); + }); + + const flake4Nix = `{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + }; + }`; + + it('includes nixpkgs input with no explicit ref', async () => { + fs.readLocalFile.mockResolvedValueOnce(flake1Lock); + expect(await extractPackageFile(flake4Nix, 'flake.nix')).toEqual({ + deps: [ + { + currentValue: undefined, + datasource: 'git-refs', + depName: 'nixpkgs', + packageName: 'https://github.com/NixOS/nixpkgs', + versioning: 'nixpkgs', + }, + ], + }); + }); + it('returns null when no inputs', async () => { fs.readLocalFile.mockResolvedValueOnce(flake1Lock); expect(await extractPackageFile('', 'flake.nix')).toBeNull(); diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 7d0db62ba12d8a..18954978869267 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -2,10 +2,11 @@ import { logger } from '../../../logger'; import { getSiblingFileName, readLocalFile } from '../../../util/fs'; import { regEx } from '../../../util/regex'; import { GitRefsDatasource } from '../../datasource/git-refs'; +import { id as nixpkgsVersioning } from '../../versioning/nixpkgs'; import type { PackageDependency, PackageFileContent } from '../types'; import { NixFlakeLock } from './schema'; -// TODO: add support to update nixpkgs branches in flakes.nix using nixpkgsVersioning +const nixpkgsRegex = regEx(/"github:nixos\/nixpkgs(\/(?[a-z0-9-.]+))?"/i); // as documented upstream // https://github.com/NixOS/nix/blob/master/doc/manual/source/protocols/tarball-fetcher.md#gitea-and-forgejo-support @@ -24,12 +25,28 @@ export async function extractPackageFile( const deps: PackageDependency[] = []; + const match = nixpkgsRegex.exec(content); + if (match?.groups) { + const { ref } = match.groups; + deps.push({ + depName: 'nixpkgs', + currentValue: ref, + datasource: GitRefsDatasource.id, + packageName: 'https://github.com/NixOS/nixpkgs', + versioning: nixpkgsVersioning, + }); + } + const flakeLockParsed = NixFlakeLock.safeParse(lockContents); if (!flakeLockParsed.success) { logger.debug( { packageLockFile, error: flakeLockParsed.error }, `invalid flake.lock file`, ); + + if (deps.length) { + return { deps }; + } return null; } @@ -41,6 +58,10 @@ export async function extractPackageFile( { packageLockFile, error: flakeLockParsed.error }, `flake.lock is missing "root" node`, ); + + if (deps.length) { + return { deps }; + } return null; } From c0ca239ab8d401bf670a0180468f705f29b6ea81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sun, 26 Jan 2025 18:52:28 +0100 Subject: [PATCH 53/53] Fix coverage --- lib/modules/manager/nix/extract.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/modules/manager/nix/extract.ts b/lib/modules/manager/nix/extract.ts index 18954978869267..cfe99ead002906 100644 --- a/lib/modules/manager/nix/extract.ts +++ b/lib/modules/manager/nix/extract.ts @@ -43,10 +43,6 @@ export async function extractPackageFile( { packageLockFile, error: flakeLockParsed.error }, `invalid flake.lock file`, ); - - if (deps.length) { - return { deps }; - } return null; }