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 bfff982 commit 6e39464
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
31 changes: 15 additions & 16 deletions lib/modules/manager/nix/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('modules/manager/nix/extract', () => {

it('returns null when no nixpkgs input exists', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake1Lock);
expect(await extractPackageFile(flake1Nix, 'flake.nix')).toBeNull();
expect(await extractPackageFile(flake1Nix, 'flake.lock')).toBeNull();
});

const flake2Nix = `{
Expand All @@ -30,7 +30,7 @@ describe('modules/manager/nix/extract', () => {

it('match nixpkgs input', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake1Lock);
expect(await extractPackageFile(flake2Nix, 'flake.nix')).toEqual({
expect(await extractPackageFile(flake2Nix, 'flake.lock')).toEqual({
deps: [
{
depName: 'nixpkgs',
Expand All @@ -51,7 +51,7 @@ describe('modules/manager/nix/extract', () => {

it('match nixpkgs input case insensitive', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake1Lock);
expect(await extractPackageFile(flake3Nix, 'flake.nix')).toEqual({
expect(await extractPackageFile(flake3Nix, 'flake.lock')).toEqual({
deps: [
{
depName: 'nixpkgs',
Expand All @@ -72,7 +72,7 @@ describe('modules/manager/nix/extract', () => {

it('includes nixpkgs input with no explicit ref', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake1Lock);
expect(await extractPackageFile(flake4Nix, 'flake.nix')).toEqual({
expect(await extractPackageFile(flake4Nix, 'flake.lock')).toEqual({
deps: [
{
currentValue: undefined,
Expand All @@ -87,7 +87,7 @@ describe('modules/manager/nix/extract', () => {

it('returns null when no inputs', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake1Lock);
expect(await extractPackageFile('', 'flake.nix')).toBeNull();
expect(await extractPackageFile('', 'flake.lock')).toBeNull();
});

const flake2Lock = `{
Expand Down Expand Up @@ -120,12 +120,11 @@ describe('modules/manager/nix/extract', () => {

it('returns nixpkgs input', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake2Lock);
expect(await extractPackageFile('', 'flake.nix')).toEqual({
expect(await extractPackageFile('', 'flake.lock')).toEqual({
deps: [
{
depName: 'nixpkgs',
currentDigest: '9f4128e00b0ae8ec65918efeba59db998750ead6',
currentValue: 'nixos-unstable',
datasource: GitRefsDatasource.id,
packageName: 'https://github.com/NixOS/nixpkgs',
},
Expand Down Expand Up @@ -162,7 +161,7 @@ describe('modules/manager/nix/extract', () => {

it('includes nixpkgs with no explicit ref', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake3Lock);
expect(await extractPackageFile('', 'flake.nix')).toMatchObject({
expect(await extractPackageFile('', 'flake.lock')).toMatchObject({
deps: [
{
currentDigest: '612ee628421ba2c1abca4c99684862f76cb3b089',
Expand Down Expand Up @@ -221,7 +220,7 @@ describe('modules/manager/nix/extract', () => {

it('includes patchelf from HEAD', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake4Lock);
expect(await extractPackageFile('', 'flake.nix')).toMatchObject({
expect(await extractPackageFile('', 'flake.lock')).toMatchObject({
deps: [
{
currentDigest: 'a0f54334df36770b335c051e540ba40afcbf8378',
Expand Down Expand Up @@ -263,7 +262,7 @@ describe('modules/manager/nix/extract', () => {

it('includes ijq from sourcehut without a flake', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake5Lock);
expect(await extractPackageFile('', 'flake.nix')).toMatchObject({
expect(await extractPackageFile('', 'flake.lock')).toMatchObject({
deps: [
{
currentDigest: '88f0d9ae98942bf49cba302c42b2a0f6e05f9b58',
Expand Down Expand Up @@ -305,7 +304,7 @@ describe('modules/manager/nix/extract', () => {

it('includes home-manager from gitlab', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake6Lock);
expect(await extractPackageFile('', 'flake.nix')).toMatchObject({
expect(await extractPackageFile('', 'flake.lock')).toMatchObject({
deps: [
{
currentDigest: '65ae9c147349829d3df0222151f53f79821c5134',
Expand All @@ -327,7 +326,7 @@ describe('modules/manager/nix/extract', () => {

it('test other version', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake7Lock);
expect(await extractPackageFile('', 'flake.nix')).toBeNull();
expect(await extractPackageFile('', 'flake.lock')).toBeNull();
});

const flake8Lock = `{
Expand Down Expand Up @@ -361,7 +360,7 @@ describe('modules/manager/nix/extract', () => {

it('includes nixpkgs with ref and shallow arguments', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake8Lock);
expect(await extractPackageFile('', 'flake.nix')).toMatchObject({
expect(await extractPackageFile('', 'flake.lock')).toMatchObject({
deps: [
{
currentDigest: '5633bcff0c6162b9e4b5f1264264611e950c8ec7',
Expand Down Expand Up @@ -401,7 +400,7 @@ describe('modules/manager/nix/extract', () => {

it('includes nixpkgs but using indirect type that cannot be updated', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake9Lock);
expect(await extractPackageFile('', 'flake.nix')).toBeNull();
expect(await extractPackageFile('', 'flake.lock')).toBeNull();
});

const flake10Lock = `{
Expand Down Expand Up @@ -488,7 +487,7 @@ describe('modules/manager/nix/extract', () => {

it('includes flake from GitHub Enterprise', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake10Lock);
expect(await extractPackageFile('', 'flake.nix')).toMatchObject({
expect(await extractPackageFile('', 'flake.lock')).toMatchObject({
deps: [
{
currentDigest: '6bf2706348447df6f8b86b1c3e54f87b0afda84f',
Expand Down Expand Up @@ -591,7 +590,7 @@ describe('modules/manager/nix/extract', () => {

it('includes flake with tarball type', async () => {
fs.readLocalFile.mockResolvedValueOnce(flake11Lock);
expect(await extractPackageFile('', 'flake.nix')).toMatchObject({
expect(await extractPackageFile('', 'flake.lock')).toMatchObject({
deps: [
{
currentDigest: 'c7e39452affcc0f89e023091524e38b3aaf109e9',
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 };

Check warning on line 42 in lib/modules/manager/nix/extract.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/manager/nix/extract.ts#L42

Added line #L42 was not covered by tests
}
return null;

Check warning on line 44 in lib/modules/manager/nix/extract.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/manager/nix/extract.ts#L44

Added line #L44 was not covered by tests
}

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 6e39464

Please sign in to comment.