swapspace: patch paths to binaries and install systemd unit file

This will be useful when creating a NixOS module for this program.
This commit is contained in:
Luflosi 2023-04-04 13:20:32 +02:00
parent b0004e6c97
commit 82dd065f7a
No known key found for this signature in database
GPG Key ID: 4E41E29EDCC345D0

View File

@ -1,4 +1,4 @@
{ lib, stdenv, fetchFromGitHub, autoreconfHook, installShellFiles }:
{ lib, stdenv, fetchFromGitHub, autoreconfHook, installShellFiles, util-linux }:
stdenv.mkDerivation rec {
pname = "swapspace";
@ -16,8 +16,23 @@ stdenv.mkDerivation rec {
installShellFiles
];
postPatch = ''
substituteInPlace 'swapspace.service' \
--replace '/usr/local/sbin/' "$out/bin/"
substituteInPlace 'src/support.c' \
--replace '/sbin/swapon' '${lib.getBin util-linux}/bin/swapon' \
--replace '/sbin/swapoff' '${lib.getBin util-linux}/bin/swapoff'
substituteInPlace 'src/swaps.c' \
--replace 'mkswap' '${lib.getBin util-linux}/bin/mkswap'
# Don't create empty directory $out/var/lib/swapspace
substituteInPlace 'Makefile.am' \
--replace 'install-data-local:' 'do-not-execute:'
'';
postInstall = ''
installManPage doc/swapspace.8
install --mode=444 -D 'swapspace.service' "$out/etc/systemd/system/swapspace.service"
'';
meta = with lib; {