nix-community / terraform-nixos

A set of Terraform modules that are designed to deploy NixOS [maintainer=@adrian-gierakowski]
Apache License 2.0
333 stars 61 forks source link

deploy_nixos: flake deployment doesn't work in a sub-folder #60

Open zimbatm opened 3 years ago

zimbatm commented 3 years ago

I just hit an issue where this doesn't work if the flake is in a sub-folder of the repo. Because it tries to instantiate from ./. and that doesn't contain the .git folder.

Originally posted by @zimbatm in https://github.com/tweag/terraform-nixos/issues/57#issuecomment-915105905

zimbatm commented 3 years ago

Error message:

error: Cannot deploy from an unclean source tree!

The issue comes from this snippet:

'nix-instantiate' '--show-trace' '--expr' $'\n  { system, configuration, hermetic ? false, flake ? false, ... }:\n  let\n    importFromFlake = { nixosConfig }:\n        let\n          flake = (import (\n                    fetchTarball {\n                      url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";\n                      sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }\n                  ) {\n                    src =  ./.;\n                  }).defaultNix;\n        in\n          builtins.getAttr nixosConfig flake.nixosConfigurations;\n    os =\n      if flake\n         then importFromFlake { nixosConfig = configuration; }\n         else if hermetic\n          then import configuration\n          else import <nixpkgs/nixos> { inherit system configuration; };\n  in {\n    inherit (builtins) currentSystem;\n\n    substituters =\n      builtins.concatStringsSep " " os.config.nix.binaryCaches;\n\n    trusted-public-keys =\n      builtins.concatStringsSep " " os.config.nix.binaryCachePublicKeys;\n\n    drv_path = os.config.system.build.toplevel.drvPath;\n    out_path = os.config.system.build.toplevel;\n  }' '--argstr' 'configuration' 'bastion' '--arg' 'flake' 'true' '--argstr' 'system' 'x86_64-linux' '--arg' 'hermetic' 'false' -A out_path