1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2025-01-05 19:03:21 +03:00
mobile-nixos/modules/zram.nix
2022-10-12 20:28:37 -04:00

32 lines
1.0 KiB
Nix

#
# Workarounds for using zram with mayby non-module kernels.
#
# (Not upstreamed to Nixpkgs since it assumes breakage in NixOS's assumptions.)
#
{ config, lib, pkgs, ... }:
let
modprobe = "${pkgs.kmod}/bin/modprobe";
in
{
config = lib.mkIf config.zramSwap.enable {
systemd.services.zram-reloader.serviceConfig = {
ExecStartPre = lib.mkForce (pkgs.writeShellScript "zram-reloader-start-pre" ''
if ${pkgs.gzip}/bin/zcat /proc/config.gz | ${pkgs.gnugrep}/bin/grep -q ^CONFIG_ZRAM=m; then
${modprobe} -r zram
fi
'');
ExecStart = lib.mkForce (pkgs.writeShellScript "zram-reloader-start" ''
if ${pkgs.gzip}/bin/zcat /proc/config.gz | ${pkgs.gnugrep}/bin/grep -q ^CONFIG_ZRAM=m; then
${modprobe} zram
fi
'');
ExecStop = lib.mkForce (pkgs.writeShellScript "zram-reloader-stop" ''
if ${pkgs.gzip}/bin/zcat /proc/config.gz | ${pkgs.gnugrep}/bin/grep -q ^CONFIG_ZRAM=m; then
${modprobe} -r zram
fi
'');
};
};
}