# HG changeset patch # User Johannes Bornhold # Date 2016-08-30 16:47:19 # Node ID 5748905636aa0b2330b7101432922d51eeb451ef # Parent 10b241b0a17c4b1f55ba33a3deec43429863adf8 packaging: Backport bower support utilities To support nixos-16.03 the utilities to build bower components are backported inside of this PR. Once we switch to the new stable branch, we should be able to drop these pieces again. diff --git a/default.nix b/default.nix --- a/default.nix +++ b/default.nix @@ -30,6 +30,10 @@ let then pythonPackages else getAttr pythonPackages pkgs; + buildBowerComponents = + pkgs.buildBowerComponents or + (import ./pkgs/backport-16.03-build-bower-components.nix { inherit pkgs; }); + elem = builtins.elem; basename = path: with pkgs.lib; last (splitString "/" path); startsWith = prefix: full: let @@ -58,7 +62,7 @@ let }; nodeDependencies = nodeEnv.shell.nodeDependencies; - bowerComponents = pkgs.buildBowerComponents { + bowerComponents = buildBowerComponents { name = "enterprise-ce-${version}"; generated = ./pkgs/bower-packages.nix; src = rhodecode-enterprise-ce-src; diff --git a/pkgs/backport-16.03-build-bower-components.nix b/pkgs/backport-16.03-build-bower-components.nix new file mode 100644 --- /dev/null +++ b/pkgs/backport-16.03-build-bower-components.nix @@ -0,0 +1,60 @@ +# Backported buildBowerComponents so that we can also use it with the version +# 16.03 which is the current stable at the time of this writing. +# +# This file can be removed once building with 16.03 is not needed anymore. + +{ pkgs }: + +{ buildInputs ? [], generated, ... } @ attrs: + +let + fetchbower = import ./backport-16.03-fetchbower.nix { + inherit (pkgs) stdenv lib; + inherit (pkgs.nodePackages) bower2nix; + }; + + # Fetches the bower packages. `generated` should be the result of a + # `bower2nix` command. + bowerPackages = import generated { + inherit (pkgs) buildEnv; + inherit fetchbower; + }; + +in pkgs.stdenv.mkDerivation ( + attrs + // + { + name = "bower_components-" + attrs.name; + + inherit bowerPackages; + + builder = builtins.toFile "builder.sh" '' + source $stdenv/setup + + # The project's bower.json is required + cp $src/bower.json . + + # Dereference symlinks -- bower doesn't like them + cp --recursive --reflink=auto \ + --dereference --no-preserve=mode \ + $bowerPackages bc + + # Bower install in offline mode -- links together the fetched + # bower packages. + HOME=$PWD bower \ + --config.storage.packages=bc/packages \ + --config.storage.registry=bc/registry \ + --offline install + + # Sets up a single bower_components directory within + # the output derivation. + mkdir -p $out + mv bower_components $out + ''; + + buildInputs = buildInputs ++ [ + pkgs.git + pkgs.nodePackages.bower + ]; + } +) diff --git a/pkgs/backport-16.03-fetchbower.nix b/pkgs/backport-16.03-fetchbower.nix new file mode 100644 --- /dev/null +++ b/pkgs/backport-16.03-fetchbower.nix @@ -0,0 +1,26 @@ +{ stdenv, lib, bower2nix }: +let + bowerVersion = version: + let + components = lib.splitString "#" version; + hash = lib.last components; + ver = if builtins.length components == 1 then version else hash; + in ver; + + fetchbower = name: version: target: outputHash: stdenv.mkDerivation { + name = "${name}-${bowerVersion version}"; + buildCommand = '' + fetch-bower --quiet --out=$PWD/out "${name}" "${target}" "${version}" + # In some cases, the result of fetchBower is different depending + # on the output directory (e.g. if the bower package contains + # symlinks). So use a local output directory before copying to + # $out. + cp -R out $out + ''; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + inherit outputHash; + buildInputs = [ bower2nix ]; + }; + +in fetchbower