parent
83fe089c5e
commit
98833bdc6f
14 changed files with 367 additions and 46 deletions
apps/update-sources
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
buildApp,
|
||||
callPackage,
|
||||
go,
|
||||
nix-update,
|
||||
nodejs_latest,
|
||||
prefetch-npm-deps,
|
||||
|
@ -11,6 +12,7 @@ buildApp {
|
|||
npmDepsHash = "sha256-TU7HoUGeCXUKwm2s4Np6NQahk6gWBN9WC5vob3zw7Ns=";
|
||||
|
||||
runtimeInputs = [
|
||||
go
|
||||
nix-update
|
||||
nodejs_latest
|
||||
prefetch-npm-deps
|
||||
|
|
|
@ -10,6 +10,7 @@ import updateNodeModules from './node-modules';
|
|||
|
||||
import {
|
||||
runNixUpdate,
|
||||
updateCaddyPlugins,
|
||||
updateCustomPackage,
|
||||
updateVuetorrent,
|
||||
} from './misc';
|
||||
|
@ -66,6 +67,10 @@ const main = async() => {
|
|||
console.log(runNixUpdate('homepage'));
|
||||
}
|
||||
|
||||
if (args['cp'] || args['caddy-plugins']) {
|
||||
console.log(updateCaddyPlugins());
|
||||
}
|
||||
|
||||
if (args['a'] || args['all']) {
|
||||
// Update this first because of nix run cmd
|
||||
const firefoxOutput = updateFirefoxAddons();
|
||||
|
@ -93,6 +98,11 @@ const main = async() => {
|
|||
console.log(vuetorrentOutput);
|
||||
|
||||
|
||||
const caddyPluginsOutput = updateCaddyPlugins();
|
||||
|
||||
console.log(caddyPluginsOutput);
|
||||
|
||||
|
||||
// This doesn't need to be added to commit msgs
|
||||
console.log(updateCustomPackage(
|
||||
'scopedPackages.x86_64-linux.lovelace-components.custom-sidebar',
|
||||
|
@ -144,6 +154,9 @@ const main = async() => {
|
|||
if (vuetorrentOutput.length > 5) {
|
||||
output.push(`Misc Sources:\n${indentOutput(vuetorrentOutput)}\n\n`);
|
||||
}
|
||||
if (caddyPluginsOutput.length > 5) {
|
||||
output.push(`Caddy Plugins:\n${indentOutput(caddyPluginsOutput)}\n\n`);
|
||||
}
|
||||
if (nixUpdateOutputs.length > 5) {
|
||||
output.push(`nix-update executions:\n${indentOutput(nixUpdateOutputs)}\n`);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { writeFileSync } from 'node:fs';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
import { parseFetchurl } from './lib';
|
||||
import { parseFetchurl, replaceInFile } from './lib';
|
||||
|
||||
|
||||
/* Constants */
|
||||
|
@ -71,3 +71,78 @@ export const runNixUpdate = (
|
|||
stderr: execution.stderr.toString(),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const genPluginsText = (
|
||||
plugins: Record<string, { url: string, version: string }>,
|
||||
) => `# This file was autogenerated. DO NOT EDIT!
|
||||
{
|
||||
plugins = {
|
||||
${Object.entries(plugins)
|
||||
.map(([key, value]) => `
|
||||
${key} = {
|
||||
url = "${value.url}";
|
||||
version = "${value.version}";
|
||||
};
|
||||
`)
|
||||
.join('')}
|
||||
};
|
||||
|
||||
hash = "";
|
||||
}
|
||||
`;
|
||||
|
||||
export const updateCaddyPlugins = () => {
|
||||
let updates = '';
|
||||
const dir = `${FLAKE}/configurations/cluster/modules/caddy`;
|
||||
|
||||
// Setup workspace
|
||||
spawnSync(
|
||||
[
|
||||
'rm -rf /tmp/update-caddy',
|
||||
'mkdir -p /tmp/update-caddy',
|
||||
'cd /tmp/update-caddy || exit 1',
|
||||
'go mod init temp',
|
||||
].join('; '),
|
||||
[],
|
||||
{ shell: true, cwd: '/tmp' },
|
||||
);
|
||||
|
||||
const plugins = JSON.parse(spawnSync('nix',
|
||||
['eval', '-f', `${dir}/plugins.nix`, '--json'],
|
||||
{ shell: true }).stdout.toString()).plugins as Record<string, { url: string, version: string }>;
|
||||
|
||||
// Get most recent versions of plugins
|
||||
Object.entries(plugins).forEach(([key, value]) => {
|
||||
const NEW_VERSION = spawnSync([
|
||||
'go mod init temp > /dev/null',
|
||||
`go get ${value.url} > /dev/null`,
|
||||
`grep '${value.url}' go.mod`,
|
||||
].join('; '), [], { shell: true, cwd: '/tmp/update-caddy' })
|
||||
.stdout
|
||||
.toString()
|
||||
.trim()
|
||||
.replace(' // indirect', '')
|
||||
.split(' ')[1];
|
||||
|
||||
if (plugins[key].version !== NEW_VERSION) {
|
||||
updates += `${key}: ${plugins[key].version} -> ${NEW_VERSION}`;
|
||||
plugins[key].version = NEW_VERSION;
|
||||
}
|
||||
});
|
||||
|
||||
writeFileSync(`${dir}/plugins.nix`, genPluginsText(plugins));
|
||||
|
||||
// Get new hash
|
||||
const caddyPkgAttr = 'nixosConfigurations.thingone.config.services.caddy.package';
|
||||
|
||||
const NEW_HASH = spawnSync(
|
||||
`nix build "$FLAKE#${caddyPkgAttr}" |& sed -n 's/.*got: *//p'`,
|
||||
[],
|
||||
{ shell: true },
|
||||
).stdout.toString().trim();
|
||||
|
||||
replaceInFile(/hash = ".*";/, `hash = "${NEW_HASH}";`, `${dir}/plugins.nix`);
|
||||
|
||||
return updates;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue