diff options
author | Ryan Lahfa <masterancpp@gmail.com> | 2023-05-17 11:38:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-17 11:38:48 +0200 |
commit | d4abba5c1e8dfb3d2d88160a42071070537412be (patch) | |
tree | c977d4af77bbc941f44b1a2b883c10de6b758676 /nixos | |
parent | e5fc07cb229ec85676de1e7bb778dee13259bfc4 (diff) | |
parent | 4101d3b56fed568b8ec52046f13bd57c9ba266f9 (diff) |
Merge pull request #232243 from mklca/issue-232229
nixos/config/swap: resolve swapfile issue !232229
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/config/swap.nix | 11 | ||||
-rw-r--r-- | nixos/tests/swap-file-btrfs.nix | 4 |
2 files changed, 9 insertions, 6 deletions
diff --git a/nixos/modules/config/swap.nix b/nixos/modules/config/swap.nix index 5c812a9226e84..0a7e45bffb267 100644 --- a/nixos/modules/config/swap.nix +++ b/nixos/modules/config/swap.nix @@ -275,12 +275,11 @@ in ''} ${optionalString sw.randomEncryption.enable '' cryptsetup plainOpen -c ${sw.randomEncryption.cipher} -d ${sw.randomEncryption.source} \ - '' + concatMapStrings (arg: arg + " \\\n") (flatten [ - (optional (sw.randomEncryption.sectorSize != null) "--sector-size=${toString sw.randomEncryption.sectorSize}") - (optional (sw.randomEncryption.keySize != null) "--key-size=${toString sw.randomEncryption.keySize}") - (optional sw.randomEncryption.allowDiscards "--allow-discards") - ]) + '' - ${sw.device} ${sw.deviceName} + ${concatStringsSep " \\\n" (flatten [ + (optional (sw.randomEncryption.sectorSize != null) "--sector-size=${toString sw.randomEncryption.sectorSize}") + (optional (sw.randomEncryption.keySize != null) "--key-size=${toString sw.randomEncryption.keySize}") + (optional sw.randomEncryption.allowDiscards "--allow-discards") + ])} ${sw.device} ${sw.deviceName} mkswap ${sw.realDevice} ''} ''; diff --git a/nixos/tests/swap-file-btrfs.nix b/nixos/tests/swap-file-btrfs.nix index d9fcd2be1160a..35b9fb4fa50ac 100644 --- a/nixos/tests/swap-file-btrfs.nix +++ b/nixos/tests/swap-file-btrfs.nix @@ -32,6 +32,8 @@ import ./make-test-python.nix ({ lib, ... }: testScript = '' machine.wait_for_unit('var-swapfile.swap') + # Ensure the swap file creation script ran to completion without failing when creating the swap file + machine.fail("systemctl is-failed --quiet mkswap-var-swapfile.service") machine.succeed("stat --file-system --format=%T /var/swapfile | grep btrfs") # First run. Auto creation. machine.succeed("swapon --show | grep /var/swapfile") @@ -41,6 +43,8 @@ import ./make-test-python.nix ({ lib, ... }: # Second run. Use it as-is. machine.wait_for_unit('var-swapfile.swap') + # Ensure the swap file creation script ran to completion without failing when the swap file already exists + machine.fail("systemctl is-failed --quiet mkswap-var-swapfile.service") machine.succeed("swapon --show | grep /var/swapfile") ''; }) |