-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
now-cli: init at 11.4.6 #48193
Merged
Merged
now-cli: init at 11.4.6 #48193
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ stdenv, lib, fetchurl }: | ||
stdenv.mkDerivation rec { | ||
name = "now-cli-${version}"; | ||
version = "11.4.6"; | ||
|
||
# TODO: switch to building from source, if possible | ||
src = fetchurl { | ||
url = "https://github.com/zeit/now-cli/releases/download/${version}/now-linux.gz"; | ||
sha256 = "1bl0yrzxdfy6sks674qlfch8mg3b0x1wj488v83glags8ibsg3cl"; | ||
}; | ||
|
||
sourceRoot = "."; | ||
unpackCmd = '' | ||
gunzip -c $curSrc > now-linux | ||
''; | ||
|
||
buildPhase = ":"; | ||
|
||
installPhase = '' | ||
mkdir $out | ||
mkdir $out/bin | ||
cp now-linux $out/bin/now | ||
''; | ||
|
||
# now is a node program packaged using zeit/pkg. | ||
# thus, it contains hardcoded offsets. | ||
# patchelf shifts these locations when it expands headers. | ||
|
||
# this could probably be generalised into allowing any program packaged | ||
# with zeit/pkg to be run on nixos. | ||
|
||
preFixup = let | ||
libPath = lib.makeLibraryPath [stdenv.cc.cc]; | ||
in '' | ||
|
||
orig_size=$(stat --printf=%s $out/bin/now) | ||
|
||
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/bin/now | ||
patchelf --set-rpath ${libPath} $out/bin/now | ||
chmod +x $out/bin/now | ||
|
||
new_size=$(stat --printf=%s $out/bin/now) | ||
|
||
###### zeit-pkg fixing starts here. | ||
# we're replacing plaintext js code that looks like | ||
# PAYLOAD_POSITION = '1234 ' | 0 | ||
# [...] | ||
# PRELUDE_POSITION = '1234 ' | 0 | ||
# ^-----20-chars-----^^------22-chars------^ | ||
# ^-- grep points here | ||
# | ||
# var_* are as described above | ||
# shift_by seems to be safe so long as all patchelf adjustments occur | ||
# before any locations pointed to by hardcoded offsets | ||
|
||
var_skip=20 | ||
var_select=22 | ||
shift_by=$(expr $new_size - $orig_size) | ||
|
||
function fix_offset { | ||
# $1 = name of variable to adjust | ||
location=$(grep -obUam1 "$1" $out/bin/now | cut -d: -f1) | ||
location=$(expr $location + $var_skip) | ||
|
||
value=$(dd if=$out/bin/now iflag=count_bytes,skip_bytes skip=$location \ | ||
bs=1 count=$var_select status=none) | ||
value=$(expr $shift_by + $value) | ||
|
||
echo -n $value | dd of=$out/bin/now bs=1 seek=$location conv=notrunc | ||
} | ||
|
||
fix_offset PAYLOAD_POSITION | ||
fix_offset PRELUDE_POSITION | ||
|
||
''; | ||
dontStrip = true; | ||
|
||
|
||
|
||
meta = with stdenv.lib; { | ||
homepage = https://zeit.co/now; | ||
description = "The Command Line Interface for Now - Global Serverless Deployments"; | ||
license = licenses.asl20; | ||
platforms = platforms.linux; | ||
maintainers = [ maintainers.bhall ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's been a while but here is an alternative solution, maybe its useful
This relies on rpath injection causing a 4096 byte extension obviously.
works on FreeBSD.