From 120f20edd290a93c456b7635e5f3d234782ebb73 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 26 Aug 2026 17:50:21 +0200 Subject: [PATCH 1/2] Inject the repository commit id in boot menu entries For convenience, it allows to get the commit id from the boot menu, but this modifies the derivation produced by nixos-rebuild since the commit id is injected via the builtins.getEnv. --- pkgs/default.nix | 4 +++- pkgs/nixos-rebuild/default.nix | 23 +++++++++++++++++++++++ pkgs/overlay.nix | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 pkgs/nixos-rebuild/default.nix diff --git a/pkgs/default.nix b/pkgs/default.nix index 44405c88..ed459676 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -2,7 +2,9 @@ # # SPDX-License-Identifier: MIT -{ callPackage }: { +{ callPackage, nixos-rebuild }: { mkPlasmaLookAndFeelPackage = callPackage ./plasma/mk-look-and-feel-package.nix { }; plasma-portail-tray-icon = callPackage ./plasma/portail-tray-icon { }; + nixos-rebuild = callPackage ./nixos-rebuild { inherit nixos-rebuild; }; + nixos-rebuild-unwrapped = nixos-rebuild; } diff --git a/pkgs/nixos-rebuild/default.nix b/pkgs/nixos-rebuild/default.nix new file mode 100644 index 00000000..5cddd7f7 --- /dev/null +++ b/pkgs/nixos-rebuild/default.nix @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2026 Antoine Eiche +# +# SPDX-License-Identifier: MIT + +# nixos-rebuild is wrapped to add the repository HEAD commit id to the added boot menu entry. +# Note the derivation produced by this nixos-rebuild wrapper then differs from the one produced from the repository itself since it injects the commit id via builtins.getEnv. +{ + writeShellApplication, + nixos-rebuild, + git, +}: +writeShellApplication { + name = "nixos-rebuild"; + runtimeInputs = [ + nixos-rebuild + git + ]; + text = '' + revision=$(git rev-parse HEAD) + export NIXOS_LABEL_VERSION="''${revision:0:7}" + nixos-rebuild "$@" + ''; +} diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index d89e5234..775a3885 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -2,4 +2,8 @@ # # SPDX-License-Identifier: MIT -super: self: (import ./default.nix { inherit (super) callPackage; }) +final: prev: +(import ./default.nix { + inherit (final) callPackage; + nixos-rebuild = prev.nixos-rebuild; +}) From 8d6263dc52cad06ce6e7b3c9c045f74b46d76366 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 9 Sep 2026 17:44:09 +0200 Subject: [PATCH 2/2] fixup! Inject the repository commit id in boot menu entries --- modules/updates/automatic-pull.nix | 2 +- pkgs/default.nix | 5 ++--- pkgs/{nixos-rebuild => nixos-rebuild-git-aware}/default.nix | 5 +++++ pkgs/overlay.nix | 6 +----- 4 files changed, 9 insertions(+), 9 deletions(-) rename pkgs/{nixos-rebuild => nixos-rebuild-git-aware}/default.nix (69%) diff --git a/modules/updates/automatic-pull.nix b/modules/updates/automatic-pull.nix index 6262de79..04971106 100644 --- a/modules/updates/automatic-pull.nix +++ b/modules/updates/automatic-pull.nix @@ -54,7 +54,7 @@ in pkgs.gawk pkgs.libnotify pkgs.sudo - pkgs.nixos-rebuild + pkgs.nixos-rebuild-git-aware ]; script = '' _notify_current_user() { diff --git a/pkgs/default.nix b/pkgs/default.nix index ed459676..f9b2ac79 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -2,9 +2,8 @@ # # SPDX-License-Identifier: MIT -{ callPackage, nixos-rebuild }: { +{ callPackage }: { mkPlasmaLookAndFeelPackage = callPackage ./plasma/mk-look-and-feel-package.nix { }; plasma-portail-tray-icon = callPackage ./plasma/portail-tray-icon { }; - nixos-rebuild = callPackage ./nixos-rebuild { inherit nixos-rebuild; }; - nixos-rebuild-unwrapped = nixos-rebuild; + nixos-rebuild-git-aware = callPackage ./nixos-rebuild-git-aware { }; } diff --git a/pkgs/nixos-rebuild/default.nix b/pkgs/nixos-rebuild-git-aware/default.nix similarity index 69% rename from pkgs/nixos-rebuild/default.nix rename to pkgs/nixos-rebuild-git-aware/default.nix index 5cddd7f7..19a75b52 100644 --- a/pkgs/nixos-rebuild/default.nix +++ b/pkgs/nixos-rebuild-git-aware/default.nix @@ -4,6 +4,7 @@ # nixos-rebuild is wrapped to add the repository HEAD commit id to the added boot menu entry. # Note the derivation produced by this nixos-rebuild wrapper then differs from the one produced from the repository itself since it injects the commit id via builtins.getEnv. +# See https://github.com/nixos/nixpkgs/blob/ddce4d809a16b9f0614e76636063282f6fb02908/nixos/modules/misc/label.nix#L69 for details. { writeShellApplication, nixos-rebuild, @@ -16,6 +17,10 @@ writeShellApplication { git ]; text = '' + if [ "$(git rev-parse --is-inside-work-tree 2>&1)" != "true" ]; then + echo "error: the current directory must be a Git repository." + exit 1 + fi revision=$(git rev-parse HEAD) export NIXOS_LABEL_VERSION="''${revision:0:7}" nixos-rebuild "$@" diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index 775a3885..c0fe1973 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -2,8 +2,4 @@ # # SPDX-License-Identifier: MIT -final: prev: -(import ./default.nix { - inherit (final) callPackage; - nixos-rebuild = prev.nixos-rebuild; -}) +final: prev: (import ./default.nix { inherit (final) callPackage; })