nixos/swapspace: add installWrapper option

Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
Co-authored-by: Luflosi <luflosi@luflosi.de>

Changed files
+31 -5
nixos
modules
services
system
tests
+26 -3
nixos/modules/services/system/swapspace.nix
···
cfg = config.services.swapspace;
inherit (lib)
types
+
mkIf
mkOption
mkPackageOption
mkEnableOption
;
-
configFile = pkgs.writeText "swapspace.conf" (lib.generators.toKeyValue { } cfg.settings);
+
inherit (pkgs)
+
makeWrapper
+
runCommand
+
writeText
+
;
+
configFile = writeText "swapspace.conf" (lib.generators.toKeyValue { } cfg.settings);
+
userWrapper =
+
runCommand "swapspace"
+
{
+
buildInputs = [ makeWrapper ];
+
}
+
''
+
mkdir -p "$out/bin"
+
makeWrapper '${lib.getExe cfg.package}' "$out/bin/swapspace" \
+
--add-flags "-c '${configFile}'"
+
'';
in
{
options.services.swapspace = {
···
"-v"
];
description = "Any extra arguments to pass to swapspace";
+
};
+
installWrapper = mkOption {
+
type = types.bool;
+
default = true;
+
description = ''
+
This will add swapspace wrapped with the generated config, to environment.systemPackages
+
'';
};
settings = mkOption {
type = types.submodule {
···
};
};
-
config = lib.mkIf cfg.enable {
-
environment.systemPackages = [ cfg.package ];
+
config = mkIf cfg.enable {
+
environment.systemPackages = [ (if cfg.installWrapper then userWrapper else cfg.package) ];
systemd.packages = [ cfg.package ];
systemd.services.swapspace = {
wantedBy = [ "multi-user.target" ];
+5 -2
nixos/tests/swapspace.nix
···
import ./make-test-python.nix (
-
{ pkgs, lib, ... }:
+
{ lib, ... }:
{
name = "swapspace";
-
meta = with pkgs.lib.maintainers; {
+
meta = with lib.maintainers; {
maintainers = [
Luflosi
phanirithvij
···
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("swapspace.service")
machine.wait_for_unit("root-swapfile.swap")
+
+
# ensure swapspace wrapper command runs
+
machine.succeed("swapspace --inspect")
swamp = False
with subtest("swapspace works"):