refactor
Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
parent
45d6f4b0f3
commit
1281c57892
191 changed files with 755 additions and 7893 deletions
73
packages/nixos-revision/default.nix
Normal file
73
packages/nixos-revision/default.nix
Normal file
|
@ -0,0 +1,73 @@
|
|||
{ pkgs
|
||||
, lib
|
||||
, gitHostCommitUrl ? "https://github.com/jakehamilton/config/commit"
|
||||
, ...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib.plusultra) 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 ];
|
||||
};
|
||||
|
||||
package =
|
||||
pkgs.writeShellScriptBin "nixos-revision" ''
|
||||
HAS_HELP=false
|
||||
HAS_OPEN=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
HAS_HELP=true
|
||||
shift
|
||||
;;
|
||||
-o|--open)
|
||||
HAS_OPEN=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $HAS_HELP == true ]; then
|
||||
HELP_MSG="
|
||||
nixos-revision
|
||||
|
||||
USAGE
|
||||
|
||||
nixos-revision [options]
|
||||
|
||||
OPTIONS
|
||||
|
||||
-h, --help Show this help message
|
||||
-o, --open Open the revision on GitHub
|
||||
|
||||
EXAMPLES
|
||||
|
||||
$ # Print the current revision
|
||||
$ nixos-revision
|
||||
|
||||
$ # Open the current revision on GitHub
|
||||
$ nixos-revision --open
|
||||
"
|
||||
echo "$HELP_MSG"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
REVISION=$(nixos-version --json | ${pkgs.jq}/bin/jq -r .configurationRevision)
|
||||
|
||||
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
|
||||
'';
|
||||
in
|
||||
override-meta new-meta package
|
Loading…
Add table
Add a link
Reference in a new issue