Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lkl: 2017-11-10 -> 2018-03-10 #36795

Merged
merged 1 commit into from Mar 18, 2018
Merged

lkl: 2017-11-10 -> 2018-03-10 #36795

merged 1 commit into from Mar 18, 2018

Conversation

YorikSar
Copy link
Contributor

Bump lkl version to latest that includes merge of Linux 4.15 and fix for
an issue where cptofs wasn't returning failure when image size was too
small and file copying failed with:

error writing file: No space left on device

(see lkl/linux#427)

Motivation for this change

While fixing #36450 I've noticed that build was going on even when image was too small and cptofs was failing but was returning success status. My PR there has been merged, so let's use new version.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Bump lkl version to latest that includes merge of Linux 4.15 and fix for
an issue where cptofs wasn't returning failure when image size was too
small and file copying failed with:

  error writing file: No space left on device

(see lkl/linux#427)
@teto
Copy link
Member

teto commented Mar 15, 2018

I have updated the package in my local copy (because it's messy) with some other additions that you might be interested with:

  • can run the tests. It is disabled by default since you need root but for quick testing in a nix-shell that's good.
  • use make install to install the program
  • also generate a .pc file to use with pkg-config.
{ stdenv, fetchFromGitHub, bc, python, fuse, libarchive,
btrfs-progs ? null, xfsprogs ? null, stress-ng ? null
, pkgconfig
, gnulib
, musl-frankenlibc
, gperf
# when building LKL with dceHost
, dce ? null
}:

# valid values are "dce"/"posix"
# fetch musl
# TODO export dce Headers
{ host ? "posix" }:
stdenv.mkDerivation rec {
  name = "lkl-${version}";
  version= "2018-11-10";
  rev  = "fd7bb8a1c38b0356ffea529de7bae73905d9ca0a";

  outputs = [ "out" "dev" "lib" ];

  nativeBuildInputs = [ bc python pkgconfig ]
  ++ stdenv.lib.optionals doCheck [ btrfs-progs xfsprogs stress-ng ]
  # ++ stdenv.lib.optionals (host == "dce") [dce.dev]
  ;

  buildInputs = [ gperf fuse libarchive gnulib ];

  # src = stdenv.lib.cleanSource /home/teto/lkl;
  src = fetchFromGitHub {
    inherit rev;
    owner  = "lkl";
    repo   = "linux";
    sha256 = "1ssgj89fkhg2waq8vqnq87qaswajbjv3whdvlvxiyq9w0am9ilym";
  };

  # Fix a /usr/bin/env reference in here that breaks sandboxed builds
  prePatch = ''
    patchShebangs arch/lkl/scripts
    patchShebangs tools/lkl
    # extracted from kernel prepatch code
    for mf in $(find -name Makefile -o -name Makefile.include -o -name install.sh); do
        echo "stripping FHS paths in \`$mf'..."
        sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g ; s|/sbin/||g'
    done
  '';

  # preInstall=''
  #   mkdir -p $out/bin
  # '';
  dontAddPrefix = true;
  configurePhase=''
    export buildRoot=$PWD/build
    mkdir $buildRoot
  '';

  # TODO I should be able to pass my own config
  installFlags= [  "PREFIX=\${out}" "DESTDIR=" ];
  makeFlags = ["-C tools/lkl" "O=\"\${buildRoot}\""];
  postInstall = ''
    mkdir -p $lib $dev

    # TODO use $buildRoot instead here !
    mv -v $out/lib $lib
    mv -v $out/include $dev

    # il n'est pas installe de base, upstreamer ?
    cp tools/lkl/bin/lkl-hijack.sh $out/bin

    sed -i $out/bin/lkl-hijack.sh \
        -e "s,LD_LIBRARY_PATH=.*,LD_LIBRARY_PATH=$lib/lib,"

    mkdir -p "$lib/lib/pkgconfig"
    cat >"$lib/lib/pkgconfig/lkl.pc" <<EOF
    prefix=$out
    libdir=$lib/lib
    includedir=$dev/include
    INSTALL_BIN=$out/bin
    INSTALL_INC=$dev/include
    INSTALL_LIB=$lib/lib

    Name: LKL
    Description: The Linux Kernel Library
    Version: ${version}
    Requires:
    Libs: -L$lib/lib -llkl
    Cflags: -I$dev/include
    EOF
  '';

  # We turn off format and fortify because of these errors (fortify implies -O2, which breaks the jitter entropy code):
  #   fs/xfs/xfs_log_recover.c:2575:3: error: format not a string literal and no format arguments [-Werror=format-security]
  #   crypto/jitterentropy.c:54:3: error: #error "The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy.c."
  hardeningDisable = [ "format" "fortify" ];

  enableParallelBuilding = true;

  # will ask for sudo reuseflags ?
  checkPhase=''
    make -C tools/lkl tests
  '';

  # tests require root access so they can't be automated
  doCheck=false;

  meta = with stdenv.lib; {
    description = "The Linux kernel as a library";
    longDescription = ''
      LKL (Linux Kernel Library) aims to allow reusing the Linux kernel code as
      extensively as possible with minimal effort and reduced maintenance
      overhead
    '';
    homepage    = https://github.com/lkl/linux/;
    platforms   = [ "x86_64-linux" "aarch64-linux" ]; # Darwin probably works too but I haven't tested it
    license     = licenses.gpl2;
    maintainers = with maintainers; [ copumpkin ];
  };
}

Also I would like the package to be able to generate the kernel config the nixos way (aka reusing the kernel). It should be easier now that one can override parameters like arch see 3ccc65a

@YorikSar
Copy link
Contributor Author

@teto I think it would be better if you propose your changes in a separate PR. I'm not sure I follow all of them.

@dezgeg dezgeg merged commit 691fe19 into NixOS:master Mar 18, 2018
@YorikSar YorikSar deleted the bump-lkl branch June 8, 2022 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants