Skip to content

Regression: self.rev is absent #1503

Open
@brprice

Description

@brprice

I am using flakes with nixops, and employ the idiom

system.configurationRevision =
  if self ? rev
  then self.rev
  else throw "Refusing to build from a dirty Git tree!";

so I can trace which configuration a running deployment is using, via nixos-version --json (and enforce that every deploy corresponds to a commit).

Unfortunately this broke in the state backend rework in #1264. Now self.rev never exists, even in a clean checkout.

Reproducer:
Have a git repo with a flake.nix containing (contents are unimportant, except for testing self.rev)

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";

  outputs = { self, nixpkgs }:
{
      nixopsConfigurations.default = {
        network.description = "A server";
        network.storage.legacy.databasefile = "/tmp/state.nixops";
        nixpkgs = nixpkgs;
        serverA = {config, pkgs, ...}: {
          # let nixos-version --json know about the git revision of this flake
          system.configurationRevision =
            if self ? rev
            then self.rev
            else throw "Refusing to build from a dirty git tree!";
          fileSystems."/" = {
            device = "/dev/sda1";
            fsType = "ext3";
          };
          boot.loader.grub = {
            enable = true;
            version = 2;
            device = "/dev/sda";
          };
        };
      };
    };
}

Note that old versions of nixops work fine (this is just before #1264):

rm /tmp/state.nixops
NIXOPS_STATE=/tmp/state.nixops nix shell -L -v github:NixOS/nixops?rev=b55cbb23cc92f14b0e028ff2f8327cab4d9af5c6 -c nixops create --flake . -d serverA
NIXOPS_STATE=/tmp/state.nixops nix shell -L -v github:NixOS/nixops?rev=b55cbb23cc92f14b0e028ff2f8327cab4d9af5c6 -c nixops deploy -d serverA --build-only

However, newer versions complain that the flake is dirty -- in actuality the checkout is clean, but self.rev does not exist.
Post-#1264:

NIXOPS_STATE=/tmp/state.nixops nix shell -L -v github:NixOS/nixops?rev=9b3ac919d87db872854fb528064821b959ac38c1 -c nixops deploy -d serverA --build-only

master:

NIXOPS_STATE=/tmp/state.nixops nix shell -L -v github:NixOS/nixops?rev=ce1c57ec104636954296c229468bb65fa4ec7f8d -c nixops deploy -d serverA --build-only

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions