##// END OF EJS Templates
py3: fix python version read.
py3: fix python version read.

File last commit:

r976:cfd2a5fb python3
r980:328a152e python3
Show More
default.nix
220 lines | 6.7 KiB | text/x-nix | NixLexer
# Nix environment for the community edition
#
# This shall be as lean as possible, just producing the rhodecode-vcsserver
# derivation. For advanced tweaks to pimp up the development environment we use
# "shell.nix" so that it does not have to clutter this file.
args@
{ system ? builtins.currentSystem
, pythonPackages ? "python27Packages"
, pythonExternalOverrides ? self: super: {}
, doCheck ? false
, ...
}:
let
pkgs_ = args.pkgs or (import <nixpkgs> { inherit system; });
in
let
pkgs = import <nixpkgs> {
overlays = [
(import ./pkgs/overlays.nix)
];
inherit
(pkgs_)
system;
};
# Works with the new python-packages, still can fallback to the old
# variant.
basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
self: basePythonPackages.override (a: { inherit self; }));
# Evaluates to the last segment of a file system path.
basename = path: with pkgs.lib; last (splitString "/" path);
startsWith = prefix: full: let
actualPrefix = builtins.substring 0 (builtins.stringLength prefix) full;
in actualPrefix == prefix;
# source code filter used as arugment to builtins.filterSource.
src-filter = path: type: with pkgs.lib;
let
ext = last (splitString "." path);
parts = last (splitString "/" path);
in
!builtins.elem (basename path) [
".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
"node_modules" "node_binaries"
"build" "data" "result" "tmp"] &&
!builtins.elem ext ["egg-info" "pyc"] &&
!startsWith "result" (basename path);
sources =
let
inherit
(pkgs.lib)
all
isString
attrValues;
sourcesConfig = pkgs.config.rc.sources or {};
in
# Ensure that sources are configured as strings. Using a path
# would result in a copy into the nix store.
assert all isString (attrValues sourcesConfig);
sourcesConfig;
rhodecode-vcsserver-src = builtins.filterSource src-filter ./.;
version = builtins.readFile "${rhodecode-vcsserver-src}/vcsserver/VERSION";
pythonLocalOverrides = self: super: {
rhodecode-vcsserver =
let
releaseName = "RhodeCodeVCSServer-${version}";
pythonWithEnv =
self.python.buildEnv.override {
extraLibs = [ ] ++ self.rhodecode-vcsserver.propagatedBuildInputs;
ignoreCollisions = true;
#--set PYTHONHASHSEED random TODO
};
in super.rhodecode-vcsserver.override (attrs: {
inherit
doCheck
version;
name = "rhodecode-vcsserver-${version}";
releaseName = releaseName;
src = rhodecode-vcsserver-src;
dontStrip = true; # prevent strip, we don't need it.
# expose following attributed outside
passthru = {
pythonPackages = self;
vcs_pkgs = pkgs;
};
buildInputs =
attrs.buildInputs or [] ++ [
];
#NOTE: option to inject additional propagatedBuildInputs
propagatedBuildInputs =
attrs.propagatedBuildInputs or [] ++ [
pkgs.git
pkgs.subversion
];
preBuild = ''
export NIX_PATH=nixpkgs=${pkgs.path}
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
'';
# Add bin directory to path so that tests can find 'vcsserver'.
preCheck = ''
echo "Expanding PATH with $out/bin directory"
export PATH="$out/bin:$PATH"
'';
# custom check phase for testing
checkPhase = ''
runHook preCheck
PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=vcsserver --cov-report=term-missing vcsserver
runHook postCheck
'';
postCheck = ''
echo "Cleanup of vcsserver/tests"
rm -rf $out/lib/${self.python.libPrefix}/site-packages/vcsserver/tests
'';
postInstall = ''
echo "Writing vcsserver meta information for rccontrol to nix-support/rccontrol"
mkdir -p $out/nix-support/rccontrol
cp -v vcsserver/VERSION $out/nix-support/rccontrol/version
echo "DONE: vcsserver meta information for rccontrol written"
mkdir -p $out/etc
cp configs/production.ini $out/etc
echo "DONE: saved vcsserver production.ini into $out/etc"
echo "saving env in $out/etc/env_vars.txt"
touch $out/etc/env_vars.txt
echo "# RhodeCode build env vars" >> $out/etc/env_vars.txt
echo "LOCALE_ARCHIVE=\"${pkgs.glibcLocales}/lib/locale/locale-archive\"" >> $out/etc/env_vars.txt
echo "LC_ALL=\"en_US.UTF-8\"" >> $out/etc/env_vars.txt
# python based programs need to be wrapped
mkdir -p $out/bin
# expose python
ln -s ${pythonWithEnv}/bin/python $out/bin/
# required binaries from dependencies
ln -s ${pythonWithEnv}/bin/gunicorn $out/bin/
ln -s ${pythonWithEnv}/bin/prequest $out/bin/
ln -s ${pythonWithEnv}/bin/pserve $out/bin/
# Symlink version control utilities
# We ensure that always the correct version is available as a symlink.
# So that users calling them via the profile path will always use the
# correct version. Wrapping is required so those can "import"
# vcsserver python hooks.
ln -s ${pkgs.git}/bin/git $out/bin
ln -s ${self.mercurial}/bin/hg $out/bin
ln -s ${pkgs.subversion}/bin/svn* $out/bin
echo "[DONE ]: created symlinks into $out/bin"
DEPS="$out/bin/hg \
$out/bin/git \
$out/bin/svn \
$out/bin/svnserve \
$out/bin/svnadmin
"
# wrap only dependency scripts, they require to have full PYTHONPATH set
# to be able to import all packages
for file in $DEPS;
do
wrapProgram $file \
--prefix PATH : $PATH \
--prefix PYTHONPATH : $PYTHONPATH
done
echo "[DONE ]: vcsserver binary wrapping"
# expose sources of vcsserver
ln -s $out $out/etc/rhodecode_vcsserver_source
'';
});
};
basePythonPackages = with builtins;
if isAttrs pythonPackages then
pythonPackages
else
getAttr pythonPackages pkgs;
pythonGeneratedPackages = import ./pkgs/python-packages.nix {
inherit pkgs;
inherit (pkgs) fetchurl fetchgit fetchhg;
};
pythonVCSServerOverrides = import ./pkgs/python-packages-overrides.nix {
inherit pkgs basePythonPackages;
};
# Apply all overrides and fix the final package set
myPythonPackagesUnfix = with pkgs.lib;
(extends pythonExternalOverrides
(extends pythonLocalOverrides
(extends pythonVCSServerOverrides
(extends pythonGeneratedPackages
basePythonPackagesUnfix))));
myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
in myPythonPackages.rhodecode-vcsserver