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