diff options
| author | Soispha Peetz <soispha@b-peetz.de> | 2026-10-30 15:15:54 +0100 |
|---|---|---|
| committer | Soispha Peetz <soispha@b-peetz.de> | 2026-11-27 00:27:17 +0100 |
| commit | e3c893c7df92e026309492dd1e646b7a77979656 (patch) | |
| tree | 93326849419dce78ce31704425d94a18122cef3f | |
| parent | inputs.nix: Add more deduplications and clearly denote stable/unstable nixpkgs (diff) | |
| download | nixos-server-e3c893c7df92e026309492dd1e646b7a77979656.zip | |
treewide: Various fixes
Diffstat (limited to '')
| -rwxr-xr-x | pkgs/update_pkgs.sh | 4 | ||||
| -rwxr-xr-x | scripts/build.sh | 81 | ||||
| -rw-r--r-- | secrets.nix | 41 | ||||
| -rwxr-xr-x | update.sh | 9 |
4 files changed, 93 insertions, 42 deletions
diff --git a/pkgs/update_pkgs.sh b/pkgs/update_pkgs.sh index 3e33b72..d447889 100755 --- a/pkgs/update_pkgs.sh +++ b/pkgs/update_pkgs.sh @@ -9,7 +9,7 @@ cd "$(dirname "$0")" || die "Bug: run with the wrong first arg: '$0'!" cd ./by-name || die "(BUG): The directory './by-name' does not exist?" # First check if all the update scripts conform to the standard -files_with_update="$(mktemp)" +files_with_update="$(mktemp -t update_pkgs_XXXXX)" trap 'rm "$files_with_update"' EXIT fd '^update.sh$' . --type file --extension sh --max-depth 3 | while read -r file; do @@ -30,8 +30,6 @@ fd . --type directory --max-depth 1 | while read -r shard; do if [ -x update.sh ]; then printf " \033[34;1m> \033[0m\033[34;1m%s\033[0m\n" "Running '${shard}${package}update.sh' .." - [ -f flake.nix ] && nix flake update - direnv allow eval "$(direnv export bash 2>/dev/null)" ./update.sh "$@" diff --git a/scripts/build.sh b/scripts/build.sh index b2e0e06..9cc4e46 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,14 +1,44 @@ #! /usr/bin/env sh - set -eu +build_system() { + host="$1" + + show_trace_arg="" + if [ "$show_trace" = true ]; then + show_trace_arg="--show-trace" + fi + + _val="$(nix build ".#nixosConfigurations.$host.config.system.build.toplevel" --print-out-paths --no-link --option max-jobs 1 $show_trace_arg)" + exit_val="$?" + + if [ "$exit_val" -ne 0 ]; then + echo "ERROR: Failed to build you system config for host: '$host'" 1>&2 + printf 1 + else + printf "%s" "$_val" + fi +} +remove_symlink() { + link="$1" + if [ -s "$link" ]; then + rm "$link" + elif ! [ -e "$link" ]; then + rm "$link" || { + : "Ignore not existing files" + } + else + echo "ERROR: '$link' is not a symlink. Not removing it." 1>&2 + exit 1 + fi +} + root="$(git rev-parse --show-toplevel)" -wrong_arg=false use_dirty=true show_trace=false -for arg in "$@"; do - case "$arg" in +while [ "$#" -ne 0 ]; do + case "$1" in --dirty) use_dirty=true ;; @@ -18,17 +48,18 @@ for arg in "$@"; do --show-trace) show_trace=true ;; + --* | -*) + echo "arg '$1' is not known." + exit 2 + ;; *) - echo "arg '$arg' is not known." - wrong_arg=true + # We reached the hosts + break ;; esac + shift 1 done -if [ "$wrong_arg" = true ]; then - exit 2 -fi - if [ "$use_dirty" = "false" ]; then tmp="$(mktemp -d -t "server_build_script_XXXXX")" trap 'rm -r "$tmp"' EXIT @@ -41,20 +72,26 @@ if [ "$use_dirty" = "false" ]; then cd "$tmp" fi -for host in "server2" "server3"; do - show_trace_arg="" - if [ "$show_trace" = true ]; then - show_trace_arg="--show-trace" - fi +for host in "$@"; do + system="$(build_system "$host")" + [ "$system" = "1" ] && exit 1 + + result_link="$root/result-$host" + remove_symlink "$result_link" + nix-store --add-root "$result_link" --realise "$(readlink -f "$system")" - nix build ".#nixosConfigurations.$host.config.system.build.toplevel" --print-out-paths --option max-jobs 1 $show_trace_arg + # Try to also provide an easy link for potential home manager outputs. + fd "home-manager-\w*.service" "$result_link/etc/systemd/system" | while read -r hm; do + home_generation_link="$(grep ExecStart= "$hm" | awk '{print $2}')" + user_name="$(basename "$hm" | sed 's/home-manager-\(.*\)\.service/\1/')" + home_link="$root/result-$host-hm-$user_name" - result_file="$root/result-$host" - if [ -L "$result_file" ]; then - rm "$result_file" + remove_symlink "$home_link" + ln --symbolic "$home_generation_link" "$home_link" + done + + if [ "$host" = "$(hostname)" ]; then + nvd diff /run/current-system "$result_link" fi - nix-store --add-root "$result_file" --realise "$(readlink -f ./result)" - rm ./result done - # vim: ft=sh diff --git a/secrets.nix b/secrets.nix index e6694fe..2e68bdb 100644 --- a/secrets.nix +++ b/secrets.nix @@ -1,6 +1,9 @@ let soispha = "age1mshh4ynzhhzhff25tqwkg4j054g3xwrfznh98ycchludj9wjj48qn2uffn"; - sils = "age1vuhaey7kd9l76y6f9weeqmde3s4kjw38869ju6u3027yece2r3rqssjxst"; + jaki = "age1vuhaey7kd9l76y6f9weeqmde3s4kjw38869ju6u3027yece2r3rqssjxst"; + + tiamatHostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMD87QQIUXdEv3TaNRrI9clD9VgpsuVLFg2CrNGa5lVB"; + apzuHostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBivF5b6PyxsR/t+4Qg4IEDXHVXrjmZpslTUNXpvcVbO"; server2HostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL1TUFoCTplkqTVbXQ6qDCyeo2h8+C0vjrIlKu6vmq5f"; server3HostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP3s4FjGx7LEVf/GE3WeCl8TmCtPt8gW1J0mp0fUJBNm"; @@ -9,32 +12,40 @@ let testingKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILxdvBk/PC9fC7B5vqe9TvygZKY6LgDQ2mXRdVrthBM/"; publicKeys = { + "tiamat" = [ + soispha + tiamatHostKey + ]; + "apzu" = [ + soispha + apzuHostKey + ]; + "server2" = [ soispha - sils + jaki server2HostKey ]; - "server3" = [ soispha - sils + jaki server3HostKey ]; }; - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - nixLib = - import (builtins.fetchTree lock.nodes.library.locked).outPath {}; - inherit ((import (builtins.fetchTree lock.nodes.nixpkgs.locked).outPath {})) lib; + sources = import ./unflake.nix; + extra_lib = sources.library.nixLib; + pkgs-unstable = sources.nixpkgs-unstable.legacyPackages."x86_64-linux"; + inherit (pkgs-unstable) lib; secrets = let - base = nixLib.mkByName { + base = extra_lib.mkByName { useShards = false; fileName = "secrets"; baseDirectory = ./hosts/by-name; }; secrets = builtins.mapAttrs (name: value: - nixLib.mkByName { + extra_lib.mkByName { relativePaths = true; useShards = false; fileRegex = "^.*\\.age$"; @@ -66,9 +77,9 @@ let in secrets // { - "tests/common/email/dkim/alice.com/private.age".publicKeys = [soispha sils testingKey]; - "tests/common/email/dkim/bob.com/private.age".publicKeys = [soispha sils testingKey]; - "tests/common/email/dkim/mail1.server.com/private.age".publicKeys = [soispha sils testingKey]; - "tests/common/email/dkim/mail2.server.com/private.age".publicKeys = [soispha sils testingKey]; - "./tests/by-name/ro/rocie/secrets/login.age".publicKeys = [soispha sils testingKey]; + "tests/common/email/dkim/alice.com/private.age".publicKeys = [soispha jaki testingKey]; + "tests/common/email/dkim/bob.com/private.age".publicKeys = [soispha jaki testingKey]; + "tests/common/email/dkim/mail1.server.com/private.age".publicKeys = [soispha jaki testingKey]; + "tests/common/email/dkim/mail2.server.com/private.age".publicKeys = [soispha jaki testingKey]; + "./tests/by-name/ro/rocie/secrets/login.age".publicKeys = [soispha jaki testingKey]; } @@ -5,14 +5,19 @@ __update_sh_run() { printf "\033[35;1m> \033[0m\033[35;1m%s\033[0m\n" "Running '$(basename "$__update_sh_command") $*' .." - "$__update_sh_command" "$@" + if ! "$__update_sh_command" "$@"; then + printf "ERROR: Command failed ('%s')\n" "$__update_sh_command" + exit 1 + fi unset __update_sh_command } -__update_sh_run nix flake update +__update_sh_run unflake.sh --backend=nix __update_sh_run ./pkgs/update_pkgs.sh "$@" __update_sh_run build.sh __update_sh_run check.sh + +printf "\033[31;1m%s\033[0m\033[33;1m%s\033[0m\n" "Also update out-of-tree dependencies, like " "the external rust binaries" 2>&1 # vim: ft=sh |
