diff --git a/flake.lock b/flake.lock index 5e5e2fc6..a1cff91e 100644 --- a/flake.lock +++ b/flake.lock @@ -200,6 +200,21 @@ "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" + } + }, "nixos-hardware": { "locked": { "lastModified": 1711352745, @@ -285,6 +300,7 @@ "home-manager": "home-manager", "home-manager-unstable": "home-manager-unstable", "hyprland": "hyprland", + "impermanence": "impermanence", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs_3", "nixpkgs-unstable": "nixpkgs-unstable" diff --git a/flake.nix b/flake.nix index 5b6bf64c..561cacd2 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,8 @@ disko-unstable.url = "github:nix-community/disko"; disko-unstable.inputs.nixpkgs.follows = "nixpkgs-unstable"; + impermanence.url = "github:nix-community/impermanence"; + # Latest Hyprland hyprland.url = "github:hyprwm/Hyprland"; @@ -40,7 +42,7 @@ }; outputs = inputs@{ nixpkgs, nixpkgs-unstable, home-manager - , home-manager-unstable, nixos-hardware, disko, disko-unstable, ... }: { + , home-manager-unstable, nixos-hardware, impermanence, disko, disko-unstable, ... }: { homeConfigurations.aly = home-manager-unstable.lib.homeManagerConfiguration { @@ -92,6 +94,7 @@ specialArgs = { inherit inputs; }; modules = [ disko-unstable.nixosModules.disko + impermanence.nixosModules.impermanence nixos-hardware.nixosModules.lenovo-thinkpad-t440p home-manager-unstable.nixosModules.home-manager ./hosts/rustboro diff --git a/hosts/rustboro/default.nix b/hosts/rustboro/default.nix index 828bdda0..c31d945f 100644 --- a/hosts/rustboro/default.nix +++ b/hosts/rustboro/default.nix @@ -1,6 +1,6 @@ # Lenovo Thinkpad T440p with a Core i5 4210M, 16GB RAM, 512GB SSD. -{ config, pkgs, ... }: +{ config, lib, pkgs, ... }: { imports = [ @@ -13,6 +13,41 @@ # Bootloader. loader.systemd-boot.enable = true; loader.efi.canTouchEfiVariables = true; + + # initrd.postDeviceCommands = lib.mkAfter '' + # mkdir /btrfs_tmp + # mount /dev/sda2 /btrfs_tmp + # if [[ -e /btrfs_tmp/rootfs ]]; then + # mkdir -p /btrfs_tmp/old_roots + # timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/rootfs)" "+%Y-%m-%-d_%H:%M:%S") + # mv /btrfs_tmp/rootfs "/btrfs_tmp/old_roots/$timestamp" + # fi + + # delete_subvolume_recursively() { + # IFS=$'\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 +10); do + # delete_subvolume_recursively "$i" + # done + + # btrfs subvolume create /btrfs_tmp/rootfs + # umount /btrfs_tmp + # ''; + initrd.postDeviceCommands = lib.mkAfter '' + mkdir /btrfs_tmp + mount /dev/sda2 /btrfs_tmp + if [[ -e /btrfs_tmp/rootfs ]]; then + btrfs subvolume delete /btrfs_tmp/rootfs + fi + + btrfs subvolume create /btrfs_tmp/rootfs + umount /btrfs_tmp + ''; }; networking.hostName = "rustboro"; # Define your hostname. @@ -40,5 +75,15 @@ users.users.aly.hashedPassword = "$y$j9T$VdtiEyMOegHpcUwgmCVFD0$K8Ne6.zk//VJNq2zxVQ0xE0Wg3LohvAQd3Xm9aXdM15"; + environment.persistence."/persist" = { + hideMounts = true; + directories = [ + "/etc/NetworkManager/system-connections" + ]; + files = [ + "/etc/machine-id" + ]; + }; + system.stateVersion = "23.11"; # Did you read the comment? } diff --git a/hosts/rustboro/disko.nix b/hosts/rustboro/disko.nix index e08fbac9..bd34b968 100644 --- a/hosts/rustboro/disko.nix +++ b/hosts/rustboro/disko.nix @@ -11,7 +11,7 @@ priority = 1; name = "ESP"; start = "1M"; - end = "128M"; + end = "512M"; type = "EF00"; content = { type = "filesystem"; @@ -31,7 +31,7 @@ "rootfs" = { mountpoint = "/"; }; # For use with future impermanence setups "persistent" = { - mountpoint = "/persistent"; + mountpoint = "/persist"; mountOptions = [ "compress=zstd" ]; }; # Subvolume name is the same as the mountpoint diff --git a/hosts/rustboro/hardware-configuration.nix b/hosts/rustboro/hardware-configuration.nix index 68ecc84e..49bf1822 100644 --- a/hosts/rustboro/hardware-configuration.nix +++ b/hosts/rustboro/hardware-configuration.nix @@ -19,6 +19,10 @@ boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; + fileSystems."/persist" = { + neededForBoot = true; + }; + networking.useDHCP = lib.mkDefault true; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";