1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-18 11:40:45 +00:00
nixpkgs/pkgs/tools/system/zram-generator/default.nix
Alyssa Ross e3e57b8f18 lib.systems: elaborate Rust metadata
We need this stuff to be available in lib so make-derivation.nix can
access it to construct the Meson cross file.

This has a couple of other advantages:

 - It makes Rust less special.  Now figuring out what Rust calls a
   platform is the same as figuring out what Linux or QEMU call it.

 - We can unify the schema used to define Rust targets, and the schema
   used to access those values later.  Just like you can set "config"
   or "system" in a platform definition, and then access those same
   keys on the elaborated platform, you can now set "rustcTarget" in
   your crossSystem, and then access "stdenv.hostPlatform.rustcTarget"
   in your code.

"rustcTarget", "rustcTargetSpec", "cargoShortTarget", and
"cargoEnvVarTarget" have the "rustc" and "cargo" prefixes because
these are not exposed to code by the compiler, and are not
standardized.  The arch/os/etc. variables are all named to match the
forms in the Rust target spec JSON.

The new rust.target-family only takes a list, since we don't need to
worry about backwards compatibility when that name is used.

The old APIs are all still functional with no warning for now, so that
it's possible for external code to use a single API on both 23.05 and
23.11.  We can introduce the warnings once 23.05 is EOL, and make them
hard errors when 23.11 is EOL.
2023-11-09 10:02:24 +01:00

74 lines
1.8 KiB
Nix

{ lib
, stdenv
, fetchFromGitHub
, rustPlatform
, pkg-config
, ronn
, systemd
, kmod
, nixosTests
}:
rustPlatform.buildRustPackage rec {
pname = "zram-generator";
version = "1.1.2";
src = fetchFromGitHub {
owner = "systemd";
repo = pname;
rev = "v${version}";
hash = "sha256-n+ZOWU+sPq9DcHgzQWTxxfMmiz239qdetXypqdy33cM=";
};
# RFE: Include Cargo.lock in sources
# https://github.com/systemd/zram-generator/issues/65
cargoLock.lockFile = ./Cargo.lock;
postPatch = ''
cp ${./Cargo.lock} Cargo.lock
substituteInPlace Makefile \
--replace 'target/$(BUILDTYPE)' 'target/${stdenv.hostPlatform.rust.rustcTargetSpec}/$(BUILDTYPE)'
substituteInPlace src/generator.rs \
--replace 'Command::new("systemd-detect-virt")' 'Command::new("${systemd}/bin/systemd-detect-virt")' \
--replace 'Command::new("modprobe")' 'Command::new("${kmod}/bin/modprobe")'
'';
nativeBuildInputs = [
pkg-config
ronn
];
buildInputs = [
systemd
];
preBuild = ''
# embedded into the binary at build time
# https://github.com/systemd/zram-generator/blob/v1.1.2/Makefile#LL11-L11C56
export SYSTEMD_UTIL_DIR=$($PKG_CONFIG --variable=systemdutildir systemd)
'';
dontCargoInstall = true;
installFlags = [
"-o program" # already built by cargoBuildHook
"PREFIX=$(out)"
"SYSTEMD_SYSTEM_UNIT_DIR=$(out)/lib/systemd/system"
"SYSTEMD_SYSTEM_GENERATOR_DIR=$(out)/lib/systemd/system-generators"
];
passthru = {
tests = {
inherit (nixosTests) zram-generator;
};
updateScript = ./update.sh;
};
meta = with lib; {
homepage = "https://github.com/systemd/zram-generator";
license = licenses.mit;
description = "Systemd unit generator for zram devices";
maintainers = with maintainers; [ nickcao ];
};
}