diff --git a/apps/update-sources/src/app.ts b/apps/update-sources/src/app.ts index 4140dc4a..83d99af0 100644 --- a/apps/update-sources/src/app.ts +++ b/apps/update-sources/src/app.ts @@ -92,7 +92,19 @@ const main = async() => { 'scopedPackages.x86_64-linux.lovelace-components.custom-sidebar', )); console.log(updateCustomPackage('some-sass-language-server')); - console.log(runNixUpdate('homepage')); + + // nix-update executions + let nixUpdateOutputs = ''; + + const updatePackage = (pkg: string): void => { + const execution = runNixUpdate(pkg); + + nixUpdateOutputs += execution.stdout; + console.log(execution.stderr); + console.log(execution.stdout); + }; + + updatePackage('homepage'); spawnSync('nixFastBuild', [], { @@ -121,7 +133,10 @@ const main = async() => { output.push(`Node modules:\n${indentOutput(nodeModulesOutput)}\n`); } if (vuetorrentOutput.length > 5) { - output.push(`Misc Sources:\n${indentOutput(vuetorrentOutput)}\n`); + output.push(`Misc Sources:\n${indentOutput(vuetorrentOutput)}\n\n`); + } + if (nixUpdateOutputs.length > 5) { + output.push(`nix-update executions:\n${indentOutput(nixUpdateOutputs)}\n`); } if (args['f']) { diff --git a/apps/update-sources/src/misc.ts b/apps/update-sources/src/misc.ts index 7197c3aa..2ea33ce1 100644 --- a/apps/update-sources/src/misc.ts +++ b/apps/update-sources/src/misc.ts @@ -40,14 +40,34 @@ export const updateVuetorrent = () => { return OLD_VERSION !== VERSION ? `Vuetorrent: ${OLD_VERSION} -> ${VERSION}` : ''; }; + export const updateCustomPackage = (pkg: string) => spawnSync( `nix run ${FLAKE}#${pkg}.update`, [], { shell: true }, ).stderr.toString(); -export const runNixUpdate = (attr: string, options: string[] = []) => spawnSync( - 'nix-update', - ['--flake', attr, ...options], - { shell: true, cwd: FLAKE }, -).stderr.toString(); + +const getAttrVersion = (attr: string): string => spawnSync('nix', + ['eval', '--raw', `${FLAKE}#${attr}.version`], + { shell: true }).stdout.toString(); + +export const runNixUpdate = ( + attr: string, + options: string[] = [], +): { stdout: string, stderr: string } => { + const OLD_VERSION = getAttrVersion(attr); + + const execution = spawnSync( + `nix-update --flake ${attr} --write-commit-message >(head -n 1 -) > /dev/null`, + options, + { shell: true, cwd: FLAKE }, + ); + + const NEW_VERSION = getAttrVersion(attr); + + return { + stdout: OLD_VERSION !== NEW_VERSION ? execution.stdout.toString() : '', + stderr: execution.stderr.toString(), + }; +};