default.nix
282 lines
| 8.9 KiB
| text/x-nix
|
NixLexer
r1 | # Nix environment for the community edition | |||
# | ||||
r2824 | # This shall be as lean as possible, just producing the enterprise-ce | |||
r1 | # derivation. For advanced tweaks to pimp up the development environment we use | |||
# "shell.nix" so that it does not have to clutter this file. | ||||
r2824 | # | |||
# Configuration, set values in "~/.nixpkgs/config.nix". | ||||
# example | ||||
# { | ||||
# # Thoughts on how to configure the dev environment | ||||
# rc = { | ||||
# codeInternalUrl = "https://usr:token@internal-code.rhodecode.com"; | ||||
# sources = { | ||||
# rhodecode-vcsserver = "/home/user/work/rhodecode-vcsserver"; | ||||
# rhodecode-enterprise-ce = "/home/user/work/rhodecode-enterprise-ce"; | ||||
# rhodecode-enterprise-ee = "/home/user/work/rhodecode-enterprise-ee"; | ||||
# }; | ||||
# }; | ||||
# } | ||||
r1 | ||||
Martin Bornhold
|
r926 | args@ | ||
{ pythonPackages ? "python27Packages" | ||||
r1 | , pythonExternalOverrides ? self: super: {} | |||
r2824 | , doCheck ? false | |||
Martin Bornhold
|
r926 | , ... | ||
r1 | }: | |||
r3140 | let pkgs_ = (import <nixpkgs> {}); in | |||
r1 | ||||
let | ||||
Martin Bornhold
|
r926 | # Use nixpkgs from args or import them. We use this indirect approach | ||
# through args to be able to use the name `pkgs` for our customized packages. | ||||
# Otherwise we will end up with an infinite recursion. | ||||
r3140 | pkgs = args.pkgs or (import <nixpkgs> { | |||
overlays = [ | ||||
(import ./pkgs/overlays.nix) | ||||
]; | ||||
inherit (pkgs_) | ||||
system; | ||||
}); | ||||
Martin Bornhold
|
r926 | |||
r2824 | # Works with the new python-packages, still can fallback to the old | |||
# variant. | ||||
basePythonPackagesUnfix = basePythonPackages.__unfix__ or ( | ||||
self: basePythonPackages.override (a: { inherit self; })); | ||||
Martin Bornhold
|
r926 | |||
# Evaluates to the last segment of a file system path. | ||||
basename = path: with pkgs.lib; last (splitString "/" path); | ||||
# source code filter used as arugment to builtins.filterSource. | ||||
src-filter = path: type: with pkgs.lib; | ||||
let | ||||
ext = last (splitString "." path); | ||||
in | ||||
!builtins.elem (basename path) [ | ||||
r2824 | ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev" | |||
Martin Bornhold
|
r926 | "bower_components" "node_modules" | ||
"build" "data" "result" "tmp"] && | ||||
!builtins.elem ext ["egg-info" "pyc"] && | ||||
# TODO: johbo: This check is wrong, since "path" contains an absolute path, | ||||
# it would still be good to restore it since we want to ignore "result-*". | ||||
!hasPrefix "result" path; | ||||
r1 | ||||
r2824 | 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; | ||||
r1 | ||||
r2824 | version = builtins.readFile "${rhodecode-enterprise-ce-src}/rhodecode/VERSION"; | |||
r1 | rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.; | |||
r2824 | buildBowerComponents = pkgs.buildBowerComponents; | |||
r708 | nodeEnv = import ./pkgs/node-default.nix { | |||
inherit pkgs; | ||||
r1 | }; | |||
r708 | nodeDependencies = nodeEnv.shell.nodeDependencies; | |||
r1 | ||||
r725 | bowerComponents = buildBowerComponents { | |||
r724 | name = "enterprise-ce-${version}"; | |||
r719 | generated = ./pkgs/bower-packages.nix; | |||
src = rhodecode-enterprise-ce-src; | ||||
}; | ||||
r2824 | rhodecode-testdata-src = sources.rhodecode-testdata or ( | |||
pkgs.fetchhg { | ||||
url = "https://code.rhodecode.com/upstream/rc_testdata"; | ||||
rev = "v0.10.0"; | ||||
sha256 = "0zn9swwvx4vgw4qn8q3ri26vvzgrxn15x6xnjrysi1bwmz01qjl0"; | ||||
}); | ||||
r1 | ||||
r2824 | rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" { | |||
inherit | ||||
doCheck | ||||
pkgs | ||||
pythonPackages; | ||||
r1 | }; | |||
pythonLocalOverrides = self: super: { | ||||
rhodecode-enterprise-ce = | ||||
let | ||||
r720 | linkNodeAndBowerPackages = '' | |||
r743 | export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src} | |||
r2824 | ||||
echo "[BEGIN]: Link node packages" | ||||
r1 | rm -fr node_modules | |||
r708 | mkdir node_modules | |||
# johbo: Linking individual packages allows us to run "npm install" | ||||
# inside of a shell to try things out. Re-entering the shell will | ||||
# restore a clean environment. | ||||
ln -s ${nodeDependencies}/lib/node_modules/* node_modules/ | ||||
r2824 | echo "[DONE]: Link node packages" | |||
r708 | ||||
r2824 | echo "[BEGIN]: Link bower packages" | |||
r720 | rm -fr bower_components | |||
mkdir bower_components | ||||
r2824 | ln -s ${bowerComponents}/bower_components/* bower_components/ | |||
echo "[DONE]: Link bower packages" | ||||
''; | ||||
r720 | ||||
r2824 | releaseName = "RhodeCodeEnterpriseCE-${version}"; | |||
r1 | in super.rhodecode-enterprise-ce.override (attrs: { | |||
r241 | inherit | |||
doCheck | ||||
version; | ||||
r2824 | ||||
r1 | name = "rhodecode-enterprise-ce-${version}"; | |||
r2824 | releaseName = releaseName; | |||
r1 | src = rhodecode-enterprise-ce-src; | |||
r1493 | dontStrip = true; # prevent strip, we don't need it. | |||
r1 | ||||
r2824 | # expose following attributed outside | |||
r1 | passthru = { | |||
r74 | inherit | |||
r2824 | rhodecode-testdata | |||
r719 | bowerComponents | |||
r720 | linkNodeAndBowerPackages | |||
r465 | myPythonPackagesUnfix | |||
r2824 | pythonLocalOverrides | |||
pythonCommunityOverrides; | ||||
r1 | pythonPackages = self; | |||
}; | ||||
r2824 | buildInputs = | |||
attrs.buildInputs or [] ++ [ | ||||
rhodecode-testdata | ||||
pkgs.nodePackages.bower | ||||
pkgs.nodePackages.grunt-cli | ||||
]; | ||||
#NOTE: option to inject additional propagatedBuildInputs | ||||
propagatedBuildInputs = | ||||
attrs.propagatedBuildInputs or [] ++ [ | ||||
]; | ||||
r1 | LC_ALL = "en_US.UTF-8"; | |||
LOCALE_ARCHIVE = | ||||
r2824 | if pkgs.stdenv.isLinux | |||
r1 | then "${pkgs.glibcLocales}/lib/locale/locale-archive" | |||
else ""; | ||||
r2824 | # Add bin directory to path so that tests can find 'rhodecode'. | |||
r1 | preCheck = '' | |||
export PATH="$out/bin:$PATH" | ||||
''; | ||||
r2824 | # custom check phase for testing | |||
checkPhase = '' | ||||
runHook preCheck | ||||
PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=rhodecode --cov-report=term-missing rhodecode | ||||
runHook postCheck | ||||
''; | ||||
r1 | postCheck = '' | |||
r2824 | echo "Cleanup of rhodecode/tests" | |||
r1 | rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests | |||
''; | ||||
r2824 | preBuild = '' | |||
echo "Building frontend assets" | ||||
${linkNodeAndBowerPackages} | ||||
r1 | grunt | |||
rm -fr node_modules | ||||
''; | ||||
postInstall = '' | ||||
r3121 | # check required files | |||
if [ ! -f rhodecode/public/js/scripts.js ]; then | ||||
echo "Missing scripts.js" | ||||
exit 1 | ||||
fi | ||||
if [ ! -f rhodecode/public/css/style.css ]; then | ||||
echo "Missing style.css" | ||||
exit 1 | ||||
fi | ||||
r2824 | echo "Writing enterprise-ce meta information for rccontrol to nix-support/rccontrol" | |||
r1773 | mkdir -p $out/nix-support/rccontrol | |||
cp -v rhodecode/VERSION $out/nix-support/rccontrol/version | ||||
r2824 | echo "[DONE]: enterprise-ce meta information for rccontrol written" | |||
mkdir -p $out/etc | ||||
cp configs/production.ini $out/etc | ||||
echo "[DONE]: saved enterprise-ce production.ini into $out/etc" | ||||
r1773 | ||||
r3133 | cp -r rhodecode/config/rcextensions $out/etc/rcextensions.tmpl | |||
echo "[DONE]: saved enterprise-ce rcextensions into $out/etc/rcextensions.tmpl" | ||||
r1 | # python based programs need to be wrapped | |||
r2824 | mkdir -p $out/bin | |||
# required binaries from dependencies | ||||
r3122 | ln -s ${self.supervisor}/bin/supervisorctl $out/bin/ | |||
ln -s ${self.supervisor}/bin/supervisord $out/bin/ | ||||
r2718 | ln -s ${self.pastescript}/bin/paster $out/bin/ | |||
r526 | ln -s ${self.channelstream}/bin/channelstream $out/bin/ | |||
r2377 | ln -s ${self.celery}/bin/celery $out/bin/ | |||
r3122 | ln -s ${self.gunicorn}/bin/gunicorn $out/bin/ | |||
ln -s ${self.pyramid}/bin/prequest $out/bin/ | ||||
ln -s ${self.pyramid}/bin/pserve $out/bin/ | ||||
r1 | ||||
r3122 | echo "[DONE]: created symlinks into $out/bin" | |||
DEPS="$out/bin/supervisorctl \ | ||||
$out/bin/supervisord \ | ||||
$out/bin/paster \ | ||||
$out/bin/channelstream \ | ||||
$out/bin/celery \ | ||||
$out/bin/gunicorn \ | ||||
$out/bin/prequest \ | ||||
$out/bin/pserve" | ||||
# wrap only dependency scripts, they require to have full PYTHONPATH set | ||||
# to be able to import all packages | ||||
for file in $DEPS; | ||||
r1773 | do | |||
r1 | wrapProgram $file \ | |||
r2824 | --prefix PATH : $PATH \ | |||
--prefix PYTHONPATH : $PYTHONPATH \ | ||||
--set PYTHONHASHSEED random | ||||
r1 | done | |||
r2824 | echo "[DONE]: enterprise-ce binary wrapping" | |||
r1 | ||||
r3121 | # rhodecode-tools don't need wrapping | |||
ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/ | ||||
r1 | ''; | |||
}); | ||||
}; | ||||
r2824 | 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; | ||||
}; | ||||
pythonCommunityOverrides = import ./pkgs/python-packages-overrides.nix { | ||||
inherit pkgs basePythonPackages; | ||||
}; | ||||
Martin Bornhold
|
r211 | |||
r1 | # Apply all overrides and fix the final package set | |||
Martin Bornhold
|
r926 | myPythonPackagesUnfix = with pkgs.lib; | ||
r1 | (extends pythonExternalOverrides | |||
(extends pythonLocalOverrides | ||||
r2824 | (extends pythonCommunityOverrides | |||
(extends pythonGeneratedPackages | ||||
basePythonPackagesUnfix)))); | ||||
Martin Bornhold
|
r926 | myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix); | ||
r1 | ||||
in myPythonPackages.rhodecode-enterprise-ce | ||||