Skip to content

Commit

Permalink
feat(nix): rework to work with all flake inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Oct 11, 2024
1 parent 748b258 commit 752feae
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 78 deletions.
7 changes: 7 additions & 0 deletions lib/modules/manager/nix/__fixtures__/flake.1.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"nodes": {
"root": {}
},
"root": "root",
"version": 7
}
27 changes: 27 additions & 0 deletions lib/modules/manager/nix/__fixtures__/flake.2.lock
Original file line number Diff line number Diff line change
@@ -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
}
26 changes: 26 additions & 0 deletions lib/modules/manager/nix/__fixtures__/flake.3.lock
Original file line number Diff line number Diff line change
@@ -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
}
44 changes: 44 additions & 0 deletions lib/modules/manager/nix/__fixtures__/flake.4.lock
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 27 additions & 0 deletions lib/modules/manager/nix/__fixtures__/flake.5.lock
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 27 additions & 0 deletions lib/modules/manager/nix/__fixtures__/flake.6.lock
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 13 additions & 16 deletions lib/modules/manager/nix/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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' } },
Expand Down Expand Up @@ -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' } },
Expand Down Expand Up @@ -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' } },
Expand Down Expand Up @@ -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' } },
Expand Down Expand Up @@ -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' } },
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/manager/nix/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading

0 comments on commit 752feae

Please sign in to comment.