update flake.lock; refactor impermanence; other minor fixes

This commit is contained in:
2026-02-24 16:50:17 +08:00
parent 12c56e2283
commit 8c10af7f58
10 changed files with 159 additions and 169 deletions
+1
View File
@@ -24,6 +24,7 @@ in
vimdiffAlias = true;
withPython3 = false;
withRuby = false;
sideloadInitLua = true;
extraPackages = with pkgs; [
# treesitter
tree-sitter
+1 -1
View File
@@ -16,7 +16,7 @@ in
my.hm.home.packages = with pkgs; [
go
gotools
gopls
(lib.hiPrio gopls)
];
my.persist.homeDirs = [
"go"
+87 -10
View File
@@ -10,15 +10,35 @@ in
{
options.my.persist = {
enable = lib.mkEnableOption "persist";
location = lib.mkOption {
type = lib.types.str;
default = "/nix/persist";
example = lib.literalExpression ''
"/persistent"
'';
description = lib.mdDoc ''
Persistent location
'';
btrfs = lib.mkOption {
type = lib.types.submodule (
{ ... }:
{
options = {
device = lib.mkOption {
type = lib.types.str;
};
zstdCompress = lib.mkOption {
type = lib.types.bool;
default = true;
};
persistSubvol = lib.mkOption {
type = lib.types.str;
};
rootSubvol = lib.mkOption {
type = lib.types.str;
default = "root";
};
mountPoint = lib.mkOption {
type = lib.types.str;
default = "/nix/persist";
example = lib.literalExpression ''
"/persistent"
'';
};
};
}
);
};
homeDirs = lib.mkOption {
default = [ ];
@@ -69,8 +89,65 @@ in
};
config = lib.mkIf cfg.enable {
fileSystems.${cfg.btrfs.mountPoint} = {
device = cfg.btrfs.device;
fsType = "btrfs";
options = [
"subvol=${cfg.btrfs.persistSubvol}"
]
++ lib.optionals cfg.btrfs.zstdCompress [
"compress=zstd"
];
neededForBoot = true;
};
fileSystems."/" = {
device = cfg.btrfs.device;
fsType = "btrfs";
options = [
"subvol=${cfg.btrfs.rootSubvol}"
]
++ lib.optionals cfg.btrfs.zstdCompress [
"compress=zstd"
];
};
boot.initrd.systemd.services.wipe-root = {
description = "Rollback BTRFS rootfs";
wantedBy = [ "initrd.target" ];
before = [ "sysroot.mount" ];
after = [ "initrd-root-device.target" ];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /btrfs_tmp
mount ${cfg.btrfs.device} /btrfs_tmp
mkdir -p /btrfs_tmp/old_roots
if [ -e /btrfs_tmp/root ]; then
timestamp=$(date -d "@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%d_%H:%M:%S" 2>/dev/null || date "+%Y-%m-%d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
delete_subvolume_recursively() {
IFS=$(printf '\n')
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +14); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/${cfg.btrfs.rootSubvol}
umount /btrfs_tmp
'';
};
programs.fuse.userAllowOther = true;
environment.persistence.${cfg.location} = {
environment.persistence.${cfg.btrfs.mountPoint} = {
hideMounts = true;
directories = cfg.nixosDirs;
files = cfg.nixosFiles;
+1 -1
View File
@@ -17,7 +17,7 @@ in
sshKeyFile = lib.mkOption {
type = lib.types.str;
default = "${
if config.my.persist.enable then config.my.persist.location else ""
if config.my.persist.enable then config.my.persist.btrfs.mountPoint else ""
}/home/${username}/.ssh/id_ed25519";
};
};