From 1de66b37952c1ff91f1567c6b15ac2726f2a00fb Mon Sep 17 00:00:00 2001 From: emily Date: Tue, 14 May 2024 15:27:57 +0200 Subject: [PATCH] fixed deployment weird thing happen when you try to copy things from a binary cache to a local store --- config/common/default.nix | 2 +- config/profiles/builder.nix | 1 + config/profiles/lxc.nix | 8 +++----- config/services/hydra/default.nix | 1 + lib/shinyflakes/default.nix | 2 +- modules/deployment/default.nix | 19 +++++++++++++------ pkgs/upgrade-system/upgrade-system.sh | 8 +++++++- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/config/common/default.nix b/config/common/default.nix index f4a2ce5..69549f1 100644 --- a/config/common/default.nix +++ b/config/common/default.nix @@ -30,7 +30,7 @@ with lib; { kyouma.deployment = { tags = [ "all" ]; - upgradeSystem.enable = true; + auto-upgrade.enable = true; }; security.dhparams.defaultBitSize = 4096; diff --git a/config/profiles/builder.nix b/config/profiles/builder.nix index 6e4a7cd..553dbb0 100644 --- a/config/profiles/builder.nix +++ b/config/profiles/builder.nix @@ -1,4 +1,5 @@ { lib, pkgs, ... }: { + kyouma.deployment.auto-upgrade.cache = "daemon"; nix.gc.options = lib.mkForce "--delete-older-than 60d"; nix.settings.trusted-users = [ "build" ]; nix.extraOptions = '' diff --git a/config/profiles/lxc.nix b/config/profiles/lxc.nix index 1cf49e3..aadeafa 100644 --- a/config/profiles/lxc.nix +++ b/config/profiles/lxc.nix @@ -1,6 +1,4 @@ -{ config, pkgs, lib, modulesPath, ... }: - -with lib; { +{ lib, modulesPath, ... }: { imports = [ (modulesPath + "/virtualisation/proxmox-lxc.nix") ]; @@ -8,11 +6,11 @@ with lib; { manageNetwork = true; manageHostName = true; }; - kyouma ={ + kyouma = { machine-type.virtual = true; deployment = { tags = [ "pve-lxc" ]; - upgradeSystem.allowReboot = false; + auto-upgrade.allowReboot = false; }; }; diff --git a/config/services/hydra/default.nix b/config/services/hydra/default.nix index c89858a..fa982ad 100644 --- a/config/services/hydra/default.nix +++ b/config/services/hydra/default.nix @@ -10,6 +10,7 @@ owner = "hydra-queue-runner"; sopsFile = ../../../secrets/services/hydra.yaml; }; + kyouma.deployment.auto-upgrade.cache = "daemon"; services.hydra = { enable = true; diff --git a/lib/shinyflakes/default.nix b/lib/shinyflakes/default.nix index dc3c20b..12b1a19 100644 --- a/lib/shinyflakes/default.nix +++ b/lib/shinyflakes/default.nix @@ -33,7 +33,7 @@ ({ ... }: { nixpkgs.overlays = [ self.overlays.kyouma self.overlays.otherPkgs ]; nixpkgs.hostPlatform.system = system; - kyouma.deployment.upgradeSystem.hostName = hostname; + kyouma.deployment.auto-upgrade.hostName = hostname; }) ]; }; diff --git a/modules/deployment/default.nix b/modules/deployment/default.nix index 5a29830..2c94321 100644 --- a/modules/deployment/default.nix +++ b/modules/deployment/default.nix @@ -1,6 +1,6 @@ { config, lib, pkgs, ... }: with lib; -let cfg = config.kyouma.deployment.upgradeSystem; +let cfg = config.kyouma.deployment.auto-upgrade; in { options.kyouma.deployment = { tags = mkOption { @@ -13,8 +13,8 @@ in { default = null; description = "colmena target host override"; }; - upgradeSystem = { - enable = mkEnableOption "automatically apply hydra builds"; + auto-upgrade = { + enable = mkEnableOption "automatically upgrade from hydra"; allowReboot = mkOption { type = types.bool; default = true; @@ -25,6 +25,11 @@ in { default = "main"; description = "branch to use for updates"; }; + cache = mkOption { + type = types.str; + default = "https://cache.kyouma.net"; + description = "Set the binary cache"; + }; hostName = mkOption { type = with types; nullOr str; default = null; @@ -51,9 +56,11 @@ in { serviceConfig = { Type = "oneshot"; - ExecStart = "${pkgs.upgrade-system}/bin/upgrade-system${optionalString cfg.allowReboot " --allow-reboot"} --branch ${cfg.branch}${ - optionalString (cfg.hostName != null) " --hostname ${cfg.hostName}" - }${optionalString cfg.noDelay " --no-delay"}"; + ExecStart = "${pkgs.upgrade-system}/bin/upgrade-system${ + optionalString cfg.allowReboot " --allow-reboot" + } --branch ${cfg.branch} --cache ${cfg.cache}${optionalString (cfg.hostName != null) " --hostname ${cfg.hostName}"}${ + optionalString cfg.noDelay " --no-delay" + }"; }; }; systemd.timers.upgrade-system = { diff --git a/pkgs/upgrade-system/upgrade-system.sh b/pkgs/upgrade-system/upgrade-system.sh index 01338ba..5e0a5b7 100644 --- a/pkgs/upgrade-system/upgrade-system.sh +++ b/pkgs/upgrade-system/upgrade-system.sh @@ -4,6 +4,7 @@ set -euo pipefail ALLOW_REBOOT= BRANCH="main" +BINARY_CACHE= HOST_NAME=$HOSTNAME NO_DELAY= @@ -18,6 +19,11 @@ while [[ $# -gt 0 ]]; do shift shift ;; + --cache) + BINARY_CACHE="$2" + shift + shift + ;; --hostname) HOST_NAME="$2" shift @@ -65,7 +71,7 @@ if [[ "$OLD_STORE_PATH" == "$NEW_STORE_PATH" ]]; then fi echo "Downloading ${NEW_STORE_PATH}" -nix copy --from "https://cache.kyouma.net" "${NEW_STORE_PATH}" +nix copy --from "${BINARY_CACHE}" --to "daemon" "${NEW_STORE_PATH}" echo "Adding path to system profile" nix-env -p "/nix/var/nix/profiles/system" --set "${NEW_STORE_PATH}"