nixpkgs/pkgs/tools/system/zram-generator/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.8 KiB
Nix
Raw Normal View History

2023-01-11 12:33:30 +01:00
{ lib
, stdenv
, fetchFromGitHub
, rustPlatform
, pkg-config
, ronn
, systemd
, kmod
2023-01-18 15:40:42 +01:00
, nixosTests
2023-01-11 12:33:30 +01:00
}:
rustPlatform.buildRustPackage rec {
2023-01-11 12:33:30 +01:00
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;
2023-01-11 12:33:30 +01:00
postPatch = ''
cp ${./Cargo.lock} Cargo.lock
substituteInPlace Makefile \
--replace 'target/$(BUILDTYPE)' 'target/${stdenv.hostPlatform.rust.rustcTargetSpec}/$(BUILDTYPE)'
2023-01-11 12:33:30 +01:00
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 = [
2023-01-11 12:33:30 +01:00
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
2023-01-11 12:33:30 +01:00
"PREFIX=$(out)"
"SYSTEMD_SYSTEM_UNIT_DIR=$(out)/lib/systemd/system"
"SYSTEMD_SYSTEM_GENERATOR_DIR=$(out)/lib/systemd/system-generators"
];
2023-02-02 03:53:10 +01:00
passthru = {
tests = {
inherit (nixosTests) zram-generator;
};
updateScript = ./update.sh;
2023-01-18 15:40:42 +01:00
};
2023-01-11 12:33:30 +01:00
meta = with lib; {
homepage = "https://github.com/systemd/zram-generator";
license = licenses.mit;
description = "Systemd unit generator for zram devices";
maintainers = with maintainers; [ nickcao ];
};
}