diff --git a/ops/nixos/lib/common.nix b/ops/nixos/lib/common.nix index abf1a1e34a..29e944bb7c 100644 --- a/ops/nixos/lib/common.nix +++ b/ops/nixos/lib/common.nix @@ -11,6 +11,11 @@ in { imports = [ ../../../third_party/home-manager/nixos ]; + options.my.specialisationName = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + }; + options.my.rundeck.hostname = lib.mkOption { type = lib.types.str; default = config.networking.fqdn; @@ -213,24 +218,30 @@ in 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" | grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')" - echo "nixos_running_system{version=\"$my_version_string\", hash=\"$my_hash_string\"} 1" > /run/prometheus-textfile-exports/running_system.prom + 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" | grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')" - echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\"} 1" > /run/prometheus-textfile-exports/booted_system.prom + 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 ''; }; 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" | grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')" - echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\"} 1" > /run/prometheus-textfile-exports/booted_system.prom + 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 + ''; + system.extraSystemBuilderCmds = lib.mkAfter '' + echo "${if config.my.specialisationName == null then "" else config.my.specialisationName}" > $out/specialisation-name ''; - system.nixos.tags = lib.mkBefore [ + system.nixos.tags = lib.mkBefore ([ depot.version - ]; + ] ++ lib.optional (config.my.specialisationName != null) "specialisation-${config.my.specialisationName}"); services.nginx = { recommendedTlsSettings = true; diff --git a/ops/nixos/lib/rebuilder.nix b/ops/nixos/lib/rebuilder.nix index ed96b0ffbb..2fae18129d 100644 --- a/ops/nixos/lib/rebuilder.nix +++ b/ops/nixos/lib/rebuilder.nix @@ -14,7 +14,14 @@ pkgs.writeShellScriptBin "rebuilder" '' export AWS_ACCESS_KEY_ID="${depot.ops.secrets.nixCache.AWS_ACCESS_KEY_ID}" export AWS_SECRET_ACCESS_KEY="${depot.ops.secrets.nixCache.AWS_SECRET_ACCESS_KEY}" + current_specialisation="$(cat /run/current-system/specialisation-name 2>/dev/null)" + specialisation_path="" + if [[ ! -z "$current_specialisation" ]]; then + specialisation_path="specialisation/$current_specialisation/" + fi + system="$(nix-build --option substituters "https://cache.nixos.org s3://lukegb-nix-cache?endpoint=storage.googleapis.com&trusted=1" -E "(import $DEPOT_PATH {}).ops.nixos.${system}" --no-out-link)" nix-env -p /nix/var/nix/profiles/system --set "$system" - "$system/bin/switch-to-configuration" switch -'' \ No newline at end of file + "$system/''${specialisation_path}bin/switch-to-configuration" test + "$system/bin/switch-to-configuration" boot +'' diff --git a/ops/nixos/porcorosso/default.nix b/ops/nixos/porcorosso/default.nix index ad15246ab0..033ff29a2e 100644 --- a/ops/nixos/porcorosso/default.nix +++ b/ops/nixos/porcorosso/default.nix @@ -161,6 +161,7 @@ in { services.xserver.windowManager.i3.enable = true; services.xserver.videoDrivers = [ "nvidia" ]; specialisation.intelGraphics.configuration = { + my.specialisationName = "intelGraphics"; services.xserver.videoDrivers = lib.mkForce [ "intel" ]; }; services.xserver.displayManager.gdm = {