nixos/swapspace: add installWrapper option (#368539)

Changed files
+48 -19
nixos
modules
services
system
tests
pkgs
by-name
sw
swapspace
+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"):
+17 -14
pkgs/by-name/sw/swapspace/package.nix
···
nixosTests,
}:
-
stdenv.mkDerivation rec {
+
stdenv.mkDerivation (finalAttrs: {
pname = "swapspace";
version = "1.18.1";
src = fetchFromGitHub {
owner = "Tookmund";
repo = "Swapspace";
-
rev = "v${version}";
+
tag = "v${finalAttrs.version}";
sha256 = "sha256-KrPdmF1H7WFI78ZJlLqDyfxbs7fymSUQpXL+7XjN9bI=";
};
···
install --mode=444 -D 'swapspace.service' "$out/etc/systemd/system/swapspace.service"
'';
-
# Nothing in swapspace --help or swapspace’s man page mentions
-
# anything about swapspace executing its arguments.
-
passthru.binlore.out = binlore.synthesize swapspace ''
-
execer cannot bin/swapspace
-
'';
-
passthru.tests = {
-
inherit (nixosTests) swapspace;
+
passthru = {
+
# Nothing in swapspace --help or swapspace’s man page mentions
+
# anything about swapspace executing its arguments.
+
binlore.out = binlore.synthesize swapspace ''
+
execer cannot bin/swapspace
+
'';
+
tests = {
+
inherit (nixosTests) swapspace;
+
};
};
-
meta = with lib; {
+
meta = {
description = "Dynamic swap manager for Linux";
homepage = "https://github.com/Tookmund/Swapspace";
-
license = licenses.gpl2Only;
-
platforms = platforms.linux;
-
maintainers = with maintainers; [ Luflosi ];
+
changelog = "https://github.com/Tookmund/Swapspace/releases/tag/v${finalAttrs.version}";
mainProgram = "swapspace";
+
license = lib.licenses.gpl2Only;
+
platforms = lib.platforms.linux;
+
maintainers = with lib.maintainers; [ Luflosi ];
};
-
}
+
})