forked from c3d2/nix-config
modules/autoupdate: add update-from-hydra script
This commit is contained in:
parent
e8cffff886
commit
6ee303cebc
11
README.md
11
README.md
|
@ -116,6 +116,17 @@ nix run .#list-upgradable
|
|||
|
||||
Checks all hosts with a `nixosConfiguration` in `flake.nix`.
|
||||
|
||||
## Update from [Hydra build](https://hydra.hq.c3d2.de/jobset/c3d2/nix-config#tabs-jobs)
|
||||
|
||||
The fastest way to update a system, a manual alternative to setting
|
||||
`c3d2.autoUpdate = true;`
|
||||
|
||||
Just run:
|
||||
|
||||
```shell
|
||||
update-from-hydra
|
||||
```
|
||||
|
||||
## Creating a new Proxmox container
|
||||
|
||||
Use the `nixprox.sh` script that should be copied to
|
||||
|
|
|
@ -11,13 +11,12 @@
|
|||
default = false;
|
||||
};
|
||||
|
||||
config = lib.mkIf config.c3d2.autoUpdate {
|
||||
# the presence of this file signifies that the system is
|
||||
config = {
|
||||
# the presence of this .service file signifies that the system is
|
||||
# autoupdate-enabled. it is checked to prevent autoupdating back
|
||||
# to a system without autoupdate when deploying with autoupdate
|
||||
# for the first time.
|
||||
|
||||
systemd.services.autoupdate = {
|
||||
systemd.services.autoupdate = lib.mkIf config.c3d2.autoUpdate {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
path = with pkgs; [ nixFlakes nettools curl jq ];
|
||||
serviceConfig = {
|
||||
|
@ -55,9 +54,36 @@
|
|||
startAt = "hourly";
|
||||
};
|
||||
|
||||
nix.gc = {
|
||||
nix.gc = lib.mkIf config.c3d2.autoUpdate {
|
||||
automatic = true;
|
||||
randomizedDelaySec = "6h";
|
||||
};
|
||||
|
||||
environment.systemPackages = [ (
|
||||
# Provide a manual updating script that fetches the latest
|
||||
# updated+built system from Hydra
|
||||
pkgs.writeScriptBin "update-from-hydra" ''
|
||||
#! ${pkgs.runtimeShell} -e
|
||||
|
||||
OLD=$(readlink /run/current-system)
|
||||
echo Current system: $(basename $OLD)
|
||||
NEW=$(curl -sLH "Accept: application/json" https://hydra.hq.c3d2.de/job/c3d2/nix-config/x86_64-linux.$(hostname)/latest | ${pkgs.jq}/bin/jq -r .buildoutputs.out.path)
|
||||
if [ -z "$NEW" ]; then
|
||||
echo "Unable to obtain updated system"
|
||||
exit 1
|
||||
fi
|
||||
echo New system: $(basename $NEW)
|
||||
|
||||
if [ "$OLD" != "$NEW" ]; then
|
||||
echo "Fetching new system built by https://hydra.hq.c3d2.de/jobset/c3d2/nix-config"
|
||||
# this should fetch the new system from the binary cache
|
||||
nix copy --from https://nix-serve.hq.c3d2.de "$NEW"
|
||||
echo "Switch to the new system..."
|
||||
"$NEW/bin/switch-to-configuration" switch
|
||||
else
|
||||
echo "No update required"
|
||||
fi
|
||||
''
|
||||
) ];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue