2024-11-19 10:31:29 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
gitHostCommitUrl ? "https://git.hoyer.xyz/harald/nixcfg/commit",
|
|
|
|
...
|
2024-03-21 15:00:36 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib.metacfg) override-meta;
|
|
|
|
|
|
|
|
new-meta = with lib; {
|
|
|
|
description = "A helper show the current git revision of the system configuration.";
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ jakehamilton ];
|
|
|
|
};
|
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
package = pkgs.writeShellScriptBin "nixos-revision" ''
|
|
|
|
HAS_HELP=false
|
|
|
|
HAS_OPEN=false
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
-h|--help)
|
|
|
|
HAS_HELP=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-o|--open)
|
|
|
|
HAS_OPEN=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
if [ $HAS_HELP == true ]; then
|
|
|
|
HELP_MSG="
|
|
|
|
nixos-revision
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
USAGE
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
nixos-revision [options]
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
OPTIONS
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
-h, --help Show this help message
|
|
|
|
-o, --open Open the revision on GitHub
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
EXAMPLES
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
$ # Print the current revision
|
|
|
|
$ nixos-revision
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
$ # Open the current revision on GitHub
|
|
|
|
$ nixos-revision --open
|
|
|
|
"
|
|
|
|
echo "$HELP_MSG"
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
REVISION=$(nixos-version --json | ${pkgs.jq}/bin/jq -r .configurationRevision)
|
2024-03-21 15:00:36 +01:00
|
|
|
|
2024-11-19 10:31:29 +01:00
|
|
|
if [ $HAS_OPEN == true ]; then
|
|
|
|
GITHUB_URL="${gitHostCommitUrl}/$REVISION"
|
|
|
|
echo "Opening URL: $GITHUB_URL"
|
|
|
|
${pkgs.xdg-utils}/bin/xdg-open $GITHUB_URL
|
|
|
|
else
|
|
|
|
echo $REVISION
|
|
|
|
fi
|
|
|
|
'';
|
2024-03-21 15:00:36 +01:00
|
|
|
in
|
|
|
|
override-meta new-meta package
|