Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions nixos/modules/system/boot/stage-1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ let
# copy what we need. Instead of using statically linked binaries,
# we just copy what we need from Glibc and use patchelf to make it
# work.
extraUtils = let
# Use lvm2 without udev support, which is the same lvm2 we already have in the closure anyways
lvm2 = pkgs.lvm2.override { udev = null; }; in pkgs.runCommandCC "extra-utils"
extraUtils = pkgs.runCommandCC "extra-utils"
{ nativeBuildInputs = [pkgs.buildPackages.nukeReferences];
allowedReferences = [ "out" ]; # prevent accidents like glibc being included in the initrd
}
Expand All @@ -113,8 +111,8 @@ let
copy_bin_and_libs ${pkgs.utillinux}/sbin/blkid

# Copy dmsetup and lvm.
copy_bin_and_libs ${getBin lvm2}/bin/dmsetup
copy_bin_and_libs ${getBin lvm2}/bin/lvm
copy_bin_and_libs ${getBin pkgs.lvm2}/bin/dmsetup
copy_bin_and_libs ${getBin pkgs.lvm2}/bin/lvm

# Add RAID mdadm tool.
copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm
Expand Down
9 changes: 4 additions & 5 deletions nixos/tests/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ let
texinfo
unionfs-fuse
xorg.lndir
(lvm2.override { udev = null; }) # for initrd (extra-utils)

# add curl so that rather than seeing the test attempt to download
# curl's tarball, we see what it's trying to download
Expand Down Expand Up @@ -634,10 +633,10 @@ in {
+ " mklabel msdos"
+ " mkpart primary ext2 1M 100MB" # /boot
+ " mkpart extended 100M -1s"
+ " mkpart logical 102M 2102M" # md0 (root), first device
+ " mkpart logical 2103M 4103M" # md0 (root), second device
+ " mkpart logical 4104M 4360M" # md1 (swap), first device
+ " mkpart logical 4361M 4617M", # md1 (swap), second device
+ " mkpart logical 102M 3102M" # md0 (root), first device
+ " mkpart logical 3103M 6103M" # md0 (root), second device
+ " mkpart logical 6104M 6360M" # md1 (swap), first device
+ " mkpart logical 6361M 6617M", # md1 (swap), second device
"udevadm settle",
"ls -l /dev/vda* >&2",
"cat /proc/partitions >&2",
Expand Down
10 changes: 10 additions & 0 deletions pkgs/os-specific/linux/lvm2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ stdenv.mkDerivation rec {
stdenv.lib.optionals (udev != null) [
"--enable-udev_rules"
"--enable-udev_sync"
"--enable-udev-systemd-background-jobs"
];

preConfigure = ''
Expand All @@ -61,6 +62,15 @@ stdenv.mkDerivation rec {

substituteInPlace make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system"
substituteInPlace libdm/make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system"
''
# Fake systemd presence; otherwise we can't --enable-udev-systemd-background-jobs
+ stdenv.lib.optionalString (udev != null) ''
cat >systemd.pc <<-EOF
Name: systemd
Description: fake systemd
Version: ${udev.version}
EOF
PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(pwd)"
'';

postConfigure = ''
Expand Down
50 changes: 40 additions & 10 deletions pkgs/os-specific/linux/systemd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,34 @@

let
version = "246";
in stdenv.mkDerivation {

libudev = systemd.overrideAttrs (_: {
pname = "libudev";

outputs = [ "out" "dev" ];

buildInputs =
[ linuxHeaders libcap curl.dev kmod xz pam acl
libuuid glib libgcrypt libgpgerror libidn2
pcre2 ] ++
stdenv.lib.optional withKexectools kexectools ++
stdenv.lib.optional withLibseccomp libseccomp ++
[ libffi audit lz4 bzip2 libapparmor
iptables gnu-efi
] ++ stdenv.lib.optional withSelinux libselinux;
Comment on lines +29 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these probably are not dependencies of just libudev, are they?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was planning to do such reductions after the change actually works.

Copy link
Member Author

@vcunat vcunat Sep 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Now it appears to work fine.)

I tried to start with empty mkDerivation instead of overriding the systemd one, but I couldn't come with anything simple. Just making the meson configure pass isn't easy – it requires lots of stuff that's useless for libudev but I see no easy way of turning these off (*Inputs, mesonFlags, etc.) – honestly it feels that maintainability will be easiest when those two derivations only have minimal differences (full systemd and libudev).


# We did a full build, but at least retain only the required results.
postInstall = ''
mv "$out" out-all
mv "$dev" dev-all
mkdir -p "$out"/lib "$dev"/include "$dev"/lib/pkgconfig
mv out-all/lib/libudev* "$out"/lib/
mv {dev-all,"$dev"}/include/libudev.h
mv {dev-all,"$dev"}/lib/pkgconfig/libudev.pc
'';
});

systemd = stdenv.mkDerivation {
inherit version;
pname = "systemd";

Expand Down Expand Up @@ -79,15 +106,8 @@ in stdenv.mkDerivation {

(buildPackages.python3Packages.python.withPackages ( ps: with ps; [ python3Packages.lxml ]))
];
buildInputs =
[ linuxHeaders libcap curl.dev kmod xz pam acl
cryptsetup libuuid glib libgcrypt libgpgerror libidn2
pcre2 ] ++
stdenv.lib.optional withKexectools kexectools ++
stdenv.lib.optional withLibseccomp libseccomp ++
[ libffi audit lz4 bzip2 libapparmor
iptables gnu-efi
] ++ stdenv.lib.optional withSelinux libselinux;

buildInputs = libudev.buildInputs ++ [ cryptsetup ];

#dontAddPrefix = true;

Expand Down Expand Up @@ -265,6 +285,12 @@ in stdenv.mkDerivation {

# "kernel-install" shouldn't be used on NixOS.
find $out -name "*kernel-install*" -exec rm {} \;

# libudev deduplication
# TODO: instead of this, patch meson.build files to use libudev cleanly?
cp -sf '${libudev.out}'/lib/libudev.so.1.* "$out"/lib/
cp -sf '${libudev.dev}'/include/libudev.h "$dev"/include/
cp -sf '${libudev.dev}'/lib/pkgconfig/libudev.pc "$dev"/lib/pkgconfig/
''; # */

enableParallelBuilding = true;
Expand All @@ -277,6 +303,8 @@ in stdenv.mkDerivation {
# runtime; otherwise we can't and we need to reboot.
passthru.interfaceVersion = 2;

passthru.libudev = libudev;

meta = with stdenv.lib; {
homepage = "https://www.freedesktop.org/wiki/Software/systemd/";
description = "A system and service manager for Linux";
Expand All @@ -286,3 +314,5 @@ in stdenv.mkDerivation {
maintainers = with maintainers; [ andir eelco flokli ];
};
}
;
in systemd
10 changes: 4 additions & 6 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17234,11 +17234,7 @@ in

criu = callPackage ../os-specific/linux/criu { };

cryptsetup = callPackage ../os-specific/linux/cryptsetup {
# cryptsetup only really needs the devmapper component of cryptsetup
# but itself is used as a library in systemd (=udev)
lvm2 = lvm2.override { udev = null; };
};
cryptsetup = callPackage ../os-specific/linux/cryptsetup { };

cramfsprogs = callPackage ../os-specific/linux/cramfsprogs { };

Expand Down Expand Up @@ -17994,7 +17990,9 @@ in

lsscsi = callPackage ../os-specific/linux/lsscsi { };

lvm2 = callPackage ../os-specific/linux/lvm2 { };
lvm2 = callPackage ../os-specific/linux/lvm2 {
udev = systemd.libudev;
};
lvm2_dmeventd = callPackage ../os-specific/linux/lvm2 {
enableDmeventd = true;
enableCmdlib = true;
Expand Down