mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 01:53:09 +09:00
nixos/swapspace: add installWrapper option
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com> Co-authored-by: Luflosi <luflosi@luflosi.de>
This commit is contained in:
parent
d29066d0f3
commit
64b06b0a19
2 changed files with 31 additions and 5 deletions
|
@ -9,11 +9,27 @@ let
|
||||||
cfg = config.services.swapspace;
|
cfg = config.services.swapspace;
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
types
|
types
|
||||||
|
mkIf
|
||||||
mkOption
|
mkOption
|
||||||
mkPackageOption
|
mkPackageOption
|
||||||
mkEnableOption
|
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
|
in
|
||||||
{
|
{
|
||||||
options.services.swapspace = {
|
options.services.swapspace = {
|
||||||
|
@ -28,6 +44,13 @@ in
|
||||||
];
|
];
|
||||||
description = "Any extra arguments to pass to swapspace";
|
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 {
|
settings = mkOption {
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -92,8 +115,8 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ (if cfg.installWrapper then userWrapper else cfg.package) ];
|
||||||
systemd.packages = [ cfg.package ];
|
systemd.packages = [ cfg.package ];
|
||||||
systemd.services.swapspace = {
|
systemd.services.swapspace = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import ./make-test-python.nix (
|
import ./make-test-python.nix (
|
||||||
{ pkgs, lib, ... }:
|
{ lib, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "swapspace";
|
name = "swapspace";
|
||||||
|
|
||||||
meta = with pkgs.lib.maintainers; {
|
meta = with lib.maintainers; {
|
||||||
maintainers = [
|
maintainers = [
|
||||||
Luflosi
|
Luflosi
|
||||||
phanirithvij
|
phanirithvij
|
||||||
|
@ -38,6 +38,9 @@ import ./make-test-python.nix (
|
||||||
machine.wait_for_unit("swapspace.service")
|
machine.wait_for_unit("swapspace.service")
|
||||||
machine.wait_for_unit("root-swapfile.swap")
|
machine.wait_for_unit("root-swapfile.swap")
|
||||||
|
|
||||||
|
# ensure swapspace wrapper command runs
|
||||||
|
machine.succeed("swapspace --inspect")
|
||||||
|
|
||||||
swamp = False
|
swamp = False
|
||||||
with subtest("swapspace works"):
|
with subtest("swapspace works"):
|
||||||
machine.execute("mkdir /root/memfs")
|
machine.execute("mkdir /root/memfs")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue