about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/system/zram-generator/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/tools/system/zram-generator/default.nix')
-rw-r--r--nixpkgs/pkgs/tools/system/zram-generator/default.nix74
1 files changed, 74 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/tools/system/zram-generator/default.nix b/nixpkgs/pkgs/tools/system/zram-generator/default.nix
new file mode 100644
index 000000000000..81bf4082d5c1
--- /dev/null
+++ b/nixpkgs/pkgs/tools/system/zram-generator/default.nix
@@ -0,0 +1,74 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, rust
+, 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/${rust.toRustTargetSpec stdenv.hostPlatform}/$(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 ];
+  };
+}