From 9370d17b8298a7e1bf5f99fb0b2c36d3af9809a8 Mon Sep 17 00:00:00 2001 From: Alexander Tomokhov Date: Mon, 9 Oct 2023 02:07:47 +0400 Subject: [PATCH] flake: embed dirty revision of NixOS configuration instead The inevitable `--override-input` nix build (and nixos-rebuild) option induces dirty state of the NixOS flake, thus `self.rev` couldn't be used together. --- flake.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 05c23d1..7866a0d 100644 --- a/flake.nix +++ b/flake.nix @@ -22,10 +22,10 @@ }: let system = "x86_64-linux"; - cfgShortRev = - if self ? rev then builtins.substring 0 7 self.rev else "dirty"; + # (only "dirty", because userdata.json and others are overriden) + cfgShortRev = builtins.substring 0 7 self.dirtyRev; nixosLabel = config: - "${cfgShortRev}.${config.system.nixos.release}.${nixpkgs.shortRev}"; + "${config.system.nixos.release}.${cfgShortRev}.${nixpkgs.shortRev}"; userdata = builtins.fromJSON (builtins.readFile userdata-json); hardware-configuration = import hardware-configuration-nix; in @@ -40,8 +40,12 @@ hardware-configuration # main configuration part ./configuration.nix - # we need to embed NixOS repository git commit sha1 - ({ config, ... }: { system.nixos.label = nixosLabel config; }) + # we need NixOS repository git commit sha1 embedded + ({ config, ... }: { + system.nixos.label = nixosLabel config; + system.nixos.version = nixosLabel config; + system.configurationRevision = self.dirtyRev; + }) ]; }; };