From a3c5f0cba8fa9c4d9782ef83757be6e4028f54b7 Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 20 Jul 2021 05:17:35 +0300 Subject: [PATCH 1/2] lib/types.nix: add nonEmptyStr --- lib/types.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/types.nix b/lib/types.nix index f47a1f92de7..68262951a13 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -287,6 +287,13 @@ rec { merge = mergeEqualOption; }; + nonEmptyStr = mkOptionType { + name = "nonEmptyStr"; + description = "non-empty string"; + check = x: str.check x && builtins.match "[ \t\n]*" x == null; + inherit (str) merge; + }; + strMatching = pattern: mkOptionType { name = "strMatching ${escapeNixString pattern}"; description = "string matching the pattern ${pattern}"; From c971de97c4146a052b731fd47babc8be395ffdf0 Mon Sep 17 00:00:00 2001 From: Artturin Date: Thu, 24 Jun 2021 20:58:18 +0300 Subject: [PATCH 2/2] nixos/swap: add options option --- nixos/modules/config/swap.nix | 9 +++++++++ nixos/modules/tasks/filesystems.nix | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nixos/modules/config/swap.nix b/nixos/modules/config/swap.nix index a37b46b8c46..9b64d5287a1 100644 --- a/nixos/modules/config/swap.nix +++ b/nixos/modules/config/swap.nix @@ -127,6 +127,15 @@ let ''; }; + options = mkOption { + default = [ "defaults" ]; + example = [ "nofail" ]; + type = types.listOf types.nonEmptyStr; + description = '' + Options used to mount the swap. + ''; + }; + deviceName = mkOption { type = types.str; internal = true; diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index d274a38a270..2f17608560f 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -255,7 +255,7 @@ in # https://wiki.archlinux.org/index.php/fstab#Filepath_spaces escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string; swapOptions = sw: concatStringsSep "," ( - [ "defaults" ] + sw.options ++ optional (sw.priority != null) "pri=${toString sw.priority}" ++ optional (sw.discardPolicy != null) "discard${optionalString (sw.discardPolicy != "both") "=${toString sw.discardPolicy}"}" );