nix-community / nixops-gce

NixOps Google Cloud Backend
25 stars 8 forks source link

After updating nixops I get an error referencing the resourceUri. #18

Open zaphar opened 3 years ago

zaphar commented 3 years ago

I'm assuming, without much to back it up other than some brief reading that this is due to an incompatibility between the sourceUri for bootstrap images in an existing network and the new nixops code.

error: A definition for option `sourceUri' is not of type `string'. Definition values:
- In `<unknown-file>':
    {
      name = "nixos-image-20-09-3531-3858fbc08e6-x86-64-linux";
      project = "nixos-cloud";
    }
(use '--show-trace' to show detailed location information)
tewfik-ghariani commented 3 years ago

This is due to the fact that the old nixops code is trying to associate the bootstrap image with the latest image available in nixpkgs as sourceUri

      nameValuePair ("bootstrap") [({ pkgs, ...}: {
        inherit (gce) project serviceAccount accessKey;
        sourceUri = images."${pkgs.lib.substring 0 5 pkgs.lib.nixpkgsVersion}" or images.latest;
      })]

https://github.com/NixOS/nixops/blob/pre-plugins/nix/eval-machine-info.nix#L293-L296

While the latest source image has changed the format as described per https://github.com/NixOS/nixpkgs/pull/117021

  # This format will be handled by the upcoming NixOPS 2.0 release.
  # The old images based on a GS object are deprecated.
  "20.09" = {
    project = "nixos-cloud";
    name = "nixos-image-20-09-3531-3858fbc08e6-x86-64-linux";
  };

https://github.com/nixos/nixpkgs/blob/master/nixos/modules/virtualisation/gce-images.nix#L9-L14

This seems to happen only when using the old nixops 1.7 in combination with the 'master' branch of nixpkgs

@zaphar what exactly do you have control on? Is it possible to update the gce-images.nix file in nixpkgs? Or is it possible to tweak the nixops code? Even better, can you switch to the new nixops 2.0?

FYI @AmineChikhaoui

zaphar commented 3 years ago

I was able to workaround this by adding a bootstrap image resource with the resourceUri and make it work. @tewfik-ghariani , is there a description or writeup anywhere of what I need to do to upgrade to 2.0?

tewfik-ghariani commented 3 years ago

@zaphar - I've looked around and I was able to use nixops 2.0 via a Hydra build ( or locally via poetry ) using this repo : https://github.com/tewfik-ghariani/my-nixops

Also, If I understood correctly, nixops-2.0 unstable was merged to nixpkgs master so there might be a way to fetch it from there and use it

rprije commented 2 years ago

I was able to workaround this by adding a bootstrap image resource with the resourceUri and make it work. @tewfik-ghariani , is there a description or writeup anywhere of what I need to do to upgrade to 2.0?

Can you please share your work around in detail?

Edit:

I figured it out. Here it is for anyone else trying to do the same. Add this to your network file:

  # Prevent this error:
  # A definition for option `sourceUri' is not of type `string'. Definition values:
  # - In `<unknown-file>':
  # {
  #   name = "nixos-image-20-09-3531-3858fbc08e6-x86-64-linux";
  #   project = "nixos-cloud";
  # }
  resources.gceImages.bootstrap = credentials // {
    name = "bootstrap";
    description = "Override bootstrap since the images in nixpkgs are now in a format incompatible with NixOps 1.7";
    sourceUri = "gs://nixos-cloud-images/nixos-image-21.03.git.6bf223c82e0-x86_64-linux.raw.tar.gz";
  };