summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-09-13 18:58:55 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-02-05 23:15:18 +0100
commit7e9b745174092b5eee25890d5d377db58236d3dd (patch)
treef09c5bf62c03e849d7d7bbd27e61b486a1fb2e8f
parent855fcc324a5e83d3abced135d4b6ecad02cc022a (diff)
downloadnixpkgs-7e9b745174092b5eee25890d5d377db58236d3dd.tar
nixpkgs-7e9b745174092b5eee25890d5d377db58236d3dd.tar.gz
nixpkgs-7e9b745174092b5eee25890d5d377db58236d3dd.tar.bz2
nixpkgs-7e9b745174092b5eee25890d5d377db58236d3dd.tar.lz
nixpkgs-7e9b745174092b5eee25890d5d377db58236d3dd.tar.xz
nixpkgs-7e9b745174092b5eee25890d5d377db58236d3dd.tar.zst
nixpkgs-7e9b745174092b5eee25890d5d377db58236d3dd.zip
nixos-version: Add --json flag and show system.configurationRevision
-rw-r--r--nixos/doc/manual/man-nixos-version.xml29
-rw-r--r--nixos/modules/installer/tools/nixos-version.sh5
-rw-r--r--nixos/modules/installer/tools/tools.nix1
3 files changed, 33 insertions, 2 deletions
diff --git a/nixos/doc/manual/man-nixos-version.xml b/nixos/doc/manual/man-nixos-version.xml
index e9ad8bddcac..aada08c5b4a 100644
--- a/nixos/doc/manual/man-nixos-version.xml
+++ b/nixos/doc/manual/man-nixos-version.xml
@@ -12,16 +12,22 @@
  </refnamediv>
  <refsynopsisdiv>
   <cmdsynopsis>
-   <command>nixos-version</command> 
+   <command>nixos-version</command>
    <arg>
     <option>--hash</option>
    </arg>
-    
+
    <arg>
     <option>--revision</option>
    </arg>
+
+   <arg>
+    <option>--json</option>
+   </arg>
+
   </cmdsynopsis>
  </refsynopsisdiv>
+
  <refsection>
   <title>Description</title>
   <para>
@@ -84,12 +90,16 @@
    </variablelist>
   </para>
  </refsection>
+
  <refsection>
   <title>Options</title>
+
   <para>
    This command accepts the following options:
   </para>
+
   <variablelist>
+
    <varlistentry>
     <term>
      <option>--hash</option>
@@ -107,6 +117,21 @@
      </para>
     </listitem>
    </varlistentry>
+
+   <varlistentry>
+    <term>
+     <option>--json</option>
+    </term>
+    <listitem>
+     <para>
+      Print a JSON representation of the versions of NixOS and the
+      top-level configuration flake.
+     </para>
+    </listitem>
+   </varlistentry>
+
   </variablelist>
+
  </refsection>
+
 </refentry>
diff --git a/nixos/modules/installer/tools/nixos-version.sh b/nixos/modules/installer/tools/nixos-version.sh
index 190c49a33ec..0117aa1549c 100644
--- a/nixos/modules/installer/tools/nixos-version.sh
+++ b/nixos/modules/installer/tools/nixos-version.sh
@@ -8,6 +8,11 @@ case "$1" in
   --hash|--revision)
     echo "@revision@"
     ;;
+  --json)
+    cat <<EOF
+{"nixosVersion": "@version@", "nixpkgsRevision": "@revision@", "configurationRevision": "@configurationRevision@"}
+EOF
+    ;;
   *)
     echo "@version@ (@codeName@)"
     ;;
diff --git a/nixos/modules/installer/tools/tools.nix b/nixos/modules/installer/tools/tools.nix
index 9c8e26ba242..47fa4725288 100644
--- a/nixos/modules/installer/tools/tools.nix
+++ b/nixos/modules/installer/tools/tools.nix
@@ -48,6 +48,7 @@ let
     name = "nixos-version";
     src = ./nixos-version.sh;
     inherit (config.system.nixos) version codeName revision;
+    inherit (config.system) configurationRevision;
   };
 
   nixos-enter = makeProg {