initial attempt at impermance

This commit is contained in:
twoneis 2024-05-08 19:20:06 +02:00
parent bfe077d474
commit 932838f736
5 changed files with 74 additions and 39 deletions

View file

@ -6,10 +6,10 @@
postDeviceCommands = lib.mkAfter '' postDeviceCommands = lib.mkAfter ''
mkdir /btrfs_tmp mkdir /btrfs_tmp
mount /dev/disk/by-uuid/b6e6bca7-1435-4b41-b174-8550eace7c32 /btrfs_tmp mount /dev/disk/by-uuid/b6e6bca7-1435-4b41-b174-8550eace7c32 /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then if [[ -e /btrfs_tmp/rootfs ]]; then
mkdir -p /btrfs_tmp/old_roots mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/rootfs)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" mv /btrfs_tmp/rootfs "/btrfs_tmp/old_roots/$timestamp"
fi fi
delete_subvolume_recursively() { delete_subvolume_recursively() {
@ -24,7 +24,7 @@
delete_subvolume_recursively "$i" delete_subvolume_recursively "$i"
done done
btrfs subvolume create /btrfs_tmp/root btrfs subvolume create /btrfs_tmp/rootfs
umount /btrfs_tmp umount /btrfs_tmp
''; '';
}; };
@ -35,6 +35,7 @@
fileSystems = { fileSystems = {
"/boot" = { "/boot" = {
device = "/dev/disk/by-uuid/7ABC-9C12"; device = "/dev/disk/by-uuid/7ABC-9C12";
neededForBoot = true;
fsType = "vfat"; fsType = "vfat";
}; };
"/" = { "/" = {
@ -45,16 +46,19 @@
"/nix" = { "/nix" = {
device = "/dev/disk/by-uuid/b6e6bca7-1435-4b41-b174-8550eace7c32"; device = "/dev/disk/by-uuid/b6e6bca7-1435-4b41-b174-8550eace7c32";
fsType = "btrfs"; fsType = "btrfs";
neededForBoot = true;
options = [ "subvol=nix" "compress=zstd" "noatime" ]; options = [ "subvol=nix" "compress=zstd" "noatime" ];
}; };
"/persist" = { "/persist" = {
device = "/dev/disk/by-uuid/b6e6bca7-1435-4b41-b174-8550eace7c32"; device = "/dev/disk/by-uuid/b6e6bca7-1435-4b41-b174-8550eace7c32";
fsType = "btrfs"; fsType = "btrfs";
neededForBoot = true;
options = [ "subvol=persist" "compress=zstd" "noatime" ]; options = [ "subvol=persist" "compress=zstd" "noatime" ];
}; };
"/ext" = { "/ext" = {
device = "/dev/disk/by-uuid/3ed92a26-775a-4e39-ac1c-84b2822cd3dd"; device = "/dev/disk/by-uuid/3ed92a26-775a-4e39-ac1c-84b2822cd3dd";
fsType = "btrfs"; fsType = "btrfs";
neededForBoot = true;
options = [ "subvol=ext" "compress=zstd" "noatime" ]; options = [ "subvol=ext" "compress=zstd" "noatime" ];
}; };
}; };

16
flake.lock generated
View file

@ -249,6 +249,21 @@
"type": "github" "type": "github"
} }
}, },
"impermanence": {
"locked": {
"lastModified": 1708968331,
"narHash": "sha256-VUXLaPusCBvwM3zhGbRIJVeYluh2uWuqtj4WirQ1L9Y=",
"owner": "nix-community",
"repo": "impermanence",
"rev": "a33ef102a02ce77d3e39c25197664b7a636f9c30",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "impermanence",
"type": "github"
}
},
"niri": { "niri": {
"inputs": { "inputs": {
"crate2nix": "crate2nix", "crate2nix": "crate2nix",
@ -464,6 +479,7 @@
"root": { "root": {
"inputs": { "inputs": {
"home-manager": "home-manager", "home-manager": "home-manager",
"impermanence": "impermanence",
"niri": "niri", "niri": "niri",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs_3", "nixpkgs": "nixpkgs_3",

View file

@ -21,6 +21,10 @@
url = "github:sodiboo/niri-flake"; url = "github:sodiboo/niri-flake";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
impermanence = {
url = "github:nix-community/impermanence";
};
}; };
outputs = inputs: import ./outputs.nix inputs; outputs = inputs: import ./outputs.nix inputs;

View file

@ -0,0 +1,8 @@
{ ... }: {
environment.persistence."/persist" = {
files = [
"/etc/shadow"
"/etc/passwd"
];
};
}

View file

@ -1,35 +1,5 @@
{ nixpkgs, home-manager, nixos-hardware, nur, niri, ... }@inputs: { { nixpkgs, home-manager, nixos-hardware, nur, niri, impermanence, ... }@inputs: {
nixosConfigurations = let nixosConfigurations = {
clientModules = [
./modules/system
./options.nix
niri.nixosModules.niri
home-manager.nixosModules.home-manager {
nixpkgs.overlays = [
nur.overlay
];
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.twoneis = import ./modules/system/home;
};
}
];
serverModules = [
./modules/server
./options.nix
home-manager.nixosModules.home-manager {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.twoneis = import ./modules/server/home;
};
}
];
in {
# AMD Ryzen 5600X # AMD Ryzen 5600X
# nvidia GeForce GTX 1060 (6GB) # nvidia GeForce GTX 1060 (6GB)
ellaca = nixpkgs.lib.nixosSystem { ellaca = nixpkgs.lib.nixosSystem {
@ -39,7 +9,20 @@
}; };
modules = [ modules = [
./devices/ellaca ./devices/ellaca
] ++ clientModules; ./modules/system
./modules/system/persist
./options.nix
niri.nixosModules.niri
impermanence.nixosModules.impermanence
home-manager.nixosModules.home-manager {
nixpkgs.overlays = [ nur.overlay ];
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.twoneis = import ./modules/system/home;
};
}
];
}; };
# Surface Pro 7 (i5 128GB) # Surface Pro 7 (i5 128GB)
@ -50,8 +33,19 @@
}; };
modules = [ modules = [
./devices/akarso ./devices/akarso
./modules/system
./options.nix
nixos-hardware.nixosModules.microsoft-surface-pro-intel nixos-hardware.nixosModules.microsoft-surface-pro-intel
] ++ clientModules; niri.nixosModules.niri
home-manager.nixosModules.home-manager {
nixpkgs.overlays = [ nur.overlay ];
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.twoneis = import ./modules/system/home;
};
}
];
}; };
# Zotac Mini # Zotac Mini
@ -63,7 +57,16 @@
}; };
modules = [ modules = [
./devices/creosote ./devices/creosote
] ++ serverModules; ./modules/server
./options.nix
home-manager.nixosModules.home-manager {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.twoneis = import ./modules/server/home;
};
}
];
}; };
}; };
} }