Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/updates/automatic-pull.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ in
pkgs.gawk
pkgs.libnotify
pkgs.sudo
pkgs.nixos-rebuild
pkgs.nixos-rebuild-git-aware
];
script = ''
_notify_current_user() {
Expand Down
1 change: 1 addition & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
}
28 changes: 28 additions & 0 deletions pkgs/nixos-rebuild-git-aware/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2026 Antoine Eiche <antoine.eiche@lewocorp.eu>
#
# SPDX-License-Identifier: MIT

# nixos-rebuild is wrapped to add the repository HEAD commit id to the added boot menu entry.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called git-aware-nixos-rebuild or something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally called it nixos-rebuild-git-aware.

Actually, i'm a bit confused because in your previous comments, I had understood that you wanted to override nixos-rebuild while exposing the original one via the attribute nixos-rebuild-unwrapped.

In this fixup commit, I do not modify the attribute nixos-rebuild but just add an attribute nixos-rebuild-git-aware. This is much simpler.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote:

it should be moved into a proper overlay directory and overlaid in the ambient pkgs so that every other module can refer to it, including the upgrade manual command

i also think it should shadow nixos-rebuild directly and re-expose nixos-rebuild unwrapped as an attribute on it as it's usual etiquette in nixpkgs

this doesn't say anything about the name of the attribute? shadowing meant that it should shadow the nixos-rebuild binary in $PATH, but you can have the attribute named nixos-rebuild-git-aware producing a bin/nixos-rebuild and having a nixos-rebuild-git-aware.unwrapped attribute to get you access to the git-unaware attribute?

# 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a link to the nixos-rebuild wrapper produced by the repository itself and the place where it makes use of builtins.getEnv ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a link to the nixos-rebuild wrapper produced by the repository itself

What do you mean?
(This file contains the wrapper itself.)

I added a link to the nixpkgs code using getEnv (maybeEnv actually, which is a wrapper around getEnv).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This comment seems to say there's a different piece of code to look at. Otherwise, can you try to rework the comment? I think I have trouble understanding it after rereading a couple of review passes already.

# 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this is run not in a Git repo? Can we have minimal fallback/error-handling here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

export NIXOS_LABEL_VERSION="''${revision:0:7}"
nixos-rebuild "$@"
'';
}
2 changes: 1 addition & 1 deletion pkgs/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# SPDX-License-Identifier: MIT

super: self: (import ./default.nix { inherit (super) callPackage; })
final: prev: (import ./default.nix { inherit (final) callPackage; })
Loading