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 44405c88..f9b2ac79 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -5,4 +5,5 @@ { callPackage }: { mkPlasmaLookAndFeelPackage = callPackage ./plasma/mk-look-and-feel-package.nix { }; plasma-portail-tray-icon = callPackage ./plasma/portail-tray-icon { }; + nixos-rebuild-git-aware = callPackage ./nixos-rebuild-git-aware { }; } diff --git a/pkgs/nixos-rebuild-git-aware/default.nix b/pkgs/nixos-rebuild-git-aware/default.nix new file mode 100644 index 00000000..19a75b52 --- /dev/null +++ b/pkgs/nixos-rebuild-git-aware/default.nix @@ -0,0 +1,28 @@ +# 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. +# See https://github.com/nixos/nixpkgs/blob/ddce4d809a16b9f0614e76636063282f6fb02908/nixos/modules/misc/label.nix#L69 for details. +{ + writeShellApplication, + nixos-rebuild, + git, +}: +writeShellApplication { + name = "nixos-rebuild"; + runtimeInputs = [ + nixos-rebuild + 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 d89e5234..c0fe1973 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -2,4 +2,4 @@ # # SPDX-License-Identifier: MIT -super: self: (import ./default.nix { inherit (super) callPackage; }) +final: prev: (import ./default.nix { inherit (final) callPackage; })