ops/nixos: add nixos-size to measure total closure pinned by booted-system/current-system mismatch
This commit is contained in:
parent
bd4e52105d
commit
55b6bd2a19
5 changed files with 50 additions and 8 deletions
|
@ -69,4 +69,5 @@
|
|||
extraPkgs = pkgs: with pkgs; [ openssl gnome.zenity ];
|
||||
};
|
||||
vault-acme = pkgs.callPackage ./vault-acme { };
|
||||
nixos-size = pkgs.callPackage ./nixos-size { };
|
||||
} // (import ./heptapod-runner args)
|
||||
|
|
3
nix/pkgs/nixos-size/combined-builder.sh
Executable file
3
nix/pkgs/nixos-size/combined-builder.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo -ne "$sp1\n$sp2\n" > $out
|
13
nix/pkgs/nixos-size/combined.nix
Normal file
13
nix/pkgs/nixos-size/combined.nix
Normal file
|
@ -0,0 +1,13 @@
|
|||
{ builder ? ./combined-builder.sh }:
|
||||
|
||||
derivation {
|
||||
system = builtins.currentSystem;
|
||||
name = "nixos-size-combined";
|
||||
inherit builder;
|
||||
|
||||
sp1 = builtins.storePath /run/current-system;
|
||||
sp2 = builtins.storePath /run/booted-system;
|
||||
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
}
|
15
nix/pkgs/nixos-size/default.nix
Normal file
15
nix/pkgs/nixos-size/default.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{ writeShellApplication, nix_2_3, gawk }:
|
||||
|
||||
writeShellApplication {
|
||||
name = "nixos-size";
|
||||
runtimeInputs = [ nix_2_3 gawk ];
|
||||
text = ''
|
||||
test -e /run/booted-system || exit 0
|
||||
|
||||
combined_path="$(nix-build ${./combined.nix} --no-out-link --arg builder ${./combined-builder.sh})"
|
||||
|
||||
echo "nixos_closure_size{type=\"booted-system\"} $(nix path-info -S /run/booted-system | awk '{ print $2 }')"
|
||||
echo "nixos_closure_size{type=\"current-system\"} $(nix path-info -S /run/current-system | awk '{ print $2 }')"
|
||||
echo "nixos_closure_size{type=\"combined\"} $(nix path-info -S "$combined_path" | awk '{ print $2 }')"
|
||||
'';
|
||||
}
|
|
@ -243,23 +243,33 @@ in
|
|||
system.activationScripts.node-exporter = {
|
||||
text = ''
|
||||
test -d /run/prometheus-textfile-exports || mkdir /run/prometheus-textfile-exports
|
||||
|
||||
my_version_string="$(cat "$systemConfig/nixos-version")"
|
||||
my_hash_string="$(readlink -f "$systemConfig" | ${pkgs.gnugrep}/bin/grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
|
||||
my_specialisation="$(cat "$systemConfig/specialisation-name" 2>/dev/null || true)"
|
||||
echo "nixos_running_system{version=\"$my_version_string\", hash=\"$my_hash_string\", specialisation=\"$my_specialisation\"} 1" > /run/prometheus-textfile-exports/running_system.prom
|
||||
|
||||
my_version_string="$(cat "/run/booted-system/nixos-version")"
|
||||
my_hash_string="$(readlink -f "/run/booted-system" | ${pkgs.gnugrep}/bin/grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
|
||||
my_specialisation="$(cat "/run/booted-system/specialisation-name" 2>/dev/null || true)"
|
||||
echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\", specialisation=\"$my_specialisation\"} 1" > /run/prometheus-textfile-exports/booted_system.prom
|
||||
if test -e /run/booted-system; then
|
||||
my_version_string="$(cat "/run/booted-system/nixos-version")"
|
||||
my_hash_string="$(readlink -f "/run/booted-system" | ${pkgs.gnugrep}/bin/grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
|
||||
my_specialisation="$(cat "/run/booted-system/specialisation-name" 2>/dev/null || true)"
|
||||
echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\", specialisation=\"$my_specialisation\"} 1" > /run/prometheus-textfile-exports/booted_system.prom
|
||||
fi
|
||||
|
||||
${depot.nix.pkgs.nixos-size}/bin/nixos-size > /run/prometheus-textfile-exports/nixos_size.prom
|
||||
'';
|
||||
};
|
||||
boot.postBootCommands = lib.mkAfter ''
|
||||
test -d /run/prometheus-textfile-exports || mkdir /run/prometheus-textfile-exports
|
||||
my_version_string="$(cat "/run/booted-system/nixos-version")"
|
||||
my_hash_string="$(readlink -f "/run/booted-system" | ${pkgs.gnugrep}/bin/grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
|
||||
my_specialisation="$(cat "/run/booted-system/specialisation-name" 2>/dev/null || true)"
|
||||
echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\", specialisation=\"$my_specialisation\"} 1" > /run/prometheus-textfile-exports/booted_system.prom
|
||||
|
||||
if test -e /run/booted-system; then
|
||||
my_version_string="$(cat "/run/booted-system/nixos-version")"
|
||||
my_hash_string="$(readlink -f "/run/booted-system" | ${pkgs.gnugrep}/bin/grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
|
||||
my_specialisation="$(cat "/run/booted-system/specialisation-name" 2>/dev/null || true)"
|
||||
echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\", specialisation=\"$my_specialisation\"} 1" > /run/prometheus-textfile-exports/booted_system.prom
|
||||
fi
|
||||
|
||||
${depot.nix.pkgs.nixos-size}/bin/nixos-size > /run/prometheus-textfile-exports/nixos_size.prom
|
||||
'';
|
||||
system.extraSystemBuilderCmds = lib.mkAfter ''
|
||||
echo "${if config.my.specialisationName == null then "" else config.my.specialisationName}" > $out/specialisation-name
|
||||
|
|
Loading…
Reference in a new issue