Simpler update script
This commit is contained in:
parent
b3d49e7415
commit
ca50fd7ecd
|
@ -12,14 +12,30 @@
|
|||
configGit = "${pkgs.git}/bin/git -C ${configPath}";
|
||||
in {
|
||||
home.packages = builtins.attrValues rec {
|
||||
updateSystem = pkgs.writeShellScriptBin "update-system" ''
|
||||
remote_host=$1
|
||||
host=''${remote_host:-${hostName}}
|
||||
|
||||
echo "Building configuration for $host …"
|
||||
output=$(nom build --builders @$(builders-configurator) ~/git/config#nixosConfigurations.$host.config.system.build.toplevel --no-link --print-out-paths)
|
||||
|
||||
if [[ -z "$remote_host" ]]; then
|
||||
on_target=("sudo" "-A")
|
||||
else
|
||||
on_target=("ssh" "root@$host")
|
||||
echo "Uploading configuration to $host …"
|
||||
nix copy $output --to ssh://$host
|
||||
fi
|
||||
$on_target[@] nix-env -p /nix/var/nix/profiles/system --set $output
|
||||
$on_target[@] $output/bin/switch-to-configuration switch
|
||||
'';
|
||||
maintenance = pkgs.writeShellScriptBin "maintenance" ''
|
||||
set -e
|
||||
${configGit} pull --ff-only
|
||||
echo "Running update-modes …"
|
||||
${updateModes}/bin/update-modes
|
||||
${lib.getExe updateModes}
|
||||
echo "Updating system …"
|
||||
${pkgs.nix-output-monitor}/bin/nom build --builders @$(builders-configurator) $(readlink -f /etc/nixos)#nixosConfigurations.$(hostname).config.system.build.toplevel --no-link
|
||||
/run/wrappers/bin/sudo -A /run/current-system/sw/bin/nixos-rebuild switch
|
||||
${lib.getExe updateSystem}
|
||||
echo "Maintenance finished."
|
||||
'';
|
||||
activateMode = pkgs.writeHaskellScript {name = "activate-mode";} ''
|
||||
|
|
|
@ -35,7 +35,6 @@ autoload -U colors && colors # Enable colors in prompt
|
|||
|
||||
alias nom-build-remote='nom build --builders @$(builders-configurator $(hostname) --force)'
|
||||
alias nix-build-remote='nix build --builders @$(builders-configurator $(hostname) --force)'
|
||||
# alias update-system='nom build --builders @$(builders-configurator)'" $(readlink -f /etc/nixos)#nixosConfigurations.$(hostname).config.system.build.toplevel --no-link && sudo -A nixos-rebuild switch"
|
||||
alias nixpkgs-review-pr-remote='nixpkgs-review pr --build-args "--builders @$(builders-configurator --force)"'
|
||||
alias nixpkgs-review-rev-remote='nixpkgs-review rev --build-args "--builders @$(builders-configurator --force)"'
|
||||
alias accounting='f() { if [[ "$1" == "" ]]; then year="buchhaltung" else year="$1" fi; hledger -f ~/git/buchhaltung/$year.journal ui -- --watch --theme=terminal -X€ -t -E}; f'
|
||||
|
@ -49,23 +48,6 @@ alias h='f() { if [[ "$1" == "" ]]; then hx .; else hx "$@"; fi}; f'
|
|||
alias vim="echo use h"
|
||||
alias r="NIX_AUTO_RUN=1"
|
||||
|
||||
update-system() {
|
||||
remote_host=$1
|
||||
host=${remote_host:-$HOST}
|
||||
|
||||
echo "Building configuration for $host …"
|
||||
output=$(nom build --builders @$(builders-configurator) $(readlink -f /etc/nixos)#nixosConfigurations.$host.config.system.build.toplevel --no-link --print-out-paths)
|
||||
|
||||
if [[ -z "$remote_host" ]] {
|
||||
on_target=("sudo" "-A")
|
||||
} else {
|
||||
on_target=("ssh" "root@$host")
|
||||
echo "Uploading configuration to $host …"
|
||||
nix copy $output --to ssh://$host
|
||||
}
|
||||
$on_target[@] nix-env -p /nix/var/nix/profiles/system --set $output
|
||||
$on_target[@] $output/bin/switch-to-configuration switch
|
||||
}
|
||||
|
||||
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
|
||||
add-zsh-hook chpwd chpwd_recent_dirs
|
||||
|
|
|
@ -141,6 +141,7 @@ playerModule = \var ->
|
|||
main :: IO ()
|
||||
main = do
|
||||
mode_var <- newVar Unrestricted
|
||||
dirty_var <- newTVarIO []
|
||||
let read_mode = fst <$> readTVarIO (value mode_var)
|
||||
modules =
|
||||
[ simpleModule (5 * oneSecond) $ do
|
||||
|
@ -179,22 +180,24 @@ main = do
|
|||
, simpleModule (5 * oneSecond) $ do
|
||||
dirs <- listDirectory "/home/maralorn/git"
|
||||
dirty <- fmap toText <$> filterM (isDirty . ("/home/maralorn/git/" <>)) dirs
|
||||
atomically $ writeTVar dirty_var dirty
|
||||
when' (not $ null dirty) $ withColor "e64443" [i|Dirty: #{Text.intercalate " " dirty}|]
|
||||
, simpleModule (5 * oneSecond) $ do
|
||||
dirs <- listDirectory "/home/maralorn/git"
|
||||
unpushed <- fmap toText <$> filterM (isUnpushed . ("/home/maralorn/git/" <>)) dirs
|
||||
when' (not $ null unpushed) $ withColor "fe640b" [i|Unpushed: #{Text.intercalate " " unpushed}|]
|
||||
, simpleModule (60 * oneSecond) $ do
|
||||
, simpleModule (5 * oneSecond) $ do
|
||||
current_kernel <- readlink "/run/current-system/kernel" |> captureTrim
|
||||
booted_kernel <- readlink "/run/booted-system/kernel" |> captureTrim
|
||||
when' (current_kernel /= booted_kernel) $ withColor "ffff00" "Booted kernel stale"
|
||||
, simpleModule (60 * oneSecond) $ do
|
||||
, simpleModule (5 * oneSecond) $ do
|
||||
current_commit <- readFileBS "/home/maralorn/git/config/.git/refs/heads/main"
|
||||
system_commit <- Exception.try @Exception.IOException $ readFileBS "/run/current-system/config-commit"
|
||||
home_commit <- Exception.try $ readFileBS "/home/maralorn/.volatile/modes/config-commit"
|
||||
let dirty_config = \case
|
||||
system_commit <- Exception.try do readFileBS "/run/current-system/config-commit"
|
||||
home_commit <- Exception.try do readFileBS "/home/maralorn/.volatile/modes/config-commit"
|
||||
dirty <- readTVarIO dirty_var
|
||||
let dirty_config :: Either Exception.IOException ByteString -> Bool = \case
|
||||
(Right commit) | commit == current_commit -> False
|
||||
_ -> True
|
||||
_ -> "config" `notElem` dirty
|
||||
system_dirty = dirty_config system_commit
|
||||
modes_dirty = dirty_config home_commit
|
||||
when' (system_dirty || modes_dirty) $ withColor "ffff00" [i|Current #{case (system_dirty,modes_dirty) of (True, True) -> "home and system"; (True, _) -> "system"; _ -> "home"} stale|]
|
||||
|
|
Loading…
Reference in a new issue