packages: cleanup

This commit is contained in:
Sandro - 2023-10-16 01:46:36 +02:00
parent 938e9bc222
commit 3ebcbacfc5
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5
1 changed files with 28 additions and 27 deletions

View File

@ -22,25 +22,23 @@ lib.attrsets.mapAttrs
in
overlayPkgs //
{
host-registry = pkgs.runCommand "host-registry"
{
src = builtins.toFile "host-registry.nix" (
lib.generators.toPretty { } hostRegistry
);
}
''
ln -s $src $out
'';
host-registry = pkgs.runCommand "host-registry" {
src = builtins.toFile "host-registry.nix" (
lib.generators.toPretty { } hostRegistry
);
} ''
ln -s $src $out
'';
list-upgradable = pkgs.writeScriptBin "list-upgradable" ''
#! ${pkgs.runtimeShell}
set -eou pipefail
NORMAL="\033[0m"
RED="\033[0;31m"
YELLOW="\033[0;33m"
GREEN="\033[0;32m"
${pkgs.lib.concatMapStringsSep "\n" (name:
${lib.concatMapStringsSep "\n" (name:
let
addr = getHostAddr name;
in lib.optionalString (addr != null) ''
@ -69,25 +67,23 @@ lib.attrsets.mapAttrs
'') (builtins.attrNames self.nixosConfigurations)}
'';
prebuild-all = pkgs.runCommand "prebuild-all"
{
preferLocalBuild = true;
}
''
mkdir $out
prebuild-all = pkgs.runCommand "prebuild-all" {
preferLocalBuild = true;
} ''
mkdir $out
${pkgs.lib.concatMapStrings (name: ''
ln -s ${self.nixosConfigurations."${name}".config.system.build.toplevel} name
'') (builtins.attrNames self.nixosConfigurations)}
'';
${pkgs.lib.concatMapStrings (name: ''
ln -s ${self.nixosConfigurations."${name}".config.system.build.toplevel} name
'') (builtins.attrNames self.nixosConfigurations)}
'';
prebuild-all-remote = pkgs.writeScriptBin "prebuild-all" ''
#!${pkgs.runtimeShell} -e
set -eou pipefail
nix copy --no-check-sigs --to ssh-ng://$1 ${inputPaths}
ssh $1 -- nix build -L --no-link ${
pkgs.lib.concatMapStringsSep " " (name:
lib.concatMapStringsSep " " (name:
"${self}#nixosConfigurations.${name}.config.system.build.toplevel"
) (builtins.attrNames self.nixosConfigurations)
}
@ -110,7 +106,7 @@ lib.attrsets.mapAttrs
# remote machine and bulding and switching there.
# Can be run with `nix run c3d2#…-nixos-rebuild switch`
"${name}-nixos-rebuild" = pkgs.writeScriptBin "${name}-nixos-rebuild" ''
#!${pkgs.runtimeShell} -e
set -eou pipefail
if nix eval .#nixosConfigurations.${name}.config.c3d2.deployment.server &>/dev/null; then
echo "microvms cannot be updated with nixos-rebuild. Use nix run .#microvm-update-${name}"
@ -126,9 +122,11 @@ lib.attrsets.mapAttrs
'';
"${name}-nixos-rebuild-hydra" = pkgs.writeScriptBin "${name}-nixos-rebuild" ''
#!${pkgs.runtimeShell} -e
set -eou pipefail
echo Copying Flakes
nix copy --no-check-sigs --to ssh-ng://root@hydra.serv.zentralwerk.org ${inputPaths}
echo Building on Hydra
ssh root@hydra.serv.zentralwerk.org -- \
nix build -L -o /tmp/nixos-system-${name} \
@ -136,12 +134,14 @@ lib.attrsets.mapAttrs
echo Built. Obtaining link to data
TOPLEVEL=$(ssh root@hydra.serv.zentralwerk.org \
readlink /tmp/nixos-system-${name})
echo Checking target ${name}
ssh ${target} -- bash -e <<EOF
[[ \$(cat /etc/hostname) == ${name} ]]
echo Copying data from Hydra to ${name}
nix copy --from https://nix-cache.hq.c3d2.de \
$TOPLEVEL
echo Activation on ${name}: "$@"
nix-env -p /nix/var/nix/profiles/system --set $TOPLEVEL
$TOPLEVEL/bin/switch-to-configuration "$@"
@ -149,14 +149,15 @@ lib.attrsets.mapAttrs
'';
"${name}-nixos-rebuild-local" = pkgs.writeScriptBin "${name}-nixos-rebuild" ''
#!${pkgs.runtimeShell} -ex
set -eou pipefail
[[ $1 == build || $(ssh ${target} cat /etc/hostname) == ${name} ]]
# don't re-execute, otherwise we run the targetPlatform locally
_NIXOS_REBUILD_REEXEC=1 ${pkgs.nixos-rebuild}/bin/nixos-rebuild ${rebuildArg} --target-host ${target} --use-remote-sudo "$@"
'';
"${name}-cleanup" = pkgs.writeScriptBin "${name}-cleanup" ''
#!${pkgs.runtimeShell} -ex
set -eou pipefail
ssh ${target} "time nix-collect-garbage -d && time nix-store --optimise"
'';