default.nix
211 lines
| 6.6 KiB
| text/x-nix
|
NixLexer
r0 | # 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. | ||||
r472 | args@ | |||
r639 | { system ? builtins.currentSystem | |||
r989 | , pythonPackages ? "python38Packages" | |||
r0 | , pythonExternalOverrides ? self: super: {} | |||
r472 | , doCheck ? false | |||
, ... | ||||
r0 | }: | |||
r571 | let | |||
r639 | pkgs_ = args.pkgs or (import <nixpkgs> { inherit system; }); | |||
r571 | in | |||
r0 | ||||
let | ||||
r571 | pkgs = import <nixpkgs> { | |||
r472 | overlays = [ | |||
(import ./pkgs/overlays.nix) | ||||
]; | ||||
r570 | inherit | |||
(pkgs_) | ||||
r472 | system; | |||
r571 | }; | |||
r116 | ||||
r472 | # Evaluates to the last segment of a file system path. | |||
basename = path: with pkgs.lib; last (splitString "/" path); | ||||
r970 | startsWith = prefix: full: let | |||
actualPrefix = builtins.substring 0 (builtins.stringLength prefix) full; | ||||
in actualPrefix == prefix; | ||||
r0 | ||||
r472 | # source code filter used as arugment to builtins.filterSource. | |||
r0 | src-filter = path: type: with pkgs.lib; | |||
let | ||||
ext = last (splitString "." path); | ||||
r970 | parts = last (splitString "/" path); | |||
r0 | in | |||
r472 | !builtins.elem (basename path) [ | |||
".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev" | ||||
r571 | "node_modules" "node_binaries" | |||
r472 | "build" "data" "result" "tmp"] && | |||
!builtins.elem ext ["egg-info" "pyc"] && | ||||
r970 | !startsWith "result" (basename path); | |||
r0 | ||||
r472 | sources = | |||
let | ||||
r570 | inherit | |||
(pkgs.lib) | ||||
all | ||||
isString | ||||
attrValues; | ||||
r970 | ||||
r472 | 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; | ||||
r976 | rhodecode-vcsserver-src = builtins.filterSource src-filter ./.; | |||
r472 | version = builtins.readFile "${rhodecode-vcsserver-src}/vcsserver/VERSION"; | |||
r0 | ||||
pythonLocalOverrides = self: super: { | ||||
r472 | rhodecode-vcsserver = | |||
let | ||||
releaseName = "RhodeCodeVCSServer-${version}"; | ||||
r981 | in super.rhodecode-vcsserver.overridePythonAttrs (attrs: { | |||
r472 | inherit | |||
doCheck | ||||
version; | ||||
r135 | ||||
r18 | name = "rhodecode-vcsserver-${version}"; | |||
r472 | releaseName = releaseName; | |||
r0 | src = rhodecode-vcsserver-src; | |||
r174 | dontStrip = true; # prevent strip, we don't need it. | |||
r0 | ||||
r970 | buildInputs = | |||
attrs.buildInputs or [] ++ [ | ||||
]; | ||||
#NOTE: option to inject additional propagatedBuildInputs | ||||
r472 | propagatedBuildInputs = | |||
attrs.propagatedBuildInputs or [] ++ [ | ||||
pkgs.git | ||||
r986 | pkgs.subversionrc | |||
r472 | ]; | |||
r970 | preBuild = '' | |||
export NIX_PATH=nixpkgs=${pkgs.path} | ||||
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt | ||||
''; | ||||
r496 | ||||
r472 | # Add bin directory to path so that tests can find 'vcsserver'. | |||
r0 | preCheck = '' | |||
r976 | echo "Expanding PATH with $out/bin directory" | |||
r0 | export PATH="$out/bin:$PATH" | |||
''; | ||||
r472 | # custom check phase for testing | |||
r135 | checkPhase = '' | |||
runHook preCheck | ||||
r981 | PYTHONHASHSEED=$RANDOM py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=vcsserver --cov-report=term-missing vcsserver | |||
r135 | runHook postCheck | |||
''; | ||||
r472 | postCheck = '' | |||
echo "Cleanup of vcsserver/tests" | ||||
rm -rf $out/lib/${self.python.libPrefix}/site-packages/vcsserver/tests | ||||
''; | ||||
r0 | postInstall = '' | |||
r472 | echo "Writing vcsserver meta information for rccontrol to nix-support/rccontrol" | |||
r0 | mkdir -p $out/nix-support/rccontrol | |||
cp -v vcsserver/VERSION $out/nix-support/rccontrol/version | ||||
r472 | 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" | ||||
r0 | ||||
r974 | 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 | ||||
r976 | # expose sources of vcsserver | |||
ln -s $out $out/etc/rhodecode_vcsserver_source | ||||
r0 | ''; | |||
}); | ||||
}; | ||||
r472 | basePythonPackages = with builtins; | |||
if isAttrs pythonPackages then | ||||
pythonPackages | ||||
else | ||||
getAttr pythonPackages pkgs; | ||||
pythonGeneratedPackages = import ./pkgs/python-packages.nix { | ||||
r970 | inherit pkgs; | |||
inherit (pkgs) fetchurl fetchgit fetchhg; | ||||
r472 | }; | |||
pythonVCSServerOverrides = import ./pkgs/python-packages-overrides.nix { | ||||
r970 | inherit pkgs basePythonPackages; | |||
r472 | }; | |||
r981 | # 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])); | ||||
r472 | ||||
r981 | # 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 | ||||
r986 | pkgs.subversionrc | |||
r981 | ]; | |||
# 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 \ | ||||
r986 | --prefix PATH : ${pkgs.subversionrc}/bin \ | |||
r981 | --prefix PATH : ${pythonEnv}/bin \ | |||
--prefix PYTHONPATH : ${pythonEnv}/${pythonEnv.sitePackages} \ | ||||
r986 | --prefix PYTHONPATH : ${pkgs.subversionrc}/${pythonEnv.sitePackages} \ | |||
r981 | --set PYTHONHASHSEED $RANDOM | |||
done | ||||
echo "DONE: vcsserver binary wrapping" | ||||
''; | ||||
}; | ||||
r0 | ||||
r981 | in vcsserver | |||