Skip to content

Commit

Permalink
ci: upgrade Nix from 2.3.12 to 2.5.1
Browse files Browse the repository at this point in the history
Due to changes in how Nix handles Git refs we need to specify
`refs/tags/` prefix in `package.json` to avoid the following error:
```
fatal: couldn't find remote ref refs/heads/v2.0.3-status-v6
error: program 'git' failed with exit code 128
```

I also had to rewrite some logic in `nix/scripts/source.sh` in order to
take account of single-user and multi-user installations.

Resolves: #12832
Issue: NixOS/nix#5291

Signed-off-by: Jakub Sokołowski <[email protected]>
  • Loading branch information
jakubgs committed Jan 14, 2022
1 parent c2ce9c5 commit 54310cf
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 100 deletions.
4 changes: 2 additions & 2 deletions ci/Jenkinsfile.android
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library 'status-jenkins-lib@v1.3.3'
library 'status-jenkins-lib@fix/nix-profile'

pipeline {
agent { label 'linux && x86_64 && nix-2.3' }
agent { label 'linux && x86_64 && nix-2.5' }

options {
timestamps()
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.combined
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.3'
library 'status-jenkins-lib@fix/nix-profile'

pipeline {
agent { label 'linux' }
Expand Down
4 changes: 2 additions & 2 deletions ci/Jenkinsfile.ios
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library 'status-jenkins-lib@v1.3.3'
library 'status-jenkins-lib@fix/nix-profile'

pipeline {
agent { label 'macos && x86_64 && nix-2.3 && xcode-12.5' }
agent { label 'macos && x86_64 && nix-2.5 && xcode-12.5' }

parameters {
string(
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.nix-cache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.3'
library 'status-jenkins-lib@fix/nix-profile'

pipeline {
agent { label params.AGENT_LABEL }
Expand Down
2 changes: 1 addition & 1 deletion ci/tools/Jenkinsfile.fastlane-clean
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.3'
library 'status-jenkins-lib@fix/nix-profile'

pipeline {
agent { label 'macos' }
Expand Down
2 changes: 1 addition & 1 deletion ci/tools/Jenkinsfile.playstore-meta
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@v1.3.3'
library 'status-jenkins-lib@fix/nix-profile'

pipeline {
agent { label 'linux' }
Expand Down
6 changes: 3 additions & 3 deletions nix/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

# This script is a wrapper around nix-build with some niceties.
set -e

GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
Expand All @@ -8,7 +8,7 @@ source "${GIT_ROOT}/scripts/colors.sh"
source "${GIT_ROOT}/nix/scripts/source.sh"

# cleanup for artifacts created during builds
function cleanup() {
cleanup() {
# clear trapped signals
trap - EXIT ERR INT QUIT
# do the actual cleanup, ignore failure
Expand All @@ -29,7 +29,7 @@ if [[ -n "${_NIX_CLEAN}" ]]; then
fi

# build output will end up under /nix, we have to extract it
function extractResults() {
extractResults() {
local nixResultPath="$1"
mkdir -p "${resultPath}"
cp -vfr ${nixResultPath}/* "${resultPath}" | sed 's#'${PWD}'#.#'
Expand Down
18 changes: 9 additions & 9 deletions nix/scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ set -e
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/nix/scripts/source.sh"

function log() { echo "$@" 1>&2; }
log() { echo "$@" 1>&2; }

# helpers for getting related paths in Nix store
function getSources() { nix-store --query --binding src "${1}"; }
function getOutputs() { nix-store --query --outputs "${1}"; }
function getDrvFiles() { nix-store --query --deriver "${1}"; }
function getReferrers() { nix-store --query --referrers "${1}"; }
function getRoots() { nix-store --query --roots "${1}"; }
getSources() { nix-store --query --binding src "${1}"; }
getOutputs() { nix-store --query --outputs "${1}"; }
getDrvFiles() { nix-store --query --deriver "${1}"; }
getReferrers() { nix-store --query --referrers "${1}"; }
getRoots() { nix-store --query --roots "${1}"; }

function findRelated() {
findRelated() {
path="${1}"
found+=("${path}")
if [[ "${path}" =~ .*.chroot ]]; then
Expand Down Expand Up @@ -51,7 +51,7 @@ function findRelated() {
}

# used to find things to delete based on a regex
function findByRegex() {
findByRegex() {
regex="${1}"

log "Searching by regex: '${regex}'"
Expand All @@ -70,7 +70,7 @@ function findByRegex() {
}

# used to find things to delete based on a given path
function findByResult() {
findByResult() {
mainPath="${1}"
log "Searching by result: '${mainPath}'"

Expand Down
10 changes: 5 additions & 5 deletions nix/scripts/node_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ source "${GIT_ROOT}/scripts/colors.sh"
# More concise output from 'time'
export TIMEFORMAT="Done in: %Es"

function removeDir() {
removeDir() {
[[ ! -d "${tmp}" ]] && return
chmod -R u+w "${tmp}"
rm -rf "${tmp}"
}

function copyNodeModules() {
copyNodeModules() {
local src="${1}"
local dst="${2}"
# WARNING: The ../ is there to avoid a Nix builtins.path bug:
Expand All @@ -51,7 +51,7 @@ function copyNodeModules() {

# Find files that were modified and should cause a re-copying of node modules.
# Some files are generated/modified by build processes and should be ignored.
function findFilesNewerThan() {
findFilesNewerThan() {
local sentinel="${1}"
local dir="${2}"
find ${dir} -type f -writable \
Expand All @@ -63,7 +63,7 @@ function findFilesNewerThan() {
-print
}

function nodeModulesUnchanged() {
nodeModulesUnchanged() {
local src="$1"
local dst="$2"
local sentinelFile="${dst}/.copied~"
Expand Down Expand Up @@ -98,7 +98,7 @@ function nodeModulesUnchanged() {
return 0
}

function replaceNodeModules() {
replaceNodeModules() {
local src="$1"
local dst="$2"
local sentinelFile="${dst}/.copied~"
Expand Down
58 changes: 30 additions & 28 deletions nix/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
#!/usr/bin/env bash
# This script installs a specific version of Nix.
set -euo pipefail

GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/scripts/colors.sh"

NIX_VERSION="2.3.12"
NIX_VERSION="2.5.1"
NIX_INSTALL_URL="https://nixos.org/releases/nix/nix-${NIX_VERSION}/install"
NIX_INSTALL_SHA256="468a49a1cef293d59508bb3b62625dfcd99ec00334a14309f125cf8de513d5f1"
NIX_INSTALL_SHA256="e265dfd8e80223633a9726009b42c534ac3d5f2b6da5ad6432ca1f6ea88206d0"
NIX_INSTALL_PATH="/tmp/nix-install-${NIX_VERSION}"

function install_nix() {
# Don't break people's profiles
export NIX_INSTALLER_NO_MODIFY_PROFILE=1
# Fix for installing on MacOS Catalina
export NIX_IGNORE_SYMLINK_STORE=1
# Download installer and verify SHA256
curl -s "${NIX_INSTALL_URL}" -o "${NIX_INSTALL_PATH}"
echo "${NIX_INSTALL_SHA256} ${NIX_INSTALL_PATH}" | sha256sum -c
chmod +x "${NIX_INSTALL_PATH}"
# Run the installer
"${NIX_INSTALL_PATH}" --no-daemon
if [ $? -eq 0 ]; then
echo -e "${GRN}The Nix package manager was successfully installed.${RST}"
else
echo -e "${RED}Failed to install Nix package manager!${RST}" >&2
echo "Please see: https://nixos.org/nix/manual/#chap-installation" >&2
exit 1
fi
install_nix() {
# Don't break people's profiles
export NIX_INSTALLER_NO_MODIFY_PROFILE=1
# Fix for installing on MacOS Catalina
export NIX_IGNORE_SYMLINK_STORE=1
# Download installer and verify SHA256
curl -s "${NIX_INSTALL_URL}" -o "${NIX_INSTALL_PATH}"
echo "${NIX_INSTALL_SHA256} ${NIX_INSTALL_PATH}" | sha256sum -c
chmod +x "${NIX_INSTALL_PATH}"
# Run the installer
"${NIX_INSTALL_PATH}" --no-daemon
if [ $? -eq 0 ]; then
echo -e "${GRN}The Nix package manager was successfully installed.${RST}"
else
echo -e "${RED}Failed to install Nix package manager!${RST}" >&2
echo "Please see: https://nixos.org/nix/manual/#chap-installation" >&2
exit 1
fi
}

if [[ ! -x "$(command -v curl)" ]]; then
echo -e "${RED}The 'curl' utility is required for Nix installation.${RST}" >&2
exit 1
echo -e "${RED}The 'curl' utility is required for Nix installation.${RST}" >&2
exit 1
fi

if [[ "$(source /etc/os-release 2>/dev/null && echo "${NAME}")" == *NixOS* ]]; then
echo -e "${GRN}Already running NixOS.${RST}"
exit
echo -e "${GRN}Already running NixOS.${RST}"
exit
fi

if [[ -x "$(command -v nix)" ]]; then
echo -e "${GRN}Nix package manager already installed.${RST}"
exit
echo -e "${GRN}Nix package manager already installed.${RST}"
exit
fi

if [[ "${IN_NIX_SHELL}" == 'pure' ]]; then
echo -e "${GRN}Already in a pure Nix shell.${RST}"
exit
echo -e "${GRN}Already in a pure Nix shell.${RST}"
exit
fi

# If none of the checks before succeeded we need to install Nix
Expand Down
75 changes: 52 additions & 23 deletions nix/scripts/source.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,62 @@
#!/usr/bin/env bash

# This script makes sure we have Nix tools available
set -e

GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)

# Location of profile script for Nix that adjusts PATH
export NIX_PROFILE_SH="${HOME}/.nix-profile/etc/profile.d/nix.sh"

function source_nix() {
# Just stop if Nix is already available
if [[ -x $(command -v nix) ]]; then
return
elif [[ -f "${NIX_PROFILE_SH}" ]]; then
# Load Nix profile if it exists
source "${NIX_PROFILE_SH}"
return
else
file_group() {
UNAME=$(uname -s)
if [[ "${UNAME}" == "Linux" ]]; then
stat -Lc "%G" /nix
elif [[ "${UNAME}" == "Darwin" ]]; then
stat -Lf "%Sg" /nix
fi
}

nix_install_type() {
NIX_DIR_GROUP=$(file_group /nix)
if [[ "${NIX_DIR_GROUP}" == "nixbld" ]]; then
echo "multi"
elif [[ "${NIX_DIR_GROUP}" == "${USER}" ]]; then
echo "single"
elif [[ "${NIX_DIR_GROUP}" == "${USER}" ]]; then
echo "nixos"
else
echo "Unknown Nix installtion type!" >&2
exit 1
fi
}

source_nix_profile() {
NIX_INSTALL_TYPE=$(nix_install_type)
if [[ "${NIX_INSTALL_TYPE}" == "multi" ]]; then
source "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
elif [[ "${NIX_INSTALL_TYPE}" == "single" ]]; then
source "${HOME}/.nix-profile/etc/profile.d/nix.sh"
elif [[ "${NIX_INSTALL_TYPE}" == "nixops" ]]; then
echo "Sourcing profile not necessary on NixOS!" >&2
fi
}

main() {
# Just stop if Nix is already available
if [[ -x $(command -v nix) ]]; then
return
fi

# Setup Nix if not available
${GIT_ROOT}/nix/scripts/setup.sh
fi
if [[ ! -d /nix ]]; then
${GIT_ROOT}/nix/scripts/setup.sh
fi

# Load Nix profile
source "${NIX_PROFILE_SH}"
# Load Nix profile
source_nix_profile

# Verify Nix is available
if [[ ! -x $(command -v nix) ]]; then
echo "Nix not available, sourcing profile failed!" > /dev/stderr
exit 1
fi
# Verify Nix is available
if [[ ! -x $(command -v nix) ]]; then
echo "Nix not available, sourcing profile failed!" >&2
exit 1
fi
}

source_nix
main
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
"scripts": {
"start": "react-native start",
"ios": "react-native run-ios",
"app:android": "react-native run-android",
"app:compile:android": "shadow-cljs compile android",
"app:watch": "shadow-cljs watch android",
"app:packager": "react-native start --host 0.0.0.0 --port 8081",
"app:android": "react-native run-android"
"app:watch": "shadow-cljs watch android"
},
"dependencies": {
"@react-native-community/async-storage": "^1.11.0",
"@react-native-community/audio-toolkit": "git+https://github.com/tbenr/react-native-audio-toolkit.git#v2.0.3-status-v6",
"@react-native-community/cameraroll": "git+https://github.com/status-im/react-native-cameraroll.git#v4.0.4-status.0",
"@react-native-community/audio-toolkit": "git+https://github.com/tbenr/react-native-audio-toolkit.git#refs/tags/v2.0.3-status-v6",
"@react-native-community/cameraroll": "git+https://github.com/status-im/react-native-cameraroll.git#refs/tags/v4.0.4-status.0",
"@react-native-community/clipboard": "^1.2.2",
"@react-native-community/hooks": "^2.5.1",
"@react-native-community/masked-view": "^0.1.6",
"@react-native-community/netinfo": "^4.4.0",
"@react-native-community/push-notification-ios": "^1.4.1",
"@react-native-community/slider": "^3.0.0",
"bignumber.js": "git+https://github.com/status-im/bignumber.js.git#v4.0.2-status",
"bignumber.js": "git+https://github.com/status-im/bignumber.js.git#refs/tags/v4.0.2-status",
"buffer": "^5.4.2",
"chance": "^1.1.0",
"create-react-class": "^15.6.2",
Expand All @@ -35,7 +35,7 @@
"react-native": "0.63.4",
"react-native-background-timer": "^2.1.1",
"react-native-camera-kit": "^8.0.4",
"react-native-config": "git+https://github.com/status-im/react-native-config.git#v1.4.2-status",
"react-native-config": "git+https://github.com/status-im/react-native-config.git#refs/tags/v1.4.2-status",
"react-native-dark-mode": "^0.2.2",
"react-native-device-info": "^7.4.0",
"react-native-dialogs": "^1.0.4",
Expand All @@ -45,10 +45,10 @@
"react-native-fs": "^2.14.1",
"react-native-gesture-handler": "^1.8.0",
"react-native-haptic-feedback": "^1.9.0",
"react-native-image-crop-picker": "git+https://github.com/status-im/react-native-image-crop-picker.git#v0.36.2-status.0",
"react-native-image-crop-picker": "git+https://github.com/status-im/react-native-image-crop-picker.git#refs/tags/v0.36.2-status.0",
"react-native-image-resizer": "^1.2.3",
"react-native-image-viewing": "git+https://github.com/Ferossgp/react-native-image-viewing.git#v0.2.1",
"react-native-keychain": "git+https://github.com/status-im/react-native-keychain.git#v.3.0.0-5-status",
"react-native-image-viewing": "git+https://github.com/Ferossgp/react-native-image-viewing.git#refs/tags/v0.2.1",
"react-native-keychain": "git+https://github.com/status-im/react-native-keychain.git#refs/tags/v.3.0.0-5-status",
"react-native-languages": "^3.0.2",
"react-native-linear-gradient": "^2.5.6",
"react-native-mail": "^6.1.1",
Expand All @@ -60,11 +60,11 @@
"react-native-shake": "^3.3.1",
"react-native-share": "^7.0.1",
"react-native-splash-screen": "^3.2.0",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.37",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.5.37",
"react-native-svg": "^9.8.4",
"react-native-touch-id": "^4.4.1",
"react-native-webview": "git+https://github.com/status-im/react-native-webview.git#v11.16.0-status",
"rn-emoji-keyboard": "git+https://github.com/status-im/rn-emoji-keyboard.git#v0.4.2",
"react-native-webview": "git+https://github.com/status-im/react-native-webview.git#refs/tags/v11.16.0-status",
"rn-emoji-keyboard": "git+https://github.com/status-im/rn-emoji-keyboard.git#refs/tags/v0.4.2",
"tdigest": "^0.1.1",
"web3-utils": "^1.2.1"
},
Expand All @@ -79,7 +79,7 @@
"jest": "^25.1.0",
"nyc": "^14.1.1",
"process": "0.11.10",
"rn-snoopy": "git+https://github.com/status-im/rn-snoopy.git#v2.0.2-status",
"rn-snoopy": "git+https://github.com/status-im/rn-snoopy.git#refs/tags/v2.0.2-status",
"shadow-cljs": "^2.10.14"
}
}
Loading

0 comments on commit 54310cf

Please sign in to comment.