mirror of
https://github.com/CHN-beta/nixos.git
synced 2024-10-23 11:29:06 +08:00
整理完成 filesystem
This commit is contained in:
parent
f1200943bb
commit
a36922f81d
@ -136,7 +136,7 @@
|
||||
btrfs =
|
||||
{
|
||||
"/dev/disk/by-uuid/02e426ec-cfa2-4a18-b3a5-57ef04d66614"."/" = "/boot";
|
||||
"/dev/mapper/root"."/nix" = "/nix";
|
||||
"/dev/mapper/root" = { "/nix" = "/nix"; "/nix/rootfs/current" = "/"; };
|
||||
};
|
||||
};
|
||||
decrypt.auto =
|
||||
@ -148,6 +148,7 @@
|
||||
"ARRAY /dev/md/swap metadata=1.2 name=chn-PC:swap UUID=2b546b8d:e38007c8:02990dd1:df9e23a4";
|
||||
swap = [ "/dev/mapper/swap" ];
|
||||
resume = "/dev/mapper/swap";
|
||||
rollingRootfs = { device = "/dev/mapper/root"; path = "/nix/rootfs"; };
|
||||
};
|
||||
};}
|
||||
)
|
||||
|
@ -3,12 +3,6 @@ inputs:
|
||||
config =
|
||||
{
|
||||
# filesystem mount
|
||||
fileSystems."/" =
|
||||
{
|
||||
device = "/dev/mapper/root";
|
||||
fsType = "btrfs";
|
||||
options = [ "subvol=nix/rootfs/current" "compress-force=zstd" ];
|
||||
};
|
||||
# sudo btrfs fi mkswapfile --size 64g --uuid clear swap
|
||||
# sudo btrfs inspect-internal map-swapfile -r swap
|
||||
# sudo mdadm --create /dev/md/swap --level 0 --raid-devices 2 /dev/nvme1n1p5 /dev/nvme0n1p5
|
||||
@ -99,29 +93,7 @@ inputs:
|
||||
# initrd, luks
|
||||
boot.initrd =
|
||||
{
|
||||
systemd =
|
||||
{
|
||||
enable = true;
|
||||
services.create-current-rootfs =
|
||||
{
|
||||
wantedBy = [ "local-fs-pre.target" ];
|
||||
after = [ "cryptsetup.target" ];
|
||||
before = [ "local-fs-pre.target" ];
|
||||
unitConfig.DefaultDependencies = false;
|
||||
serviceConfig.Type = "oneshot";
|
||||
script =
|
||||
''
|
||||
mount /dev/mapper/root /mnt -m
|
||||
if [ -f /mnt/nix/rootfs/current/.timestamp ]
|
||||
then
|
||||
mv /mnt/nix/rootfs/current /mnt/nix/rootfs/$(cat /mnt/nix/rootfs/current/.timestamp)
|
||||
fi
|
||||
btrfs subvolume create /mnt/nix/rootfs/current
|
||||
echo $(date '+%Y%m%d%H%M%S') > /mnt/nix/rootfs/current/.timestamp
|
||||
umount /mnt
|
||||
'';
|
||||
};
|
||||
};
|
||||
systemd.enable = true;
|
||||
# modules in initrd
|
||||
# modprobe --show-depends
|
||||
availableKernelModules =
|
||||
|
@ -18,18 +18,11 @@ inputs:
|
||||
swap = mkOption { type = types.listOf types.nonEmptyStr; };
|
||||
resume = mkOption { type = types.nullOr (types.str or (types.submodule { options =
|
||||
{ device = mkOption { type = types.nonEmptyStr; }; offset = mkOption { type = types.ints.unsigned; }; }; })); };
|
||||
# cleanRootfs = mkOption { type = types.nullOr
|
||||
|
||||
# swap and resume
|
||||
# swap != resume.device if swap is a file
|
||||
# swap = mkOption { type = types.nullOr types.str; };
|
||||
# resume =
|
||||
# {
|
||||
# device = mkOption { type = types.nullOr types.str; };
|
||||
# # sudo btrfs fi mkswapfile --size 64g --uuid clear swap
|
||||
# # sudo btrfs inspect-internal map-swapfile -r swap
|
||||
# offset = mkOption { type = types.nullOr types.ints.unsigned; };
|
||||
# };
|
||||
rollingRootfs = mkOption { type = types.nullOr (types.submodule { options =
|
||||
{
|
||||
device = mkOption { type = types.nonEmptyStr; };
|
||||
path = mkOption { type = types.nonEmptyStr; };
|
||||
}; }); };
|
||||
};
|
||||
config =
|
||||
{
|
||||
@ -91,6 +84,31 @@ inputs:
|
||||
if inputs.config.nixos.fileSystems.mdadm != null then
|
||||
{ services.swraid = { enable = true; mdadmConf = inputs.config.nixos.fileSystems.mdadm; }; }
|
||||
else {}
|
||||
)
|
||||
// (
|
||||
if inputs.config.nixos.fileSystems.rollingRootfs != null then
|
||||
{
|
||||
systemd.services.roll-rootfs =
|
||||
{
|
||||
wantedBy = [ "local-fs-pre.target" ];
|
||||
after = [ "cryptsetup.target" ];
|
||||
before = [ "local-fs-pre.target" ];
|
||||
unitConfig.DefaultDependencies = false;
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = let inherit (inputs.config.nixos.fileSystems.rollingRootfs) device path; in
|
||||
''
|
||||
mount ${device} /mnt
|
||||
if [ -f /mnt${path}/current/.timestamp ]
|
||||
then
|
||||
mv /mnt${path}/current /mnt${path}/$(cat /mnt${path}/current/.timestamp)
|
||||
fi
|
||||
btrfs subvolume create /mnt${path}/current
|
||||
echo $(date '+%Y%m%d%H%M%S') > /mnt${path}/current/.timestamp
|
||||
umount /mnt
|
||||
'';
|
||||
};
|
||||
}
|
||||
else {}
|
||||
);
|
||||
}
|
||||
// (
|
||||
|
Loading…
Reference in New Issue
Block a user