summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2021-07-23 10:45:53 +0200
committerGitHub <noreply@github.com>2021-07-23 10:45:53 +0200
commit98352288bd3c314a1a53c2da52b98931b694dd39 (patch)
treea51c4ff157b2cba8201bedd5a521235cb4596a84
parenta6d966aeacd10a0e2a887e218f9b0c7df6356cae (diff)
parentc971de97c4146a052b731fd47babc8be395ffdf0 (diff)
downloadnixpkgs-98352288bd3c314a1a53c2da52b98931b694dd39.tar
nixpkgs-98352288bd3c314a1a53c2da52b98931b694dd39.tar.gz
nixpkgs-98352288bd3c314a1a53c2da52b98931b694dd39.tar.bz2
nixpkgs-98352288bd3c314a1a53c2da52b98931b694dd39.tar.lz
nixpkgs-98352288bd3c314a1a53c2da52b98931b694dd39.tar.xz
nixpkgs-98352288bd3c314a1a53c2da52b98931b694dd39.tar.zst
nixpkgs-98352288bd3c314a1a53c2da52b98931b694dd39.zip
Merge pull request #128032 from Artturin/add-swap-options
nixos/swap: add options option
-rw-r--r--lib/types.nix7
-rw-r--r--nixos/modules/config/swap.nix9
-rw-r--r--nixos/modules/tasks/filesystems.nix2
3 files changed, 17 insertions, 1 deletions
diff --git a/lib/types.nix b/lib/types.nix
index c35f055e17f..a0be2ff3a45 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}";
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}"}"
         );