You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

223 lines
8.5 KiB

  1. { stdenv, fetchFromGitHub, fetchpatch, pkgconfig, intltool, gperf, libcap, kmod
  2. , zlib, xz, pam, acl, cryptsetup, libuuid, m4, utillinux, libffi
  3. , glib, kbd, libxslt, coreutils, libgcrypt, libgpgerror, libidn2, libapparmor
  4. , audit, lz4, bzip2, kexectools, libmicrohttpd
  5. , linuxHeaders ? stdenv.cc.libc.linuxHeaders
  6. , libseccomp, iptables, gnu-efi
  7. , autoreconfHook, gettext, docbook_xsl, docbook_xml_dtd_42, docbook_xml_dtd_45
  8. , ninja, meson, python3Packages, glibcLocales
  9. , patchelf
  10. , getent
  11. , hostPlatform
  12. , buildPackages
  13. , withSelinux ? false, libselinux
  14. }:
  15. assert stdenv.isLinux;
  16. let
  17. pythonLxmlEnv = buildPackages.python3Packages.python.withPackages ( ps: with ps; [ python3Packages.lxml ]);
  18. in stdenv.mkDerivation rec {
  19. version = "237";
  20. name = "systemd-${version}";
  21. src = fetchFromGitHub {
  22. owner = "NixOS";
  23. repo = "systemd";
  24. rev = "98067cc806ae0d2759cdd2334f230cd8548e5317";
  25. sha256 = "077svfs2xy3g30s62q69wcv5pb9vfhzh8i7lhfri73vvhwbpzd5q";
  26. };
  27. outputs = [ "out" "lib" "man" "dev" ];
  28. nativeBuildInputs =
  29. [ pkgconfig intltool gperf libxslt gettext docbook_xsl docbook_xml_dtd_42 docbook_xml_dtd_45
  30. ninja meson
  31. coreutils # meson calls date, stat etc.
  32. glibcLocales
  33. patchelf getent m4
  34. ];
  35. buildInputs =
  36. [ linuxHeaders libcap kmod xz pam acl
  37. /* cryptsetup */ libuuid glib libgcrypt libgpgerror libidn2
  38. libmicrohttpd ] ++
  39. stdenv.lib.meta.enableIfAvailable kexectools ++
  40. stdenv.lib.meta.enableIfAvailable libseccomp ++
  41. [ libffi audit lz4 bzip2 libapparmor
  42. iptables gnu-efi
  43. # This is actually native, but we already pull it from buildPackages
  44. pythonLxmlEnv
  45. ] ++ stdenv.lib.optionals withSelinux [ libselinux ];
  46. #dontAddPrefix = true;
  47. mesonFlags = [
  48. "-Dloadkeys-path=${kbd}/bin/loadkeys"
  49. "-Dsetfont-path=${kbd}/bin/setfont"
  50. "-Dtty-gid=3" # tty in NixOS has gid 3
  51. # "-Dtests=" # TODO
  52. "-Dlz4=true"
  53. "-Dhostnamed=true"
  54. "-Dnetworkd=true"
  55. "-Dsysusers=false"
  56. "-Dtimedated=true"
  57. "-Dtimesyncd=true"
  58. "-Dfirstboot=false"
  59. "-Dlocaled=true"
  60. "-Dresolve=true"
  61. "-Dsplit-usr=false"
  62. "-Dlibcurl=false"
  63. "-Dlibidn=false"
  64. "-Dlibidn2=true"
  65. "-Dquotacheck=false"
  66. "-Dldconfig=false"
  67. "-Dsmack=true"
  68. "-Dsystem-uid-max=499" #TODO: debug why awking around in /etc/login.defs doesn't work
  69. "-Dsystem-gid-max=499"
  70. # "-Dtime-epoch=1"
  71. (if stdenv.isArm || !hostPlatform.isEfi then "-Dgnu-efi=false" else "-Dgnu-efi=true")
  72. "-Defi-libdir=${toString gnu-efi}/lib"
  73. "-Defi-includedir=${toString gnu-efi}/include/efi"
  74. "-Defi-ldsdir=${toString gnu-efi}/lib"
  75. "-Dsysvinit-path="
  76. "-Dsysvrcnd-path="
  77. "-Dkill-path=${coreutils}/bin/kill"
  78. "-Dkmod-path=${kmod}/bin/kmod"
  79. "-Dsulogin-path=${utillinux}/bin/sulogin"
  80. "-Dmount-path=${utillinux}/bin/mount"
  81. "-Dumount-path=${utillinux}/bin/umount"
  82. ];
  83. preConfigure = ''
  84. mesonFlagsArray+=(-Dntp-servers="0.nixos.pool.ntp.org 1.nixos.pool.ntp.org 2.nixos.pool.ntp.org 3.nixos.pool.ntp.org")
  85. mesonFlagsArray+=(-Ddbuspolicydir=$out/etc/dbus-1/system.d)
  86. mesonFlagsArray+=(-Ddbussessionservicedir=$out/share/dbus-1/services)
  87. mesonFlagsArray+=(-Ddbussystemservicedir=$out/share/dbus-1/system-services)
  88. mesonFlagsArray+=(-Dpamconfdir=$out/etc/pam.d)
  89. mesonFlagsArray+=(-Drootprefix=$out)
  90. mesonFlagsArray+=(-Dlibdir=$lib/lib)
  91. mesonFlagsArray+=(-Drootlibdir=$lib/lib)
  92. mesonFlagsArray+=(-Dmandir=$man/lib)
  93. mesonFlagsArray+=(-Dincludedir=$dev/include)
  94. mesonFlagsArray+=(-Dpkgconfiglibdir=$dev/lib/pkgconfig)
  95. mesonFlagsArray+=(-Dpkgconfigdatadir=$dev/share/pkgconfig)
  96. # FIXME: Why aren't includedir and libdir picked up from mesonFlags while other options are?
  97. substituteInPlace meson.build \
  98. --replace "includedir = join_paths(prefixdir, get_option('includedir'))" \
  99. "includedir = '$dev/include'" \
  100. --replace "libdir = join_paths(prefixdir, get_option('libdir'))" \
  101. "libdir = '$lib/lib'"
  102. export LC_ALL="en_US.UTF-8";
  103. # FIXME: patch this in systemd properly (and send upstream).
  104. # already fixed in f00929ad622c978f8ad83590a15a765b4beecac9: (u)mount
  105. for i in src/remount-fs/remount-fs.c src/core/mount.c src/core/swap.c src/fsck/fsck.c units/emergency.service.in units/rescue.service.in src/journal/cat.c src/core/shutdown.c src/nspawn/nspawn.c src/shared/generator.c; do
  106. test -e $i
  107. substituteInPlace $i \
  108. --replace /usr/bin/getent ${getent}/bin/getent \
  109. --replace /sbin/swapon ${utillinux.bin}/sbin/swapon \
  110. --replace /sbin/swapoff ${utillinux.bin}/sbin/swapoff \
  111. --replace /sbin/fsck ${utillinux.bin}/sbin/fsck \
  112. --replace /bin/echo ${coreutils}/bin/echo \
  113. --replace /bin/cat ${coreutils}/bin/cat \
  114. --replace /sbin/sulogin ${utillinux.bin}/sbin/sulogin \
  115. --replace /usr/lib/systemd/systemd-fsck $out/lib/systemd/systemd-fsck \
  116. --replace /bin/plymouth /run/current-system/sw/bin/plymouth # To avoid dependency
  117. done
  118. for i in tools/xml_helper.py tools/make-directive-index.py tools/make-man-index.py test/sys-script.py; do
  119. substituteInPlace $i \
  120. --replace "#!/usr/bin/env python" "#!${pythonLxmlEnv}/bin/python"
  121. done
  122. for i in src/basic/generate-gperfs.py src/resolve/generate-dns_type-gperf.py src/test/generate-sym-test.py ; do
  123. substituteInPlace $i \
  124. --replace "#!/usr/bin/env python" "#!${buildPackages.python3Packages.python}/bin/python"
  125. done
  126. substituteInPlace src/journal/catalog.c \
  127. --replace /usr/lib/systemd/catalog/ $out/lib/systemd/catalog/
  128. '';
  129. # These defines are overridden by CFLAGS and would trigger annoying
  130. # warning messages
  131. postConfigure = ''
  132. substituteInPlace config.h \
  133. --replace "POLKIT_AGENT_BINARY_PATH" "_POLKIT_AGENT_BINARY_PATH" \
  134. --replace "SYSTEMD_BINARY_PATH" "_SYSTEMD_BINARY_PATH" \
  135. --replace "SYSTEMD_CGROUP_AGENT_PATH" "_SYSTEMD_CGROUP_AGENT_PATH"
  136. '';
  137. hardeningDisable = [ "stackprotector" ];
  138. NIX_CFLAGS_COMPILE =
  139. [ # Can't say ${polkit.bin}/bin/pkttyagent here because that would
  140. # lead to a cyclic dependency.
  141. "-UPOLKIT_AGENT_BINARY_PATH" "-DPOLKIT_AGENT_BINARY_PATH=\"/run/current-system/sw/bin/pkttyagent\""
  142. # Set the release_agent on /sys/fs/cgroup/systemd to the
  143. # currently running systemd (/run/current-system/systemd) so
  144. # that we don't use an obsolete/garbage-collected release agent.
  145. "-USYSTEMD_CGROUP_AGENT_PATH" "-DSYSTEMD_CGROUP_AGENT_PATH=\"/run/current-system/systemd/lib/systemd/systemd-cgroups-agent\""
  146. "-USYSTEMD_BINARY_PATH" "-DSYSTEMD_BINARY_PATH=\"/run/current-system/systemd/lib/systemd/systemd\""
  147. ];
  148. postInstall = ''
  149. # sysinit.target: Don't depend on
  150. # systemd-tmpfiles-setup.service. This interferes with NixOps's
  151. # send-keys feature (since sshd.service depends indirectly on
  152. # sysinit.target).
  153. mv $out/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup-dev.service $out/lib/systemd/system/multi-user.target.wants/
  154. mkdir -p $out/example/systemd
  155. mv $out/lib/{modules-load.d,binfmt.d,sysctl.d,tmpfiles.d} $out/example
  156. mv $out/lib/systemd/{system,user} $out/example/systemd
  157. rm -rf $out/etc/systemd/system
  158. # Install SysV compatibility commands.
  159. mkdir -p $out/sbin
  160. ln -s $out/lib/systemd/systemd $out/sbin/telinit
  161. for i in init halt poweroff runlevel reboot shutdown; do
  162. ln -s $out/bin/systemctl $out/sbin/$i
  163. done
  164. # Fix reference to /bin/false in the D-Bus services.
  165. for i in $out/share/dbus-1/system-services/*.service; do
  166. substituteInPlace $i --replace /bin/false ${coreutils}/bin/false
  167. done
  168. rm -rf $out/etc/rpm
  169. # "kernel-install" shouldn't be used on NixOS.
  170. find $out -name "*kernel-install*" -exec rm {} \;
  171. # Keep only libudev and libsystemd in the lib output.
  172. mkdir -p $out/lib
  173. mv $lib/lib/security $lib/lib/libnss* $out/lib/
  174. ''; # */
  175. enableParallelBuilding = true;
  176. # The interface version prevents NixOS from switching to an
  177. # incompatible systemd at runtime. (Switching across reboots is
  178. # fine, of course.) It should be increased whenever systemd changes
  179. # in a backwards-incompatible way. If the interface version of two
  180. # systemd builds is the same, then we can switch between them at
  181. # runtime; otherwise we can't and we need to reboot.
  182. passthru.interfaceVersion = 2;
  183. meta = {
  184. homepage = http://www.freedesktop.org/wiki/Software/systemd;
  185. description = "A system and service manager for Linux";
  186. platforms = stdenv.lib.platforms.linux;
  187. maintainers = [ stdenv.lib.maintainers.eelco ];
  188. };
  189. }