13 apr 2015
gentoo linux has USE flags [1] and nixos has a very similar system. in this short posting i want to show how they are used on nixos.
for a very long time i was not even sure if nixos had USE flags at all, since nix and nixos is so much different from all other linux systems. but since i understand a lot more about nix/nixos now, i would like to share my insights:
note: there is a nice discussion here:
https://github.com/NixOS/nixpkgs/issues/7446
you can find the source for the subversion nix expression at [4]:
? false # build support for Berkeley DB repositories
{ bdbSupport ? false # build Apache DAV module
, httpServer ? false # client must support http
, httpSupport ? false
, pythonBindings ? false
, perlBindings ? false
, javahlBindings ? false
, saslSupport
, stdenv, fetchurl, apr, aprutil, zlib, sqlite? null, expat, swig ? null, jdk ? null, python ? null, perl ? null
, apacheHttpd ? null, serf ? null
, sasl :
}
-> aprutil.bdbSupport;
assert bdbSupport -> apacheHttpd != null;
assert httpServer -> swig != null && python != null;
assert pythonBindings -> jdk != null && perl != null;
assert javahlBindings
.mkDerivation (rec {
stdenv
= "1.8.13";
version
= "subversion-${version}";
name
= fetchurl {
src = "mirror://apache/subversion/${name}.tar.bz2";
url = "aa0bd14ac6a8f0fb178cc9ff325387de01cd7452";
sha1
};
= [ zlib apr aprutil sqlite ]
buildInputs ++ stdenv.lib.optional httpSupport serf
++ stdenv.lib.optional pythonBindings python
++ stdenv.lib.optional perlBindings perl
++ stdenv.lib.optional saslSupport sasl;
= ''
configureFlags ${if bdbSupport then "--with-berkeley-db" else "--without-berkeley-db"}
${if httpServer then "--with-apxs=${apacheHttpd}/bin/apxs" else "--without-apxs"}
${if pythonBindings || perlBindings then "--with-swig=${swig}" else "--without-swig"}
${if javahlBindings then "--enable-javahl --with-jdk=${jdk}" else ""}
${if stdenv.isDarwin then "--enable-keychain" else "--disable-keychain"}
${if saslSupport then "--with-sasl=${sasl}" else "--without-sasl"}
${if httpSupport then "--with-serf=${serf}" else "--without-serf"}
--with-zlib=${zlib}
--with-sqlite=${sqlite}
'';
= ''
preBuild =(APACHE_LIBEXECDIR=$out/modules)
makeFlagsArray
'';
= ''
postInstall if test -n "$pythonBindings"; then
-py swig_pydir=$(toPythonPath $out)/libsvn swig_pydir_extra=$(toPythonPath $out)/svn
make swig-swig-py swig_pydir=$(toPythonPath $out)/libsvn swig_pydir_extra=$(toPythonPath $out)/svn
make install
fiif test -n "$perlBindings"; then
-pl-lib
make swig-swig-pl-lib
make install/bindings/swig/perl/native
cd subversionMakefile.PL PREFIX=$out
perl
make install-
cd
fi-p $out/share/bash-completion/completions
mkdir /client-side/bash_completion $out/share/bash-completion/completions/subversion
cp tools
'';
inherit perlBindings pythonBindings;
= true;
enableParallelBuilding
= {
meta = "A version control system intended to be a compelling replacement for CVS in the open source community";
description = http://subversion.apache.org/;
homepage = with stdenv.lib.maintainers; [ eelco lovek323 ];
maintainers = stdenv.lib.platforms.linux ++ stdenv.lib.platforms.darwin;
hydraPlatforms
};// stdenv.lib.optionalAttrs stdenv.isDarwin {
} CXX = "clang++";
CC = "clang";
CPP = "clang -E";
CXXCPP = "clang++ -E";
})
this subversion nix expression can be customized depending on the values provided on the function call. just see the two examples below.
example usage of the subversion expression [5] - pkgs/top-level/all-packages.nix:
= apacheHttpd: self: let callPackage = newScope self; in {
apacheHttpdPackagesFor
inherit apacheHttpd;= callPackage ../servers/http/apache-modules/mod_dnssd { };
mod_dnssd = callPackage ../servers/http/apache-modules/mod_evasive { };
mod_evasive = callPackage ../servers/http/apache-modules/mod_fastcgi { };
mod_fastcgi = callPackage ../servers/http/apache-modules/mod_python { };
mod_python = callPackage ../servers/http/apache-modules/mod_wsgi { };
mod_wsgi = pkgs.php.override { inherit apacheHttpd; };
php = pkgs.subversion.override { httpServer = true; inherit apacheHttpd; };
subversion };
when the attribute apacheHttpdPackagesFor is evaluated it will be passed all the function arguments shown above as mod_dnssd, mod_evasive, …, and subversion. the main difference is that it passes a specially crafted version of the subversion expression with httpServer = true set;
example usage of the subversion expression [6] - pkgs/top-level/all-packages.nix:
= callPackage ../applications/version-management/subversion/default.nix {
subversion = true;
bdbSupport = false;
httpServer = true;
httpSupport = false;
pythonBindings = false;
perlBindings = false;
javahlBindings = false;
saslSupport = cyrus_sasl;
sasl };
if the attribute subversion is evaluated, say by using:
$ nix-env -i subversion
then it won’t enable httpServer as it is disabled by default. if both, example 1 and example 2 are used on the same system, this means that two different versions of subversion are installed. this is a major difference to gentoo, where you could have such a feature only by using SLOS.
with nixos USE flags and assertions you can do everything what gentoo linux provided and more. there are many good examples for their usage in nixpkgs [3] already.
if you would use example 1 and example 2 on the same machine, then it would install subversion two times on the same host. however, if both function calls are equal it will use the same subversion binary twice which happens if two users install subversion in their profile using:
$ nix-env -i subversion
for instance.