##// END OF EJS Templates
nix: fix dogpile imports
nix: fix dogpile imports

File last commit:

r981:55389aab python3
r985:788d6820 python3
Show More
default.nix
211 lines | 6.6 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 ? "python37Packages"
, 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;
};
# 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}";
in super.rhodecode-vcsserver.overridePythonAttrs (attrs: {
inherit
doCheck
version;
name = "rhodecode-vcsserver-${version}";
releaseName = releaseName;
src = rhodecode-vcsserver-src;
dontStrip = true; # prevent strip, we don't need it.
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
# 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 vcsserver package set
targetPython = basePythonPackages.python.override {
packageOverrides = self: super: with pkgs.lib;
(extends pythonExternalOverrides
(extends pythonLocalOverrides
(extends pythonVCSServerOverrides
(extends pythonGeneratedPackages
(self: super))))) self;
};
# Python env with rhodecode-vcsserver
pythonEnv = (targetPython.withPackages(ps: with ps; [rhodecode-vcsserver]));
# Generic env with wrapped binaries
vcsserver = pkgs.buildEnv {
name = if ! isNull targetPython.pkgs.rhodecode-vcsserver
then "vcsserver-${targetPython.pkgs.rhodecode-vcsserver.version}"
else "vcsserver";
paths = [
pythonEnv
# 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.
pkgs.git
pkgs.subversion
];
# expose following attributed outside
passthru = {
pythonPackages = targetPython.pkgs;
vcs_pkgs = pkgs;
};
buildInputs = [
pkgs.makeWrapper
];
postBuild = (if ! isNull targetPython.pkgs.rhodecode-vcsserver then ''
echo "Writing vcsserver meta information for rccontrol to nix-support/rccontrol"
ln -s ${targetPython.pkgs.rhodecode-vcsserver}/nix-support $out/nix-support
echo "DONE: vcsserver meta information for rccontrol written"
'' else "") + ''
DEPS="$out/bin/*"
# 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 : ${pkgs.git}/bin \
--prefix PATH : ${pkgs.subversion}/bin \
--prefix PATH : ${pythonEnv}/bin \
--prefix PYTHONPATH : ${pythonEnv}/${pythonEnv.sitePackages} \
--prefix PYTHONPATH : ${pkgs.subversion}/${pythonEnv.sitePackages} \
--set PYTHONHASHSEED $RANDOM
done
echo "DONE: vcsserver binary wrapping"
'';
};
in vcsserver