summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--maintainers/maintainer-list.nix5
-rw-r--r--pkgs/development/web/now-cli/default.nix87
-rw-r--r--pkgs/top-level/all-packages.nix2
3 files changed, 94 insertions, 0 deletions
diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix
index 9d93bbed9cfb..e7756f0bff11 100644
--- a/maintainers/maintainer-list.nix
+++ b/maintainers/maintainer-list.nix
@@ -520,6 +520,11 @@
     github = "bgamari";
     name = "Ben Gamari";
   };
+  bhall = {
+    email = "brendan.j.hall@bath.edu";
+    github = "brendan-hall";
+    name = "Brendan Hall";
+  };
   bhipple = {
     email = "bhipple@protonmail.com";
     github = "bhipple";
diff --git a/pkgs/development/web/now-cli/default.nix b/pkgs/development/web/now-cli/default.nix
new file mode 100644
index 000000000000..911e03daa371
--- /dev/null
+++ b/pkgs/development/web/now-cli/default.nix
@@ -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 ];
+  };
+}
\ No newline at end of file
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 4c9bdd844033..8f4bc519285f 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -3765,6 +3765,8 @@ with pkgs;
 
   npm2nix = nodePackages.npm2nix;
 
+  now-cli = callPackage ../development/web/now-cli {};
+
   file-rename = callPackage ../tools/filesystems/file-rename { };
 
   kea = callPackage ../tools/networking/kea {