Skip to content

Commit

Permalink
fix(nix): fix flake lock refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Feb 2, 2025
1 parent 52ab2d8 commit 5021fa2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions lib/modules/manager/nix/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import { logger } from '../../../logger';
import { findGithubToken } from '../../../util/check-token';
import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import { readLocalFile } from '../../../util/fs';
import { getSiblingFileName, readLocalFile } from '../../../util/fs';
import { getRepoStatus } from '../../../util/git';
import * as hostRules from '../../../util/host-rules';
import { regEx } from '../../../util/regex';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';

export async function updateArtifacts({
packageFileName,
config,
updatedDeps,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
const lockFileName = packageFileName.replace(regEx(/\.nix$/), '.lock');
const lockFileName = getSiblingFileName(packageFileName, 'flake.lock');
const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');
if (!existingLockFileContent) {
logger.debug('No flake.lock found');
Expand Down
12 changes: 7 additions & 5 deletions lib/modules/manager/nix/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export async function extractPackageFile(
});
}

if (!packageFile.match(regEx(/\.lock$/))) {
if (deps.length) {
return { deps };
}
return null;
}

const flakeLockParsed = NixFlakeLock.safeParse(lockContents);
if (!flakeLockParsed.success) {
logger.debug(
Expand Down Expand Up @@ -93,7 +100,6 @@ export async function extractPackageFile(
case 'github':
deps.push({
depName,
currentValue: flakeOriginal.ref,
currentDigest: flakeLocked.rev,
datasource: GitRefsDatasource.id,
packageName: `https://${flakeOriginal.host ?? 'github.com'}/${flakeOriginal.owner}/${flakeOriginal.repo}`,
Expand All @@ -102,7 +108,6 @@ export async function extractPackageFile(
case 'gitlab':
deps.push({
depName,
currentValue: flakeOriginal.ref,
currentDigest: flakeLocked.rev,
datasource: GitRefsDatasource.id,
packageName: `https://${flakeOriginal.host ?? 'gitlab.com'}/${flakeOriginal.owner}/${flakeOriginal.repo}`,
Expand All @@ -111,7 +116,6 @@ export async function extractPackageFile(
case 'git':
deps.push({
depName,
currentValue: flakeOriginal.ref,
currentDigest: flakeLocked.rev,
datasource: GitRefsDatasource.id,
packageName: flakeOriginal.url,
Expand All @@ -120,7 +124,6 @@ export async function extractPackageFile(
case 'sourcehut':
deps.push({
depName,
currentValue: flakeOriginal.ref,
currentDigest: flakeLocked.rev,
datasource: GitRefsDatasource.id,
packageName: `https://${flakeOriginal.host ?? 'git.sr.ht'}/${flakeOriginal.owner}/${flakeOriginal.repo}`,
Expand All @@ -129,7 +132,6 @@ export async function extractPackageFile(
case 'tarball':
deps.push({
depName,
currentValue: flakeLocked.ref,
currentDigest: flakeLocked.rev,
datasource: GitRefsDatasource.id,
// type tarball always contains this link
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/nix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const supportsLockFileMaintenance = true;
export const url = 'https://nix.dev';

export const defaultConfig = {
fileMatch: ['(^|/)flake\\.nix$'],
fileMatch: ['(^|/)flake\\.(nix|lock)$'],
commitMessageTopic: 'nix',
commitMessageExtra: 'to {{newValue}}',
enabled: false,
Expand Down

0 comments on commit 5021fa2

Please sign in to comment.