使用 stripeTabs

This commit is contained in:
2023-07-22 00:14:07 +08:00
parent 1e2fd98bd0
commit 30ca432712
3 changed files with 12 additions and 12 deletions

View File

@@ -189,9 +189,9 @@
};
boot.grub =
{
entries =
''
menuentry "Windows" {
entries = localLib.stripeTabs
"
menuentry \"Windows\" {
insmod part_gpt
insmod fat
insmod search_fs_uuid
@@ -199,7 +199,7 @@
search --fs-uuid --set=root 7317-1DB6
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
menuentry "Windows for malware" {
menuentry \"Windows for malware\" {
insmod part_gpt
insmod fat
insmod search_fs_uuid
@@ -207,7 +207,7 @@
search --fs-uuid --set=root 7321-FA9C
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
'';
";
installDevice = "efi";
};
system =

View File

@@ -53,12 +53,12 @@ lib:
stripeTabs = text:
let
# Whether all lines start with a tab (or is empty)
shouldStripTab = lines: builtins.all (line: (line == "") || (pkgs.lib.strings.hasPrefix " " line)) lines;
shouldStripTab = lines: builtins.all (line: (line == "") || (lib.strings.hasPrefix " " line)) lines;
# Strip a leading tab from all lines
stripTab = lines: builtins.map (line: pkgs.lib.strings.removePrefix " " line) lines;
stripTab = lines: builtins.map (line: lib.strings.removePrefix " " line) lines;
# Strip tabs recursively until there are none
stripTabs = lines: if (shouldStripTab lines) then (stripTabs (stripTab lines)) else lines;
in
# Split into lines. Strip leading tabs. Concat back to string.
builtins.concatStringsSep "\n" (stripTabs (pkgs.lib.strings.splitString "\n" text));
builtins.concatStringsSep "\n" (stripTabs (lib.strings.splitString "\n" text));
}

View File

@@ -24,7 +24,7 @@ inputs:
path = mkOption { type = types.nonEmptyStr; };
}; }); };
};
config = let inherit (inputs.lib) mkMerge mkIf; in mkMerge
config = let inherit (inputs.lib) mkMerge mkIf; inherit (inputs.localLib) stripeTabs; in mkMerge
[
# mount.vfat
{
@@ -105,8 +105,8 @@ inputs:
before = [ "local-fs-pre.target" ];
unitConfig.DefaultDependencies = false;
serviceConfig.Type = "oneshot";
script = let inherit (inputs.config.nixos.fileSystems.rollingRootfs) device path; in
''
script = let inherit (inputs.config.nixos.fileSystems.rollingRootfs) device path; in stripeTabs
"
mount ${device} /mnt -m
if [ -f /mnt${path}/current/.timestamp ]
then
@@ -115,7 +115,7 @@ inputs:
btrfs subvolume create /mnt${path}/current
echo $(date '+%Y%m%d%H%M%S') > /mnt${path}/current/.timestamp
umount /mnt
'';
";
};
}
)