Skip to content

Commit

Permalink
nixos/swapspace: add installWrapper option
Browse files Browse the repository at this point in the history
Signed-off-by: phanirithvij <[email protected]>
Co-authored-by: Luflosi <[email protected]>
  • Loading branch information
phanirithvij and Luflosi committed Dec 27, 2024
1 parent d29066d commit 64b06b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
29 changes: 26 additions & 3 deletions nixos/modules/services/system/swapspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@ let
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 = {
Expand All @@ -28,6 +44,13 @@ in
];
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 {
options = {
Expand Down Expand Up @@ -92,8 +115,8 @@ in
};
};

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" ];
Expand Down
7 changes: 5 additions & 2 deletions nixos/tests/swapspace.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ./make-test-python.nix (
{ pkgs, lib, ... }:
{ lib, ... }:

{
name = "swapspace";

meta = with pkgs.lib.maintainers; {
meta = with lib.maintainers; {
maintainers = [
Luflosi
phanirithvij
Expand Down Expand Up @@ -38,6 +38,9 @@ import ./make-test-python.nix (
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"):
machine.execute("mkdir /root/memfs")
Expand Down

0 comments on commit 64b06b0

Please sign in to comment.