From 1512268b1e0ebddcf47e150eba0b06a7d80cc0a0 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Wed, 5 Jan 2022 10:39:25 +0100 Subject: [PATCH 1/5] devenv: Factor out a function to get the Nix version. --- dev-env/lib/dade-dump-profile | 48 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/dev-env/lib/dade-dump-profile b/dev-env/lib/dade-dump-profile index 18d95a2da4b9..7d3291ccce96 100755 --- a/dev-env/lib/dade-dump-profile +++ b/dev-env/lib/dade-dump-profile @@ -20,34 +20,42 @@ unset NIX_PATH set -Eeuo pipefail if [[ -n "${DADE_DEBUG+x}" ]]; then - set -x + set -x fi errcho() { - >&2 echo "[dev-env] $*" + >&2 echo "[dev-env] $*" +} + +get_nix_version() { + local current + current="$(nix-env --version)" + if [[ "$current" =~ ([0-9])[.]([0-9]+)([.]([0-9]+))?$ ]]; then + echo "${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[4]:-0}" + else + errcho "WARNING: Unexpected output of 'nix-env --version' ($current), dev-env might not work properly." + return 1 + fi } check_nix_version() { - # Keep in sync with dade-nix-install. - NIX_MAJOR="$1" - NIX_MINOR="$2" - NIX_PATCH="$3" - local current - current=$(nix-env --version) - if [[ $current =~ ([0-9])[.]([0-9]+)([.]([0-9]+))? ]]; then - local current_major="${BASH_REMATCH[1]}" - local current_minor="${BASH_REMATCH[2]}" - local current_patch="${BASH_REMATCH[4]:-0}" - if [[ $current_major -lt $NIX_MAJOR ]] || - [[ $current_major -eq $NIX_MAJOR && $current_minor -lt $NIX_MINOR ]] || - [[ $current_major -eq $NIX_MAJOR && $current_minor -eq $NIX_MINOR && $current_patch -lt $NIX_PATCH ]]; + # Keep in sync with dade-nix-install. + NIX_MAJOR="$1" + NIX_MINOR="$2" + NIX_PATCH="$3" + if current="$(get_nix_version)"; then + [[ "$current" =~ ([0-9])[.]([0-9]+)[.]([0-9]+)$ ]] + local current_major="${BASH_REMATCH[1]}" + local current_minor="${BASH_REMATCH[2]}" + local current_patch="${BASH_REMATCH[3]}" + if [[ $current_major -lt $NIX_MAJOR ]] || + [[ $current_major -eq $NIX_MAJOR && $current_minor -lt $NIX_MINOR ]] || + [[ $current_major -eq $NIX_MAJOR && $current_minor -eq $NIX_MINOR && $current_patch -lt $NIX_PATCH ]]; then - errcho "WARNING: Version ${current_major}.${current_minor}.${current_patch} detected, but ${NIX_MAJOR}.${NIX_MINOR}.${NIX_PATCH} or higher required." - errcho "Please run 'nix upgrade-nix' or 'curl -sSfL https://nixos.org/nix/install | sh' to update Nix." - fi - else - errcho "WARNING: Unexpected output of 'nix-env --version' ($current), dev-env might not work properly. Contact #disc-enterprise-pipe immediately!" + errcho "WARNING: Version ${current_major}.${current_minor}.${current_patch} detected, but ${NIX_MAJOR}.${NIX_MINOR}.${NIX_PATCH} or higher required." + errcho "Please run 'nix upgrade-nix' or 'curl -sSfL https://nixos.org/nix/install | sh' to update Nix." fi + fi } # TODO(gleber): Compatibility mode until JBH is ugraded. From 4ca849e81dd551393c55bdbfeaa56142c4d24dc0 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Wed, 5 Jan 2022 10:46:24 +0100 Subject: [PATCH 2/5] devenv: On newer versions of Nix, use `NIX_USER_CONF_FILES`. This stacks, rather than overwrites. --- dev-env/lib/dade-dump-profile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dev-env/lib/dade-dump-profile b/dev-env/lib/dade-dump-profile index 7d3291ccce96..509d3baa69cc 100755 --- a/dev-env/lib/dade-dump-profile +++ b/dev-env/lib/dade-dump-profile @@ -104,10 +104,15 @@ source "$(dirname "${BASH_SOURCE[0]}")/ensure-nix" ) # Make sure nix gets ensured in main shell -echo source "$(dirname "${BASH_SOURCE[0]}")/ensure-nix" +echo "source $(dirname "${BASH_SOURCE[0]}")/ensure-nix" # Expose our tools in /dev-env/bin and our version of nixpkgs -echo "export NIX_CONF_DIR=\"${DADE_DEVENV_DIR}/etc\"" +if [[ "$("${DADE_DEVENV_DIR}/bin/semver" compare "$(get_nix_version)" '2.4.0')" -ge 0 ]]; then + echo "export NIX_USER_CONF_FILES=\"${DADE_DEVENV_DIR}/etc/nix.conf:\${NIX_USER_CONF_FILES}:\${XDG_CONFIG_HOME:-\${HOME}/.config}/nix/nix.conf\"" +else + # On an old version of Nix, overwrite the system config, as we can't support multiple config files. + echo "export NIX_CONF_DIR=\"${DADE_DEVENV_DIR}/etc\"" +fi echo "export NIX_PATH=nixpkgs=\"${DADE_NIXPKGS}\"" echo "export PATH=\"${DADE_DEVENV_DIR}/bin:\$PATH\"" echo "export PYTHONPATH=\".\${PYTHONPATH:+:\$PYTHONPATH}\"" From 840fb729b28626196126b64c1e90bed75cafa269 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Wed, 5 Jan 2022 10:48:32 +0100 Subject: [PATCH 3/5] devenv: Append Nix caches, instead of overwriting them. The "extra-" prefix tells Nix to append. We also switch to non-deprecated configuration keys. CHANGELOG_BEGIN CHANGELOG_END --- dev-env/etc/nix.conf | 7 ++++--- infra/vsts_agent_ubuntu_20_04_startup.sh | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dev-env/etc/nix.conf b/dev-env/etc/nix.conf index 680cf56bb128..28574a3dbbd2 100644 --- a/dev-env/etc/nix.conf +++ b/dev-env/etc/nix.conf @@ -1,10 +1,11 @@ build-max-jobs = 2 -binary-caches = https://nix-cache.da-ext.net https://cache.nixos.org + +extra-substituters = https://nix-cache.da-ext.net # Note: the "hydra.da-int.net" string is now part of the name of the key for # legacy reasons; it bears no relation to the DNS hostname of the current # cache. -# If you change this, you also need to update the config in infra/vsts_agent_linux_startup.sh. -binary-cache-public-keys = hydra.da-int.net-2:91tXuJGf/ExbAz7IWsMsxQ5FsO6lG/EGM5QVt+xhZu0= hydra.da-int.net-1:6Oy2+KYvI7xkAOg0gJisD7Nz/6m8CmyKMbWfSKUe03g= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs= +# If you change this, you also need to update the config in infra/vsts_agent_ubuntu_20_04_startup.sh. +extra-trusted-public-keys = hydra.da-int.net-2:91tXuJGf/ExbAz7IWsMsxQ5FsO6lG/EGM5QVt+xhZu0= hydra.da-int.net-1:6Oy2+KYvI7xkAOg0gJisD7Nz/6m8CmyKMbWfSKUe03g= # Keep build-time dependencies of non-garbage outputs around gc-keep-outputs = true diff --git a/infra/vsts_agent_ubuntu_20_04_startup.sh b/infra/vsts_agent_ubuntu_20_04_startup.sh index bc2410f4e9b6..dbfb59295892 100644 --- a/infra/vsts_agent_ubuntu_20_04_startup.sh +++ b/infra/vsts_agent_ubuntu_20_04_startup.sh @@ -199,8 +199,8 @@ rm /etc/sudoers.d/nix_installation # legacy reasons; it bears no relation to the DNS hostname of the current # cache. cat < /etc/nix/nix.conf -binary-cache-public-keys = hydra.da-int.net-2:91tXuJGf/ExbAz7IWsMsxQ5FsO6lG/EGM5QVt+xhZu0= hydra.da-int.net-1:6Oy2+KYvI7xkAOg0gJisD7Nz/6m8CmyKMbWfSKUe03g= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs= -binary-caches = https://nix-cache.da-ext.net https://cache.nixos.org +extra-substituters = https://nix-cache.da-ext.net +extra-trusted-public-keys = hydra.da-int.net-2:91tXuJGf/ExbAz7IWsMsxQ5FsO6lG/EGM5QVt+xhZu0= hydra.da-int.net-1:6Oy2+KYvI7xkAOg0gJisD7Nz/6m8CmyKMbWfSKUe03g= build-users-group = nixbld cores = 1 max-jobs = 0 From ed442fa8ae8228369cffed85dad40db8157dfe71 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Wed, 5 Jan 2022 11:21:00 +0100 Subject: [PATCH 4/5] devenv: Just require Nix v2.4 or newer. --- dev-env/lib/dade-dump-profile | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/dev-env/lib/dade-dump-profile b/dev-env/lib/dade-dump-profile index 509d3baa69cc..72f7909f23c9 100755 --- a/dev-env/lib/dade-dump-profile +++ b/dev-env/lib/dade-dump-profile @@ -27,27 +27,17 @@ errcho() { >&2 echo "[dev-env] $*" } -get_nix_version() { - local current - current="$(nix-env --version)" - if [[ "$current" =~ ([0-9])[.]([0-9]+)([.]([0-9]+))?$ ]]; then - echo "${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[4]:-0}" - else - errcho "WARNING: Unexpected output of 'nix-env --version' ($current), dev-env might not work properly." - return 1 - fi -} - check_nix_version() { # Keep in sync with dade-nix-install. NIX_MAJOR="$1" NIX_MINOR="$2" NIX_PATCH="$3" - if current="$(get_nix_version)"; then - [[ "$current" =~ ([0-9])[.]([0-9]+)[.]([0-9]+)$ ]] + local current + current=$(nix-env --version) + if [[ $current =~ ([0-9])[.]([0-9]+)([.]([0-9]+))? ]]; then local current_major="${BASH_REMATCH[1]}" local current_minor="${BASH_REMATCH[2]}" - local current_patch="${BASH_REMATCH[3]}" + local current_patch="${BASH_REMATCH[4]:-0}" if [[ $current_major -lt $NIX_MAJOR ]] || [[ $current_major -eq $NIX_MAJOR && $current_minor -lt $NIX_MINOR ]] || [[ $current_major -eq $NIX_MAJOR && $current_minor -eq $NIX_MINOR && $current_patch -lt $NIX_PATCH ]]; @@ -55,6 +45,8 @@ check_nix_version() { errcho "WARNING: Version ${current_major}.${current_minor}.${current_patch} detected, but ${NIX_MAJOR}.${NIX_MINOR}.${NIX_PATCH} or higher required." errcho "Please run 'nix upgrade-nix' or 'curl -sSfL https://nixos.org/nix/install | sh' to update Nix." fi + else + errcho "WARNING: Unexpected output of 'nix-env --version' ($current), dev-env might not work properly." fi } @@ -79,7 +71,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/ensure-nix" # shellcheck source=./ensure-nix source "$(dirname "${BASH_SOURCE[0]}")/ensure-nix" - : "${DADE_DESIRED_NIX_VERSION:=2 1 3}" + : "${DADE_DESIRED_NIX_VERSION:=2 4 0}" check_nix_version $DADE_DESIRED_NIX_VERSION # If the user has no channels configured, then NIX_PATH might point @@ -107,12 +99,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/ensure-nix" echo "source $(dirname "${BASH_SOURCE[0]}")/ensure-nix" # Expose our tools in /dev-env/bin and our version of nixpkgs -if [[ "$("${DADE_DEVENV_DIR}/bin/semver" compare "$(get_nix_version)" '2.4.0')" -ge 0 ]]; then - echo "export NIX_USER_CONF_FILES=\"${DADE_DEVENV_DIR}/etc/nix.conf:\${NIX_USER_CONF_FILES}:\${XDG_CONFIG_HOME:-\${HOME}/.config}/nix/nix.conf\"" -else - # On an old version of Nix, overwrite the system config, as we can't support multiple config files. - echo "export NIX_CONF_DIR=\"${DADE_DEVENV_DIR}/etc\"" -fi +echo "export NIX_USER_CONF_FILES=\"${DADE_DEVENV_DIR}/etc/nix.conf:\${NIX_USER_CONF_FILES}:\${XDG_CONFIG_HOME:-\${HOME}/.config}/nix/nix.conf\"" echo "export NIX_PATH=nixpkgs=\"${DADE_NIXPKGS}\"" echo "export PATH=\"${DADE_DEVENV_DIR}/bin:\$PATH\"" echo "export PYTHONPATH=\".\${PYTHONPATH:+:\$PYTHONPATH}\"" From 5de0616b81cdd37c7e4ed36461556f58f5d6aedd Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Wed, 5 Jan 2022 11:23:09 +0100 Subject: [PATCH 5/5] devenv: `NIX_USER_CONF_FILES` may not be set already. --- dev-env/lib/dade-dump-profile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-env/lib/dade-dump-profile b/dev-env/lib/dade-dump-profile index 72f7909f23c9..01408c09f9ec 100755 --- a/dev-env/lib/dade-dump-profile +++ b/dev-env/lib/dade-dump-profile @@ -99,7 +99,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/ensure-nix" echo "source $(dirname "${BASH_SOURCE[0]}")/ensure-nix" # Expose our tools in /dev-env/bin and our version of nixpkgs -echo "export NIX_USER_CONF_FILES=\"${DADE_DEVENV_DIR}/etc/nix.conf:\${NIX_USER_CONF_FILES}:\${XDG_CONFIG_HOME:-\${HOME}/.config}/nix/nix.conf\"" +echo "export NIX_USER_CONF_FILES=\"${DADE_DEVENV_DIR}/etc/nix.conf:\${NIX_USER_CONF_FILES:-}:\${XDG_CONFIG_HOME:-\${HOME}/.config}/nix/nix.conf\"" echo "export NIX_PATH=nixpkgs=\"${DADE_NIXPKGS}\"" echo "export PATH=\"${DADE_DEVENV_DIR}/bin:\$PATH\"" echo "export PYTHONPATH=\".\${PYTHONPATH:+:\$PYTHONPATH}\""