update
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
imports = [
|
imports = [
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
./fish.nix
|
./fish.nix
|
||||||
|
./optin-persistence.nix
|
||||||
./sops.nix
|
./sops.nix
|
||||||
] ++ (builtins.attrValues outputs.nixosModules);
|
] ++ (builtins.attrValues outputs.nixosModules);
|
||||||
|
|
||||||
|
|||||||
35
hosts/common/global/optin-persistence.nix
Normal file
35
hosts/common/global/optin-persistence.nix
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
inputs,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
imports = [inputs.impermanence.nixosModules.impermanence];
|
||||||
|
|
||||||
|
environment.persistence = {
|
||||||
|
"/persist" = {
|
||||||
|
files = [
|
||||||
|
"/etc/machine-id"
|
||||||
|
];
|
||||||
|
directories = [
|
||||||
|
"/var/lib/fprint"
|
||||||
|
"/var/lib/systemd"
|
||||||
|
"/var/lib/nixos"
|
||||||
|
"/var/log"
|
||||||
|
"/srv"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
programs.fuse.userAllowOther = true;
|
||||||
|
system.activationScripts.persistent-dirs.text = let
|
||||||
|
mkHomePersist = user:
|
||||||
|
lib.optionalString user.createHome ''
|
||||||
|
mkdir -p /persist/${user.home}
|
||||||
|
chown ${user.name}:${user.group} /persist/${user.home}
|
||||||
|
chmod ${user.homeMode} /persist/${user.home}
|
||||||
|
'';
|
||||||
|
users = lib.attrValues config.users.users;
|
||||||
|
in
|
||||||
|
lib.concatLines (map mkHomePersist users);
|
||||||
|
}
|
||||||
@@ -1,5 +1,49 @@
|
|||||||
{
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
root = config.fileSystems."/";
|
||||||
|
|
||||||
}: {
|
wipeScript = ''
|
||||||
|
mkdir /tmp -p
|
||||||
|
MNTPOINT=$(mktemp -d)
|
||||||
|
(
|
||||||
|
mount -t btrfs -o subvol=/ ${root.device} "$MNTPOINT"
|
||||||
|
trap 'umount "$MNTPOINT"' EXIT
|
||||||
|
|
||||||
|
echo "Creating needed directories"
|
||||||
|
mkdir -p "$MNTPOINT"/persist/var/{log,lib/{nixos,systemd}}
|
||||||
|
if [ -e "$MNTPOINT/dont-wipe" ]; then
|
||||||
|
echo "Skipping wipe"
|
||||||
|
else
|
||||||
|
echo "Cleaning root subvolume"
|
||||||
|
btrfs subvolume delete -R "$MNTPOINT/root"
|
||||||
|
echo "Restoring blank subvolume"
|
||||||
|
btrfs subvolume snapshot "$MNTPOINT/root-blank" "$MNTPOINT/root"
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Convert a device path to a systemd .device
|
||||||
|
toSystemdDevice = device: lib.concatStringsSep "-" (lib.tail (map (lib.replaceString "-" "\\x2d" ) (lib.splitString "/" device))) + ".device";
|
||||||
|
|
||||||
|
phase1Systemd = config.boot.initrd.systemd.enable;
|
||||||
|
in {
|
||||||
|
boot.initrd = {
|
||||||
|
supportedFilesystems = ["btrfs"];
|
||||||
|
postDeviceCommands = lib.mkIf (!phase1Systemd) (lib.mkBefore wipeScript);
|
||||||
|
systemd.services.restore-root = lib.mkIf phase1Systemd {
|
||||||
|
description = "Rollback btrfs rootfs";
|
||||||
|
wantedBy = ["initrd.target"];
|
||||||
|
requires = [(toSystemdDevice root.device)];
|
||||||
|
after = [(toSystemdDevice root.device)];
|
||||||
|
before = ["sysroot.mount"];
|
||||||
|
unitConfig.DefaultDependencies = "no";
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
script = wipeScript;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
fileSystems."/persist".neededForBoot = lib.mkDefault true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,7 @@
|
|||||||
dconf.enable = true;
|
dconf.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hardware.graphics.enable = true;
|
||||||
|
|
||||||
system.stateVersion = "25.11";
|
system.stateVersion = "25.11";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
{inputs, ... }: {
|
{inputs, lib, ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
inputs.disko.nixosModules.disko
|
inputs.disko.nixosModules.disko
|
||||||
../common/optional/ephermal-btrfs.nix
|
../common/optional/ephemeral-btrfs.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
boot = {
|
boot = {
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
partions = {
|
partitions = {
|
||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02";
|
type = "EF02";
|
||||||
@@ -88,6 +88,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user