diff --git a/nixos/modules/services/system/earlyoom.nix b/nixos/modules/services/system/earlyoom.nix index bcdf7d6512d5..7e012dee02cb 100644 --- a/nixos/modules/services/system/earlyoom.nix +++ b/nixos/modules/services/system/earlyoom.nix @@ -4,15 +4,29 @@ let cfg = config.services.earlyoom; inherit (lib) - mkDefault mkEnableOption mkIf mkOption types - mkRemovedOptionModule literalExpression - escapeShellArg concatStringsSep optional optionalString; - + concatStringsSep + escapeShellArg + literalExpression + mkDefault + mkEnableOption + mkIf + mkOption + mkPackageOption + mkRemovedOptionModule + optionalString + optionals + types; in { + meta = { + maintainers = with lib.maintainers; [ AndersonTorres ]; + }; + options.services.earlyoom = { enable = mkEnableOption "early out of memory killing"; + package = mkPackageOption pkgs "earlyoom" { }; + freeMemThreshold = mkOption { type = types.ints.between 1 100; default = 10; @@ -138,22 +152,21 @@ in systemd.services.earlyoom = { description = "Early OOM Daemon for Linux"; wantedBy = [ "multi-user.target" ]; - path = optional cfg.enableNotifications pkgs.dbus; + path = optionals cfg.enableNotifications [ pkgs.dbus ]; serviceConfig = { StandardError = "journal"; ExecStart = concatStringsSep " " ([ - "${pkgs.earlyoom}/bin/earlyoom" + "${lib.getExe cfg.package}" ("-m ${toString cfg.freeMemThreshold}" - + optionalString (cfg.freeMemKillThreshold != null) ",${toString cfg.freeMemKillThreshold}") + + optionalString (cfg.freeMemKillThreshold != null) ",${toString cfg.freeMemKillThreshold}") ("-s ${toString cfg.freeSwapThreshold}" - + optionalString (cfg.freeSwapKillThreshold != null) ",${toString cfg.freeSwapKillThreshold}") + + optionalString (cfg.freeSwapKillThreshold != null) ",${toString cfg.freeSwapKillThreshold}") "-r ${toString cfg.reportInterval}" ] - ++ optional cfg.enableDebugInfo "-d" - ++ optional cfg.enableNotifications "-n" - ++ optional (cfg.killHook != null) "-N ${escapeShellArg cfg.killHook}" - ++ cfg.extraArgs - ); + ++ optionals cfg.enableDebugInfo [ "-d" ] + ++ optionals cfg.enableNotifications [ "-n" ] + ++ optionals (cfg.killHook != null) [ "-N ${escapeShellArg cfg.killHook}" ] + ++ cfg.extraArgs); }; }; }; diff --git a/nixos/tests/earlyoom.nix b/nixos/tests/earlyoom.nix index 75bdf56899b3..b7850ddeaaab 100644 --- a/nixos/tests/earlyoom.nix +++ b/nixos/tests/earlyoom.nix @@ -1,7 +1,7 @@ import ./make-test-python.nix ({ lib, ... }: { name = "earlyoom"; meta = { - maintainers = with lib.maintainers; [ ncfavier ]; + maintainers = with lib.maintainers; [ ncfavier AndersonTorres ]; }; machine = { diff --git a/pkgs/os-specific/linux/earlyoom/fix-dbus-path.patch b/pkgs/by-name/ea/earlyoom/0000-fix-dbus-path.patch similarity index 100% rename from pkgs/os-specific/linux/earlyoom/fix-dbus-path.patch rename to pkgs/by-name/ea/earlyoom/0000-fix-dbus-path.patch diff --git a/pkgs/by-name/ea/earlyoom/package.nix b/pkgs/by-name/ea/earlyoom/package.nix new file mode 100644 index 000000000000..ba69b72b3bab --- /dev/null +++ b/pkgs/by-name/ea/earlyoom/package.nix @@ -0,0 +1,64 @@ +{ + lib, + fetchFromGitHub, + installShellFiles, + pandoc, + stdenv, + nixosTests, + # Boolean flags + withManpage ? true, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "earlyoom"; + version = "1.8"; + + src = fetchFromGitHub { + owner = "rfjakob"; + repo = "earlyoom"; + rev = "v${finalAttrs.version}"; + hash = "sha256-jgNoYOGor2i3ngDuU3It238n5ky+AppzlRKdkwXb2AI="; + }; + + outputs = [ "out" ] ++ lib.optionals withManpage [ "man" ]; + + patches = [ ./0000-fix-dbus-path.patch ]; + + nativeBuildInputs = lib.optionals withManpage [ + installShellFiles + pandoc + ]; + + makeFlags = [ + "VERSION=${finalAttrs.version}" + ]; + + installPhase = '' + runHook preInstall + install -D earlyoom $out/bin/earlyoom + '' + lib.optionalString withManpage '' + installManPage earlyoom.1 + '' + '' + runHook postInstall + ''; + + passthru.tests = { + inherit (nixosTests) earlyoom; + }; + + meta = { + homepage = "https://github.com/rfjakob/earlyoom"; + description = "Early OOM Daemon for Linux"; + longDescription = '' + earlyoom checks the amount of available memory and free swap up to 10 + times a second (less often if there is a lot of free memory). By default + if both are below 10%, it will kill the largest process (highest + oom_score). The percentage value is configurable via command line + arguments. + ''; + license = lib.licenses.mit; + mainProgram = "earlyoom"; + maintainers = with lib.maintainers; [ AndersonTorres ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/os-specific/linux/earlyoom/default.nix b/pkgs/os-specific/linux/earlyoom/default.nix deleted file mode 100644 index d1d95b4d3f95..000000000000 --- a/pkgs/os-specific/linux/earlyoom/default.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ lib, stdenv, fetchFromGitHub, pandoc, installShellFiles, withManpage ? false, nixosTests }: - -stdenv.mkDerivation rec { - pname = "earlyoom"; - version = "1.7"; - - src = fetchFromGitHub { - owner = "rfjakob"; - repo = "earlyoom"; - rev = "v${version}"; - sha256 = "sha256-8YcT1TTlAet7F1U9Ginda4IApNqkudegOXqm8rnRGfc="; - }; - - nativeBuildInputs = lib.optionals withManpage [ pandoc installShellFiles ]; - - patches = [ ./fix-dbus-path.patch ]; - - makeFlags = [ "VERSION=${version}" ]; - - installPhase = '' - install -D earlyoom $out/bin/earlyoom - '' + lib.optionalString withManpage '' - installManPage earlyoom.1 - ''; - - passthru.tests = { - inherit (nixosTests) earlyoom; - }; - - meta = with lib; { - description = "Early OOM Daemon for Linux"; - mainProgram = "earlyoom"; - homepage = "https://github.com/rfjakob/earlyoom"; - license = licenses.mit; - platforms = platforms.linux; - maintainers = with maintainers; []; - }; -} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a57aded5818e..f51ecb16d0b2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5130,8 +5130,6 @@ with pkgs; earlybird = callPackage ../tools/security/earlybird { }; - earlyoom = callPackage ../os-specific/linux/earlyoom { }; - easyabc = callPackage ../applications/audio/easyabc { }; easycrypt = callPackage ../applications/science/logic/easycrypt {