2024-07-20 22:33:14 -04:00
|
|
|
import { readdirSync, writeFileSync } from 'node:fs';
|
2024-07-20 22:02:22 -04:00
|
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
|
2024-07-20 22:33:14 -04:00
|
|
|
import { parseFetchurl } from './lib.ts';
|
|
|
|
|
2024-07-20 22:02:22 -04:00
|
|
|
|
|
|
|
/* Constants */
|
|
|
|
const FLAKE = process.env.FLAKE;
|
|
|
|
|
2024-07-20 23:40:06 -04:00
|
|
|
export const updateFlakeInputs = () => {
|
|
|
|
const output = spawnSync(
|
2024-07-30 22:21:08 -04:00
|
|
|
`git restore flake.lock &> /dev/null; nix flake update --flake ${FLAKE}` +
|
2024-10-20 21:42:54 -04:00
|
|
|
' |& grep -v "warning: updating lock file" |& grep -v "unpacking"',
|
2024-07-20 23:40:06 -04:00
|
|
|
[],
|
|
|
|
{ shell: true },
|
|
|
|
).stdout
|
|
|
|
.toString()
|
2024-07-21 01:17:10 -04:00
|
|
|
// Add an extra blank line between inputs
|
2024-07-20 23:40:06 -04:00
|
|
|
.split('\n•')
|
2024-10-30 02:27:07 -04:00
|
|
|
.filter((input) => ![
|
|
|
|
'systems',
|
|
|
|
'flake-utils',
|
|
|
|
'flake-parts',
|
|
|
|
'treefmt-nix',
|
|
|
|
'lib-aggregate',
|
2024-11-04 16:00:32 -05:00
|
|
|
'lib-aggregate/nixpkgs-lib',
|
|
|
|
'sops-nix/nixpkgs-stable',
|
2024-10-30 19:51:39 -04:00
|
|
|
].some((inputName) => input.startsWith(` Updated input '${inputName}'`)))
|
|
|
|
.join('\n\n•')
|
|
|
|
// Shorten git revs to help readability
|
|
|
|
.split('\n')
|
|
|
|
.map((l) => l
|
|
|
|
.replace(/.{33}\?narHash=sha256[^']*/, '')
|
|
|
|
.replace(/&rev=(.{7})[^'&]*/, (_, backref) => `&rev=${backref}`))
|
2024-07-20 23:40:06 -04:00
|
|
|
.join('\n');
|
|
|
|
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
2024-07-20 22:02:22 -04:00
|
|
|
export const updateDocker = () => {
|
2024-11-04 16:00:32 -05:00
|
|
|
const updateImages = (imagePath: string): string | undefined => {
|
|
|
|
console.log(`Updating ${imagePath.split('/').at(-1)} images`);
|
|
|
|
|
|
|
|
const out = spawnSync('updateImages', [imagePath], { shell: true }).stdout.toString();
|
2024-07-20 22:02:22 -04:00
|
|
|
|
2024-11-06 21:46:40 -05:00
|
|
|
if (!out.startsWith('# Locked')) {
|
2024-11-04 16:00:32 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let updates = '';
|
2024-10-05 22:22:02 -04:00
|
|
|
|
2024-11-04 16:00:32 -05:00
|
|
|
updates += updateImages(`${FLAKE}/devices/nos/modules/jellyfin`) ?? '';
|
|
|
|
updates += updateImages(`${FLAKE}/devices/homie/modules/home-assistant/netdaemon`) ?? '';
|
2024-10-05 22:22:02 -04:00
|
|
|
|
2024-11-04 16:00:32 -05:00
|
|
|
const DIR = `${FLAKE}/devices/nos/modules/docker`;
|
2024-07-20 22:02:22 -04:00
|
|
|
|
2024-11-04 16:00:32 -05:00
|
|
|
readdirSync(DIR, { withFileTypes: true, recursive: true }).forEach((path) => {
|
2024-07-20 22:02:22 -04:00
|
|
|
if (path.name === 'compose.nix') {
|
2024-11-04 16:00:32 -05:00
|
|
|
updates += updateImages(path.parentPath) ?? '';
|
2024-07-20 22:02:22 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return updates;
|
|
|
|
};
|
2024-07-20 22:33:14 -04:00
|
|
|
|
2024-10-20 21:42:54 -04:00
|
|
|
const genVueText = (
|
|
|
|
version: string,
|
|
|
|
hash: string,
|
|
|
|
url: string,
|
|
|
|
) => `# This file was autogenerated. DO NOT EDIT!
|
2024-07-20 22:33:14 -04:00
|
|
|
{
|
|
|
|
version = "${version}";
|
|
|
|
url = "${url}";
|
|
|
|
hash = "${hash}";
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const updateVuetorrent = () => {
|
|
|
|
const FILE = `${FLAKE}/devices/nos/modules/qbittorrent/vuetorrent.nix`;
|
|
|
|
|
|
|
|
const OLD_VERSION = JSON.parse(spawnSync('nix',
|
|
|
|
['eval', '-f', FILE, '--json'],
|
|
|
|
{ shell: true }).stdout.toString()).version;
|
|
|
|
|
|
|
|
const VERSION = JSON.parse(spawnSync('curl',
|
|
|
|
['-s', 'https://api.github.com/repos/VueTorrent/VueTorrent/releases/latest'],
|
|
|
|
{ shell: true }).stdout.toString()).tag_name.replace('v', '');
|
|
|
|
|
|
|
|
const URL = `https://github.com/VueTorrent/VueTorrent/releases/download/v${VERSION}/vuetorrent.zip`;
|
|
|
|
const HASH = parseFetchurl(URL);
|
|
|
|
|
|
|
|
const fileText = genVueText(VERSION, HASH, URL);
|
|
|
|
|
|
|
|
writeFileSync(FILE, fileText);
|
|
|
|
|
2024-07-22 20:16:03 -04:00
|
|
|
return OLD_VERSION !== VERSION ? `Vuetorrent: ${OLD_VERSION} -> ${VERSION}` : '';
|
2024-07-20 22:33:14 -04:00
|
|
|
};
|
2024-10-20 21:42:54 -04:00
|
|
|
|
2024-10-31 15:35:03 -04:00
|
|
|
export const updateCustomPackage = (pkg: string) => spawnSync(
|
|
|
|
`nix run ${FLAKE}#${pkg}.update`,
|
2024-10-20 21:42:54 -04:00
|
|
|
[],
|
|
|
|
{ shell: true },
|
|
|
|
).stderr.toString();
|