Merge pull request #232243 from mklca/issue-232229

nixos/config/swap: resolve swapfile issue !232229
This commit is contained in:
Ryan Lahfa 2023-05-17 11:38:48 +02:00 committed by GitHub
commit d4abba5c1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -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}
''}
'';

View file

@ -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")
'';
})