How can I override the jetbrains jdk dependency required by idea-ultimate or idea-community in config.nix? - intellij-idea

I’ve been setting up my local nix config as per nixpkgs manual's declarative package management.
I’d like to include idea-ultimate as one of myPackages, but at this time the dependency idea has on the jetbrains jdk is broken, pointing to a non-existing package for macOS.
It’s trying to download jbrsdk-11_0_2-osx-x64-b485.1.tar.gz instead of jbrsdk-11_0_4-osx-x64-b485.1.tar.gz.
I was assuming I could fix that by overriding jetbrainsjdk as follows, but I’m getting: error: attribute 'jetbrainsjdk' missing, at /Users/ldeck/.config/nixpkgs/config.nix:4:20 when I do anything like nix-env -qa ‘jetbrains.*’.
What is the right way to override idea-ultimate so that it uses the fixed jdk?
Here’s my ~./config/nixpkgs/config.nix.
{
allowUnfree = true;
packageOverrides = pkgs: rec {
jetbrainsjdk = pkgs.jetbrainsjdk.override {
version = "520.11";
src = pkgs.fetchurl {
url = "https://bintray.com/jetbrains/intellij-jdk/download_file?file_path=jbrsdk-11_0_4-osx-x64-b${jetbrainsjdk.version}.tar.gz";
sha256 = "0d1qwbssc8ih62rlfxxxcn8i65cjgycdfy1dc1b902j46dqjkq9z";
};
};
myProfile = pkgs.writeText "my-profile" ''
export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man
'';
myPackages = with pkgs; buildEnv {
name = "my-packages";
paths = [
(runCommand "profile" {} ''
mkdir -p $out/etc/profile.d
cp ${myProfile} $out/etc/profile.d/my-profile.sh
'')
aspell
bc
coreutils
direnv
emacs
emscripten
ffmpeg
gdb
git
hello
jq
nixops
nox
scala
silver-searcher
];
pathsToLink = [ "/share/man" "/share/doc" "/bin" "/etc" "/Applications" ];
extraOutputsToInstall = [ "man" "doc" ];
};
};
}
UPDATE 1
Thanks to #ChrisStryczynski who suggested I needed with pkgs, I’ve gotten a little further.
But now the problem is when attempting to install idea-ultimate with the custom jdk, it’s still requiring the broken, non-existing, jbrsdk-11_02-osx-x64-b485.1.tar.gz.drv from somewhere.
Updated config and logs below.
{
allowUnfree = true;
packageOverrides = pkgs: **with pkgs;** rec {
myJetbrainsJdk = **pkgs.jetbrains.jdk.overrideAttrs** (oldAttrs: rec {
version = "520.11";
src = pkgs.fetchurl {
url = "https://bintray.com/jetbrains/intellij-jdk/download_file?file_path=jbrsdk-11_0_4-osx-x64-b520.11.tar.gz";
sha256 = "0d1qwbssc8ih62rlfxxxcn8i65cjgycdfy1dc1b902j46dqjkq9z";
};
});
myIdeaUltimate = pkgs.jetbrains.idea-ultimate.override {
jdk = myJetbrainsJdk;
};
...
myPackages = with pkgs; buildEnv {
...
myIdeaUltimate
];
...
};
};
}
Logs
nix-channel --update; nix-env -iA nixpkgs.myPackages
unpacking channels...
replacing old 'my-packages'
installing 'my-packages'
these derivations will be built:
/nix/store/9kfi3k9q6hi7z3lwann318hndbah535v-idea-ultimate.desktop.drv
/nix/store/ica1m5yq3f3y05xnw7ln1lnfvp0yjvyf-download_file?file_path=jbrsdk-11_0_4-osx-x64-b520.11.tar.gz.drv
/nix/store/bf2hwhrvfl8g77gdiw053rayh06x0120-jetbrainsjdk-520.11.drv
/nix/store/fazsa1a4l70s391rjk9yyi2hvrg0zbmp-download_file?file_path=jbrsdk-11_0_2-osx-x64-b485.1.tar.gz.drv
/nix/store/fwwk976sd278zb68zy9wm5pkxss0rnhg-jetbrainsjdk-485.1.drv
/nix/store/s3m2bpcyrnx9dcq4drh95882n0mk1d6m-ideaIU-2019.2.4-no-jbr.tar.gz.drv
/nix/store/9kiajpmmsp3i6ysj4vdqq8dzi84mnr73-idea-ultimate-2019.2.4.drv
/nix/store/jh1ixm54qinv8pk6kypvv6n6cfr4sws8-my-packages.drv
these paths will be fetched (0.02 MiB download, 0.12 MiB unpacked):
/nix/store/hp90sbwznq1msv327f0lb27imvcvi80h-libnotify-0.7.8
building '/nix/store/9kfi3k9q6hi7z3lwann318hndbah535v-idea-ultimate.desktop.drv'...
copying path '/nix/store/hp90sbwznq1msv327f0lb27imvcvi80h-libnotify-0.7.8' from 'https://cache.nixos.org'...
building '/nix/store/fazsa1a4l70s391rjk9yyi2hvrg0zbmp-download_file?file_path=jbrsdk-11_0_2-osx-x64-b485.1.tar.gz.drv'...
trying https://bintray.com/jetbrains/intellij-jdk/download_file?file_path=jbrsdk-11_0_2-osx-x64-b485.1.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (22) The requested URL returned error: 404 Not Found
error: cannot download download_file?file_path=jbrsdk-11_0_2-osx-x64-b485.1.tar.gz from any mirror
builder for '/nix/store/fazsa1a4l70s391rjk9yyi2hvrg0zbmp-download_file?file_path=jbrsdk-11_0_2-osx-x64-b485.1.tar.gz.drv' failed with exit code 1
building '/nix/store/ica1m5yq3f3y05xnw7ln1lnfvp0yjvyf-download_file?file_path=jbrsdk-11_0_4-osx-x64-b520.11.tar.gz.drv'...
cannot build derivation '/nix/store/fwwk976sd278zb68zy9wm5pkxss0rnhg-jetbrainsjdk-485.1.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/9kiajpmmsp3i6ysj4vdqq8dzi84mnr73-idea-ultimate-2019.2.4.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/jh1ixm54qinv8pk6kypvv6n6cfr4sws8-my-packages.drv': 1 dependencies couldn't be built
error: build of '/nix/store/jh1ixm54qinv8pk6kypvv6n6cfr4sws8-my-packages.drv' failed

Thanks to How do you discover the override attributes for a derivation, a solution has been found using an overlay.
# ~/config/nixpkgs/overlays/02-jetbrains.nix
self: super:
{
jetbrains = super.jetbrains // {
jdk = super.jetbrains.jdk.overrideAttrs (oldAttrs: rec {
version = "520.11";
src = super.fetchurl {
url = "https://bintray.com/jetbrains/intellij-jbr/download_file?file_path=jbrsdk-11_0_4-osx-x64-b520.11.tar.gz";
sha256 = "3fe1297133440a9056602d78d7987f9215139165bd7747b3303022a6f5e23834";
};
passthru = oldAttrs.passthru // {
home = "${self.jetbrains.jdk}/Contents/Home";
};
});
idea-ultimate = super.jetbrains.idea-ultimate.overrideAttrs (_: {
name = "idea-ultimate.2019.2.4";
src = super.fetchurl {
url = "https://download.jetbrains.com/idea/ideaIU-2019.2.4-no-jbr.tar.gz";
sha256 = "09mz4dx3zbnqw0vh4iqr8sn2s8mvgr7zvn4k7kqivsiv8f79g90a";
};
});
};
}
Install: nix-env -iA 'nixpkgs.jetbrains.idea-ultimate'.
Execute: idea-ultimate.
The crucial part of the puzzle was overriding the passthru.home variable to point to the overlayed JDK rather than the one required by super. Otherwise, you’ll be downloading the old JDK for runtime purposes.
passthru = oldAttrs.passthru // {
home = "${self.jetbrains.jdk}/Contents/Home”;
};
Without /Contents/Home appended, idea won’t startup since self.jetbrains.jdk isn’t a valid home.

Instead of:
nix-env -iA nixpkgs.myPackages
Just do:
nix-env -iA nixpkgs.myIdeaUltimate
The problem being:
myPackages = with pkgs; buildEnv {
...
myIdeaUltimate
];
...
};
Here you are still referencing the old pkgs.myIdeaUltimate.
Nixos seems to do some processing that replaces the pkgs with the appropriate from packageOverrides.

Related

How do I force rebuild of all snapshot dependencies in my teamcity build trigger?

I have a list of build types in my settings.kts:
val buildChain = listOf(build1, build2, build3, ...)
I define the following chain of snapshot dependencies:
for ((previous, current) in buildChain.zip(buildChain.drop(1))) {
current.dependencies {
snapshot(previous) {
reuseBuilds = ReuseBuilds.NO
onDependencyFailure = FailureAction.FAIL_TO_START
onDependencyCancel = FailureAction.FAIL_TO_START
}
}
}
With that, build<N> depends on build<N-1>. Then I define the following build type that runs the whole build chain:
val buildChainRunner = BuildChainRunner(headOfBuildChain = buildChain.last())
where
class BuildChainRunner(
headOfBuildChain: BuildType,
) : BuildType({
name = "Build Chain Runner"
dependencies {
snapshot(headOfBuildChain) {
reuseBuilds = ReuseBuilds.NO
onDependencyFailure = FailureAction.ADD_PROBLEM
onDependencyCancel = FailureAction.ADD_PROBLEM
}
}
triggers {
schedule {
schedulingPolicy = daily {
hour = 2
minute = 0
timezone = "Europe/Amsterdam"
}
branchFilter = "+:<default>"
triggerBuild = always()
withPendingChangesOnly = false
}
}
[...]
}
Now, when the build gets triggered by the schedule trigger, it doesn't necessarily rebuilds all builds from the chain. What I would like to do is the very same as this:
I thought that would be automatically the case because of
reuseBuilds = ReuseBuilds.NO
but unfortunately, it doesn't work. When I trigger the build manually and set "rebuild snapshot dependencies" to "all", then it works as I expect. What am I doing wrong in my kotlin DSL configuration?

Build a CMake project with Nix

I'm trying to make a derivation from fokus (a KDE plasmoid).
I have a default.nix which looks like:
{ mkDerivation, lib, fetchFromGitLab, cmake, extra-cmake-modules
, plasma-framework
, qt5 }:
let
version = "1.5.4";
repo = fetchFromGitLab {
owner = "divinae";
repo = "focus-plasmoid";
rev = "v${version}";
sha256 = "19nndmqfzdcg7lzcifxa17m2mx85dlf4m2wxzr72gf78h4yj0ahv";
};
in
mkDerivation rec {
inherit version;
pname = "fokus";
src = "${repo}/packages";
dontUnpack = true;
buildInputs = [
plasma-framework
qt5.qtbase
];
nativeBuildInputs = [ cmake extra-cmake-modules ];
meta = with lib; {
description = "Simple pomodoro timer plasmoid";
homepage = "https://store.kde.org/p/1308861/";
license = licenses.gpl3Only;
maintainers = with maintainers; [ ];
platforms = platforms.unix;
};
}
I also added to all-packages:
fokus-plasma-applet = libsForQt5.callPackage ../applications/misc/fokus-plasma-applet { };
The thing is, I have only find few examples in nixpkgs, and I do not see what to do with this error (since CMakeLists.txt is effectively in /package):
building '/nix/store/c21h5667abmj4v0ci4n51ckvkxvc23gk-fokus-1.5.4.drv'...
qtPreHook
patching sources
configuring
fixing cmake files...
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/doc/fokus -DCMAKE_INSTALL_INFODIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/include -DCMAKE_INSTALL_SBINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/4g5fidyk19akng9n91cql60ylrjq93s6-gcc-wrapper-10.3.0/bin/strip -DCMAKE_RANLIB=/nix/store/ffcrrgb6k5h7crr93dj90bi9fy1jvj16-binutils-2.35.1/bin/ranlib -DCMAKE_AR=/nix/store/ffcrrgb6k5h7crr93dj90bi9fy1jvj16-binutils-2.35.1/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4 -DKDE_INSTALL_EXECROOTDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4 -DKDE_INSTALL_BINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/bin -DKDE_INSTALL_SBINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/sbin -DKDE_INSTALL_LIBDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib -DKDE_INSTALL_LIBEXECDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/libexec -DKDE_INSTALL_CMAKEPACKAGEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/cmake -DKDE_INSTALL_INCLUDEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/include -DKDE_INSTALL_LOCALSTATEDIR=/var -DKDE_INSTALL_DATAROOTDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share -DKDE_INSTALL_DATADIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share -DKDE_INSTALL_DOCBUNDLEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/doc/HTML -DKDE_INSTALL_KCFGDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/config.kcfg -DKDE_INSTALL_KCONFUPDATEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kconf_update -DKDE_INSTALL_KSERVICES5DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kservices5 -DKDE_INSTALL_KSERVICETYPES5DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kservicetypes5 -DKDE_INSTALL_KXMLGUI5DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kxmlgui5 -DKDE_INSTALL_KNOTIFY5RCDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/knotifications5 -DKDE_INSTALL_ICONDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/icons -DKDE_INSTALL_LOCALEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/locale -DKDE_INSTALL_SOUNDDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/sounds -DKDE_INSTALL_TEMPLATEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/templates -DKDE_INSTALL_WALLPAPERDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/wallpapers -DKDE_INSTALL_APPDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/applications -DKDE_INSTALL_DESKTOPDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/desktop-directories -DKDE_INSTALL_MIMEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/mime/packages -DKDE_INSTALL_METAINFODIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/appdata -DKDE_INSTALL_MANDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/man -DKDE_INSTALL_INFODIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/info -DKDE_INSTALL_DBUSDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1 -DKDE_INSTALL_DBUSINTERFACEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1/interfaces -DKDE_INSTALL_DBUSSERVICEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1/services -DKDE_INSTALL_DBUSSYSTEMSERVICEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1/system-services -DKDE_INSTALL_SYSCONFDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/etc -DKDE_INSTALL_CONFDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/etc/xdg -DKDE_INSTALL_AUTOSTARTDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/etc/xdg/autostart -DKDE_INSTALL_QTPLUGINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/qt-5.15.2/plugins -DKDE_INSTALL_PLUGINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/qt-5.15.2/plugins -DKDE_INSTALL_QMLDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/qt-5.15.2/qml
CMake Error: The source directory "/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
builder for '/nix/store/c21h5667abmj4v0ci4n51ckvkxvc23gk-fokus-1.5.4.drv' failed with exit code 1
cannot build derivation '/nix/store/b9jhnh8bix892wql3qifvgf742lq41v9-system-path.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/3n3mwi7vqmnkng6r8kpa9881xdgcd253-nixos-system-looping-21.11pre328987.c935f5e0add.drv': 1 dependencies couldn't be built
error: build of '/nix/store/3n3mwi7vqmnkng6r8kpa9881xdgcd253-nixos-system-looping-21.11pre328987.c935f5e0add.drv' failed

VM creation using terraform in vsphere gives An error occurred while customizing VM

provider "vsphere" {
vsphere_server = "myserver"
user = "myuser"
password = "mypass"
allow_unverified_ssl = true
version = "v1.21.0"
}
data "vsphere_datacenter" "dc" {
name = "pcloud-datacenter"
}
data "vsphere_datastore_cluster" "datastore_cluster" {
name = "pc-storage"
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_compute_cluster" "compute_cluster" {
name = "pcloud-cluster"
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_network" "network" {
name = "u32c01p26-1514"
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_virtual_machine" "vm_template" {
name = "first-terraform-vm"
datacenter_id = data.vsphere_datacenter.dc.id
}
resource "vsphere_virtual_machine" "vm" {
count = 1
name = "first-terraform-vm-1"
resource_pool_id = data.vsphere_compute_cluster.compute_cluster.resource_pool_id
datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id
num_cpus = 2
memory = 1024
wait_for_guest_ip_timeout = 2
wait_for_guest_net_timeout = 0
guest_id = data.vsphere_virtual_machine.vm_template.guest_id
scsi_type = data.vsphere_virtual_machine.vm_template.scsi_type
network_interface {
network_id = data.vsphere_network.network.id
adapter_type = data.vsphere_virtual_machine.vm_template.network_interface_types[0]
}
disk {
name = "disk0.vmdk"
size = data.vsphere_virtual_machine.vm_template.disks.0.size
eagerly_scrub = data.vsphere_virtual_machine.vm_template.disks.0.eagerly_scrub
thin_provisioned = data.vsphere_virtual_machine.vm_template.disks.0.thin_provisioned
}
folder = "virtual-machines"
clone {
template_uuid = data.vsphere_virtual_machine.vm_template.id
customize {
linux_options {
host_name = "first-terraform-vm-1"
domain = "localhost.localdomain"
}
network_interface {
ipv4_address = "10.10.14.100"
ipv4_netmask = 24
}
ipv4_gateway = "10.10.14.1"
}
}
}
The command terraform script throws the below error
Error:
Virtual machine customization failed on "/pcloud-datacenter/vm/virtual-machines/first-terraform-vm-1":
An error occurred while customizing VM first-terraform-vm-1. For details reference the log file <No Log> in the guest OS.
The virtual machine has not been deleted to assist with troubleshooting. If
corrective steps are taken without modifying the "customize" block of the
resource configuration, the resource will need to be tainted before trying
again. For more information on how to do this, see the following page:
https://www.terraform.io/docs/commands/taint.html
on create_vm.tf line 34, in resource "vsphere_virtual_machine" "vm":
34: resource "vsphere_virtual_machine" "vm" {
Some how the generated vm "first-terraform-vm-1" doesn't have the connected box checked-in in network settings. While i checked my template "first-terraform-vm" it has network connected box checked-in.
I see similar post in github https://github.com/hashicorp/terraform-provider-vsphere/issues/951
But not sure why this issue is still surfacing?
Vsphere version: 6.7
Terraform v0.12.28
provider.vsphere v1.21.0
Is there anything wrong with my template? Or am i missing something? Can anyone help please? Stuck with this for last 2 days.
The problem looks to be with the template that i have used. The linux template should have Network Manager installed and running. It looks like terraform uses the network manager to assign IPaddress for newly created vm.

Workaround for `count.index` in Terraform Module

I need a workaround for using count.index inside a module block for some input variables. I have a habit of over-complicating problems, so maybe there's a much easier solution.
File/Folder Structure:
modules/
main.tf
ignition/
main.tf
modules/
files/
main.tf
template_files/
main.tf
End Goal: Create an Ignition file for each instance I'm deploying. Each Ignition file has instance-specific info like hostname, IP address, etc.
All of this code works if I use a static value or a variable without cound.index. I need help coming up with a workaround for the address, gateway, and hostname variables specifically. If I need to process the count.index inside one of the child modules, that's totally fine. I can't seem to wrap my brain around that though. I've tried null_data_source and null_resource blocks from the child modules to achieve that, but so far no luck.
Variables:
workers = {
Lab1 = {
"lab1k8sc8r001" = "192.168.17.100/24"
}
Lab2 = {
"lab2k8sc8r001" = "192.168.18.100/24"
}
}
gateway = {
Lab1 = [
"192.168.17.1",
]
Lab2 = [
"192.168.18.1",
]
}
From modules/main.tf, I'm calling the ignition module:
module "ignition_workers" {
source = "./modules/ignition"
virtual_machines = var.workers[terraform.workspace]
ssh_public_keys = var.ssh_public_keys
files = [
"files_90-disable-auto-updates.yaml",
"files_90-disable-console-logs.yaml",
]
template_files = {
"files_eth0.nmconnection.yaml" = {
interface-name = "eth0",
address = element(values(var.workers[terraform.workspace]), count.index),
gateway = element(var.gateway, count.index % length(var.gateway)),
dns = join(";", var.dns_servers),
dns-search = var.domain,
}
"files_etc_hostname.yaml" = {
hostname = element(keys(var.workers[terraform.workspace]), count.index),
}
"files_chronyd.yaml" = {
ntp_server = var.ntp_server,
}
}
}
From modules/ignition/main.tf I take the files and template_files variables to build the Ignition config:
module "ingition_file_snippets" {
source = "./modules/files"
files = var.files
}
module "ingition_template_file_snippets" {
source = "./modules/template_files"
template_files = var.template_files
}
data "ct_config" "fedora-coreos-config" {
count = length(var.virtual_machines)
content = templatefile("${path.module}/assets/files_ssh_authorized_keys.yaml", {
ssh_public_keys = var.ssh_public_keys
})
pretty_print = true
snippets = setunion(values(module.ingition_file_snippets.files), values(module.ingition_template_file_snippets.files))
}
I am not quite sure what you are trying to achieve so I can not give any detailed examples.
But modules in terraform do not support count or for_each yet. So you can also not use count.index.
You might want to change your module to take lists/maps of input and create those lists/maps via for-expressions by transforming them from some input variables.
You can combine for with if to create a filtered subset of your source list/map. Like in:
[for s in var.list : upper(s) if s != ""]
I hope this helps you work around the missing count support.

Call fetchgit without SSL Verify

I'm trying to use fetchgit to download source repos from my lab's private GitLab server, which currently self-signs its SSL certificate.
default.nix:
with (import <nixpkgs> {});
{ test-pkg = callPackage ./test-pkg.nix {
buildPythonPackage = python35Packages.buildPythonPackage;
};
}
test-pkg.nix:
{ buildPythonPackage,fetchgit }:
buildPythonPackage rec {
pname = "test-pkg";
version = "0.2.1";
src = fetchgit {
url = "https://gitlabserver/experiment-deployment/test-pkg";
rev = "refs/tags/v${version}";
sha256 = "43c2c9e5e7a16b6c88ba3088a9bfc82f7db8e13378be7c78d6c14a5f8ed05afd";
};
}
Which results in the error when I call nix-shell
fatal: unable to access 'https://gitlabserver/experiment-deployment/test-pkg/': SSL certificate problem: self signed certificate
Looking at, build-support/fetchgit, it seems that fetchgit is made with mkDerivation, so I tried to make a new fetchgit using overrideAttrs. I pass in the git environment variable to make git ignore SSL verification, expecting that the variable will be initialized during the setup phase.
revised default.nix:
with (import <nixpkgs> {});
let fetchgit-no-verify = fetchgit.overrideAttrs { GIT_SSL_NO_VERIFY=true;} ;
in rec {
test-pkg = callPackage ./test-pkg.nix {
buildPythonPackage = python35Packages.buildPythonPackage;
fetchgit = fetchgit-no-verify;
};
}
I thought I was really clever when I thought of this over the weekend, only to discover that when implemented my new error states that
error: attribute 'overrideAttrs' missing, at [...]/default.nix:2:26
Inspecting fetchgit in nix repl shows that it is a functor attribute set. I tried for a little bit to get to the overrideAttrs, without success. Trying again I saw that git could be passed to to fetchGit,
re-revised default.nix:
with (import <nixpkgs> {});
let git = git.overrideAttrs { GIT_SSL_NO_VERIFY=true;} ;
fetchgit-no-verify = fetchgit.override { git=git-no-verify;} ;
in rec {
test-pkg = callPackage ./test-pkg.nix {
buildPythonPackage = python35Packages.buildPythonPackage;
fetchgit = fetchgit-no-verify;
};
}
but the new error:
error: attempt to call something which is not a function but a set, at /nix/store/jmynn33vcn3mcscsch0zf46fz9wsw05y-nixpkgs-20.03pre193309.c4196cca9ac/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:318:55
Finally, onto my questions. Is there a way to add the environment variable to the fetchgit or git derivations? Is there perhaps another way to connect--some builtin option I missed? I could use a private repository, using ssh and avoiding https, however due to how we deploy experiments I'd like to avoid that.
I was able to make this work with this ugly thing.
default.nix:
with (import <nixpkgs> {});
let fetchgit-no-verify = fetchgit // {
__functor = self : args :
(fetchgit.__functor self args).overrideAttrs (oldAttrs:{GIT_SSL_NO_VERIFY=true;});
} ;
in rec {
test-pkg = callPackage ./test-pkg.nix {
buildPythonPackage = python35Packages.buildPythonPackage;
fetchgit = fetchgit-no-verify;
};
}
fetchgit-no-verify uses the fetchgit functor set to begin with and overwrites the __functor attribute with a new function. The new functor just applies its arguments and then calls overrideAttrs.
This works, but I'm happy to award the answer to anybody who can add some insight or comes with another solution. For one, I'd like to know how the fetchgit derivation becomes a functor. Is this something callPackage does?.