diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index c4897dac4..ad07381dd 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -1113,6 +1113,7 @@ Section "Install" File /nonfatal /r __INDEX_CACHE__ File /r __REPODATA_RECORD__ + @EXTRA_ENV_VARIABLES@ System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_SAFETY_CHECKS", "disabled").r0' System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_EXTRA_SAFETY_CHECKS", "no").r0' System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_PKGS_DIRS", "$INSTDIR\pkgs")".r0' diff --git a/constructor/winexe.py b/constructor/winexe.py index 345378ce7..fcab7336f 100644 --- a/constructor/winexe.py +++ b/constructor/winexe.py @@ -86,6 +86,23 @@ def insert_tempfiles_commands(paths: os.PathLike) -> List[str]: lines.append(f"File {path}") return lines +def setup_extra_env_variables(info) -> List[str]: + """Helper function to insert extra environment variables into nsis template. + + Args: + info: Dictionary of information parsed from construct.yaml + + Returns: + List[str]: Commands to be inserted into nsi template + """ + lines = [] + for variable in info.get('extra_env_variables',[]): + split = variable.split('=') + if len(split)==2: + (name, val) = split + lines.append(f"""System::Call 'kernel32::SetEnvironmentVariable(t,t)i("{name}", "{val}").r0'""") + + return lines def custom_nsi_insert_from_file(filepath: os.PathLike) -> str: """Insert NSI script commands from file. @@ -332,6 +349,7 @@ def make_nsi(info, dir_path, extra_files=None, temp_extra_files=None): '${NAME} ${VERSION} (Python ${PYVERSION} ${ARCH})' )), ('@EXTRA_FILES@', '\n '.join(extra_files_commands(extra_files, dir_path))), + ('@EXTRA_ENV_VARIABLES@', '\n '.join(setup_extra_env_variables(info))), ( '@CUSTOM_WELCOME_FILE@', custom_nsi_insert_from_file(info.get('welcome_file', '')) diff --git a/examples/scripts/post_install.bat b/examples/scripts/post_install.bat index 6b80f986a..a4113f8c7 100644 --- a/examples/scripts/post_install.bat +++ b/examples/scripts/post_install.bat @@ -4,4 +4,6 @@ if not "%INSTALLER_VER%" == "X" exit 1 if not "%INSTALLER_PLAT%" == "win-64" exit 1 if not "%INSTALLER_TYPE%" == "EXE" exit 1 if "%PREFIX%" == "" exit 1 +if not "%CUSTOM_VARIABLE_1%" == "CUSTOM1" exit 1 +if not "%CUSTOM_VARIABLE_2%" == "CUSTOM2" exit 1 if not exist "%PREFIX%\pre_install_sentinel.txt" exit 1 diff --git a/examples/scripts/pre_install.bat b/examples/scripts/pre_install.bat index d1bd0598a..27b788685 100644 --- a/examples/scripts/pre_install.bat +++ b/examples/scripts/pre_install.bat @@ -3,4 +3,6 @@ if not "%INSTALLER_VER%" == "X" exit 1 if not "%INSTALLER_PLAT%" == "win-64" exit 1 if not "%INSTALLER_TYPE%" == "EXE" exit 1 if "%PREFIX%" == "" exit 1 +if not "%CUSTOM_VARIABLE_1%" == "CUSTOM1" exit 1 +if not "%CUSTOM_VARIABLE_2%" == "CUSTOM2" exit 1 echo Added by pre-install script > "%PREFIX%\pre_install_sentinel.txt"