nixos-version: escape specialisations and use kernel.modDirVersion if available

This commit is contained in:
Thiago Kenji Okada
2026-09-28 10:57:35 +01:00
parent 716f0c4e18
commit 6500ce6442
2 changed files with 13 additions and 7 deletions

View File

@@ -28,15 +28,15 @@ case "$1" in
echo "@kernelVersion@"
;;
--specialisations)
if [[ -z "@specialisations@" ]]; then
specialisations=@specialisations@
if [[ -z "$specialisations" ]]; then
echo "$0: no specialisations found" >&2
exit 1
else
echo "@specialisations@"
fi
printf '%s\n' "$specialisations"
;;
--json)
cat <<EOF
cat <<'EOF'
@json@
EOF
;;

View File

@@ -58,13 +58,19 @@ let
inherit (config.system.nixos) version codeName revision;
inherit (config.system) configurationRevision;
kernelVersion =
if config.boot.kernel.enable then config.boot.kernelPackages.kernel.version else null;
specialisations = lib.attrNames config.specialisation;
if config.boot.kernel.enable then
# modDirVersion returns 6.18.54-xanmod1 instead of 6.18.54
config.boot.kernelPackages.kernel.modDirVersion or config.boot.kernelPackages.kernel.version
else
null;
specialisations = lib.escapeShellArg (
lib.concatStringsSep " " (lib.attrNames config.specialisation)
);
json = builtins.toJSON (
{
nixosVersion = config.system.nixos.version;
inherit kernelVersion specialisations;
specialisations = lib.attrNames config.specialisation;
}
// lib.optionalAttrs (kernelVersion != null) {
inherit kernelVersion;