From eb5b62196226fc29f29978e3a84b45100318bafb Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 25 Feb 2026 23:58:47 +0000 Subject: [PATCH] disko --- flake.lock | 55 +++++++++----- flake.nix | 127 +++++++++++++++++++-------------- home/default.nix | 1 + home/user/impermanence.nix | 12 ++++ system/disko.nix | 48 +++++++++++++ system/modules/boot.nix | 37 +++++++--- system/modules/impermanenc.nix | 14 ++++ 7 files changed, 213 insertions(+), 81 deletions(-) create mode 100644 home/user/impermanence.nix create mode 100644 system/disko.nix create mode 100644 system/modules/impermanenc.nix diff --git a/flake.lock b/flake.lock index c06f44f..25f1e3a 100644 --- a/flake.lock +++ b/flake.lock @@ -1,25 +1,24 @@ { "nodes": { - "firefox-addons": { + "disko": { "inputs": { "nixpkgs": [ - "nixpkgs" + "nixpkgs-unstable" ] }, "locked": { - "dir": "pkgs/firefox-addons", - "lastModified": 1771732978, - "narHash": "sha256-o7gZh/eXFkEEmzwlBdIbgCJhmdlqQhOhVjudqgsIefg=", - "owner": "rycee", - "repo": "nur-expressions", - "rev": "18226106e18bc40cce99d436ee741a946f1888f6", - "type": "gitlab" + "lastModified": 1768920986, + "narHash": "sha256-CNzzBsRhq7gg4BMBuTDObiWDH/rFYHEuDRVOwCcwXw4=", + "owner": "nix-community", + "repo": "disko", + "rev": "de5708739256238fb912c62f03988815db89ec9a", + "type": "github" }, "original": { - "dir": "pkgs/firefox-addons", - "owner": "rycee", - "repo": "nur-expressions", - "type": "gitlab" + "owner": "nix-community", + "ref": "latest", + "repo": "disko", + "type": "github" } }, "home-manager": { @@ -29,20 +28,39 @@ ] }, "locked": { - "lastModified": 1714043624, - "narHash": "sha256-Xn2r0Jv95TswvPlvamCC46wwNo8ALjRCMBJbGykdhcM=", + "lastModified": 1772020340, + "narHash": "sha256-aqBl3GNpCadMoJ/hVkWTijM1Aeilc278MjM+LA3jK6g=", "owner": "nix-community", "repo": "home-manager", - "rev": "86853e31dc1b62c6eeed11c667e8cdd0285d4411", + "rev": "36e38ca0d9afe4c55405fdf22179a5212243eecc", "type": "github" }, "original": { "owner": "nix-community", - "ref": "release-23.11", + "ref": "release-25.11", "repo": "home-manager", "type": "github" } }, + "impermanence": { + "inputs": { + "home-manager": [], + "nixpkgs": [] + }, + "locked": { + "lastModified": 1769548169, + "narHash": "sha256-03+JxvzmfwRu+5JafM0DLbxgHttOQZkUtDWBmeUkN8Y=", + "owner": "nix-community", + "repo": "impermanence", + "rev": "7b1d382faf603b6d264f58627330f9faa5cba149", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "impermanence", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1771903837, @@ -77,8 +95,9 @@ }, "root": { "inputs": { - "firefox-addons": "firefox-addons", + "disko": "disko", "home-manager": "home-manager", + "impermanence": "impermanence", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable" } diff --git a/flake.nix b/flake.nix index 8a65552..293e10f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,64 +1,81 @@ { - description = "Stationette nix config"; + description = "Stationette nix config"; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; - nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; - home-manager.url = "github:nix-community/home-manager/release-23.11"; - home-manager.inputs.nixpkgs.follows = "nixpkgs"; - firefox-addons = { - url = "gitlab:rycee/nur-expressions?dir=pkgs/firefox-addons"; - inputs.nixpkgs.follows = "nixpkgs"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; + nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; + impermanence = { + url = "github:nix-community/impermanence"; + inputs.nixpkgs.follows = ""; + inputs.home-manager.follows = ""; + }; + home-manager.url = "github:nix-community/home-manager/release-25.11"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + disko.url = "github:nix-community/disko/latest"; + disko.inputs.nixpkgs.follows = "nixpkgs-unstable"; + #firefox-addons = { + # url = "gitlab:rycee/nur-expressions?dir=pkgs/firefox-addons"; + # inputs.nixpkgs.follows = "nixpkgs"; + #}; }; - }; - outputs = { - self, - nixpkgs, - nixpkgs-unstable, - home-manager, - ... - } @ inputs: let - lib = nixpkgs.lib; - # Supported systems for your flake packages, shell, etc. - # "aarch64-linux" - # "i686-linux" - # "x86_64-linux" - # "aarch64-darwin" - # "x86_64-darwin" - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; - in { + outputs = { + self, + nixpkgs, + nixpkgs-unstable, + home-manager, + impermanence, + disko, + ... + } @ inputs: let + lib = nixpkgs.lib; + # Supported systems for your flake packages, shell, etc. + # "aarch64-linux" + # "i686-linux" + # "x86_64-linux" + # "aarch64-darwin" + # "x86_64-darwin" + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; + in { # NixOS configuration entrypoint # Available through 'nixos-rebuild --flake .#stationette' - nixosConfigurations = { - stationette = nixpkgs.lib.nixosSystem { - modules = [ - ./system/configuration.nix - #home-manager.nixosModules.home-manager { - # home-manager.users.chris = import ./home; - # home-manager.extraSpecialArgs = { - # inherit pkgs-unstable; - # inherit inputs; - # }; - #} - ]; - }; - }; - - # Standalone home-manager configuration entrypoint - homeConfigurations = { - chris = home-manager.lib.homeManagerConfiguration { - inherit pkgs; - extraSpecialArgs = { - inherit pkgs-unstable; - inherit inputs; + nixosConfigurations = { + stationette = nixpkgs.lib.nixosSystem { + modules = [ + ./system/configuration.nix + disko.nixModules.disko + import ./system/disko.nix + { + imports = [ + impermanence.nixModules.impermanence + home-manager.nixModules.home-manager + ]; + home-manager = { + users.chris = import ./home; + extraSpecialArgs = { + inherit pkgs-unstable; + inherit inputs; + }; + }; + } + ]; + }; + }; + + # Standalone home-manager configuration entrypoint + homeConfigurations = { + chris = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + extraSpecialArgs = { + inherit pkgs-unstable; + inherit inputs; + }; + modules = [ + ./home + ]; + }; }; - modules = [ - ./home - ]; - }; }; - }; } diff --git a/home/default.nix b/home/default.nix index e9e0f91..73e96c9 100644 --- a/home/default.nix +++ b/home/default.nix @@ -7,6 +7,7 @@ ... }: { imports = [ + inputs.impermanence.nixosModules.home-manager.impermanence ./user ]; diff --git a/home/user/impermanence.nix b/home/user/impermanence.nix new file mode 100644 index 0000000..eb7e16e --- /dev/null +++ b/home/user/impermanence.nix @@ -0,0 +1,12 @@ +{ + home.persistenec."/persist/home/chris" = { + directories = [ + "Downloads" + "Tower" + ".config/dotfiles" + ".local/share/direnv" + ".ssh" + ]; + "allowOther" = true; + }; +} diff --git a/system/disko.nix b/system/disko.nix new file mode 100644 index 0000000..fd0e895 --- /dev/null +++ b/system/disko.nix @@ -0,0 +1,48 @@ +# nix --extra-experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko ./disko.nix +{ + disko.devices = { + disk = { + stationette = { + type = "disk"; + device = "/dev/sda"; # Check this with lsblk + content = { + type = "gpt"; + partitions = { + ESP = { + size = "512M"; + type = "EFOO"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + size = "100%"; + type = "btfs"; + extraArgs = [ "-f" ]; # Force overwrite + subvolumes = { + "/root" = { + mountpoint = "/"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + "/nix" = { + mountpoint = "/nix"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + "/persist" = { + mountpoint = "/persist"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + "/swap" = { + mountpoint = "/.swapvol"; + swap.swapfile.size = "8G"; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/system/modules/boot.nix b/system/modules/boot.nix index 27fcf36..fd825f4 100644 --- a/system/modules/boot.nix +++ b/system/modules/boot.nix @@ -1,13 +1,34 @@ { config, pkgs, lib, ... }: { - boot = { - #kernelParams = ["nohibernate" "ipv6.disable=1"]; - #tmp.cleanOnBoot = true; - # supportedFilesystems = ["ntfs"]; - loader = { - systemd-boot.enable = true; - efi.canTouchEfiVariables = true; + boot = { + loader = { + systemd-boot.enable = true; + efi.canTouchEfiVariables = true; + }; + initrd.postDeviceCommands = lib.mkAfter '' + mkdir /btrfs_tmp + mount /dev/disk/by-label/NIXOS /btrfs_tmp + if [[ -e /btrfs_tmp/root ]]; then + mkdir -p /btrfs_tmp/old_roots + timestamp=$(dat +%Y-%m-%d_%H-%M-%S) + mv /btrfs_tmp/root "/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 +30); do + delete_subvolume_recursively "$i" + done + + btrfs subvolume create /btrfs_tmp/root + umount /btrfs_tmp + ''; }; - }; } diff --git a/system/modules/impermanenc.nix b/system/modules/impermanenc.nix new file mode 100644 index 0000000..4ea3ef9 --- /dev/null +++ b/system/modules/impermanenc.nix @@ -0,0 +1,14 @@ +{ + environment.persistence."/persist" = { + hideMounts = true; + directories = [ + "/var/log" + "/var/lib/bluetooth" + "/var/lib/networkmanager" + "/etc/ssh" + ]; + files = [ + "/etc/machine-id" + ] + }; +}