diff --git a/flake.lock b/flake.lock index f2c538b..b0213d6 100644 --- a/flake.lock +++ b/flake.lock @@ -11,11 +11,11 @@ "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1775232685, - "narHash": "sha256-+kVivleQqI6HdFeVWVukEPvPec/SN74l+j/Tw9OBaSw=", + "lastModified": 1776442854, + "narHash": "sha256-63dPlCgKEfqWmzaRnec4W2sQDtwfApPxKbpy05ChQ+U=", "owner": "linyinfeng", "repo": "angrr", - "rev": "e1b066a0dbdd6ed3208dd5405e7d6cde91b7e20d", + "rev": "a49a74a81185fc0bfad62e98d80f05e80cd6c3e6", "type": "github" }, "original": { @@ -130,11 +130,11 @@ ] }, "locked": { - "lastModified": 1775213373, - "narHash": "sha256-wJHsijC2l/E+ovmlpPGha8pXA6RHSwHWmBV97gvkmyI=", + "lastModified": 1776420287, + "narHash": "sha256-0P2QyDM8R1FFww//TNDLTRVnVkQxVdbEVQiVuyD1SqY=", "owner": "catppuccin", "repo": "nix", - "rev": "ba73719e673e7c2d89ac2f8df0bc0d48983e4907", + "rev": "bdf0285dc7978ebd78b76054631d7ef05680895e", "type": "github" }, "original": { @@ -193,11 +193,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1775807984, - "narHash": "sha256-Redoe3D9zGN5I9QPHWL9vfMVQBehY1fKsMiRXQ83X3w=", + "lastModified": 1776413252, + "narHash": "sha256-ZQhyB2vnFsE1KcWJlWle1UujEDVjTJVL3oMIHUvnzuo=", "owner": "nix-community", "repo": "fenix", - "rev": "fcf90c0c4d368b2ca917a7afa6d08e98a397e5fd", + "rev": "a318c3c6120e91375eea1d7c57a0cd101a81b14a", "type": "github" }, "original": { @@ -542,11 +542,11 @@ ] }, "locked": { - "lastModified": 1775781825, - "narHash": "sha256-L5yKTpR+alrZU2XYYvIxCeCP4LBHU5jhwSj7H1VAavg=", + "lastModified": 1776454077, + "narHash": "sha256-7zSUFWsU0+jlD7WB3YAxQ84Z/iJurA5hKPm8EfEyGJk=", "owner": "nix-community", "repo": "home-manager", - "rev": "e35c39fca04fee829cecdf839a50eb9b54d8a701", + "rev": "565e5349208fe7d0831ef959103c9bafbeac0681", "type": "github" }, "original": { @@ -585,11 +585,11 @@ ] }, "locked": { - "lastModified": 1774991950, - "narHash": "sha256-kScKj3qJDIWuN9/6PMmgy5esrTUkYinrO5VvILik/zw=", + "lastModified": 1776184304, + "narHash": "sha256-No6QGBmIv5ChiwKCcbkxjdEQ/RO2ZS1gD7SFy6EZ7rc=", "owner": "nix-community", "repo": "home-manager", - "rev": "f2d3e04e278422c7379e067e323734f3e8c585a7", + "rev": "3c7524c68348ef79ce48308e0978611a050089b2", "type": "github" }, "original": { @@ -704,11 +704,11 @@ "xwayland-satellite-unstable": "xwayland-satellite-unstable" }, "locked": { - "lastModified": 1775802594, - "narHash": "sha256-miydzsK4cMzBXoHw+/5Am4PwB/P/ifWOlfHHqFe7FKU=", + "lastModified": 1776435348, + "narHash": "sha256-qsZnMThxTqxCJZ7DEKu3DD3KjIPcuUBvZ0C9a2uIvaQ=", "owner": "sodiboo", "repo": "niri-flake", - "rev": "63213c63766e5bb28e0e0b078c4628b01b24c92f", + "rev": "55b5b1fc9481ab267603a1099e5d4b4ebc7394d7", "type": "github" }, "original": { @@ -737,11 +737,11 @@ "niri-unstable": { "flake": false, "locked": { - "lastModified": 1775561155, - "narHash": "sha256-TK2IrqQivRcwqJa0suZMbcsN17CtA8Uu0v7CDnLATb0=", + "lastModified": 1776432730, + "narHash": "sha256-Pq1ZVvRGq/IFiFH6vkNwMfZEpWk23NjgGdX50COdj/c=", "owner": "YaLTeR", "repo": "niri", - "rev": "599db847f857b8a7ff78ce02f15acab5d5d9fee1", + "rev": "c814c656c53ea9d69f5afb45c88f4dc4d25338cd", "type": "github" }, "original": { @@ -838,11 +838,11 @@ ] }, "locked": { - "lastModified": 1774972752, - "narHash": "sha256-DnLIpFxznohpLkIFs390uZ0gxwkVyhtknhKNu+lQJK8=", + "lastModified": 1776255237, + "narHash": "sha256-LQjlc0VEn55WAT4BiI8sIsokb/2FNlcbBD+Xr3MTE24=", "owner": "nix-community", "repo": "NixOS-WSL", - "rev": "d97e078f4788cddb8d11c3c99f72a4bb9ddec221", + "rev": "9a8c2a85f1ffdcecfb0f9c52c5a73c49ceb43911", "type": "github" }, "original": { @@ -881,11 +881,11 @@ }, "nixpkgs-master": { "locked": { - "lastModified": 1775819370, - "narHash": "sha256-BHRz22IikhXRf50kZ4N/zpVcwpF2Iu9oZszo7kjZOFw=", + "lastModified": 1776485399, + "narHash": "sha256-4Cmxz15i5qn3HZFbyxf6hRyeb7huOJgW2+c1GCQ0J4U=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7a0597d154a4f90b29c0dcd8cb465de0986452a6", + "rev": "5230db4d0c546b5b7594aa978e6e8aa560351748", "type": "github" }, "original": { @@ -897,11 +897,11 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1775595990, - "narHash": "sha256-OEf7YqhF9IjJFYZJyuhAypgU+VsRB5lD4DuiMws5Ltc=", + "lastModified": 1776221942, + "narHash": "sha256-FbQAeVNi7G4v3QCSThrSAAvzQTmrmyDLiHNPvTF2qFM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4e92bbcdb030f3b4782be4751dc08e6b6cb6ccf2", + "rev": "1766437c5509f444c1b15331e82b8b6a9b967000", "type": "github" }, "original": { @@ -913,11 +913,11 @@ }, "nixpkgs-stable_2": { "locked": { - "lastModified": 1775811116, - "narHash": "sha256-t+HZK42pB6N+i5RGbuy7Xluez/VvWbembBdvzsc23Ss=", + "lastModified": 1776481463, + "narHash": "sha256-WL4ugBHkmW89Hu4BfZN5ZdrgBhr/azwu4Ogx9IH9UaM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "54170c54449ea4d6725efd30d719c5e505f1c10e", + "rev": "63d42e035e2eddc492965a2cca2ac3f21dfcf82f", "type": "github" }, "original": { @@ -929,11 +929,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1775710090, - "narHash": "sha256-ar3rofg+awPB8QXDaFJhJ2jJhu+KqN/PRCXeyuXR76E=", + "lastModified": 1776169885, + "narHash": "sha256-l/iNYDZ4bGOAFQY2q8y5OAfBBtrDAaPuRQqWaFHVRXM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4c1018dae018162ec878d42fec712642d214fdfa", + "rev": "4bd9165a9165d7b5e33ae57f3eecbcb28fb231c9", "type": "github" }, "original": { @@ -993,11 +993,11 @@ }, "nixpkgs_5": { "locked": { - "lastModified": 1775710090, - "narHash": "sha256-ar3rofg+awPB8QXDaFJhJ2jJhu+KqN/PRCXeyuXR76E=", + "lastModified": 1776169885, + "narHash": "sha256-l/iNYDZ4bGOAFQY2q8y5OAfBBtrDAaPuRQqWaFHVRXM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4c1018dae018162ec878d42fec712642d214fdfa", + "rev": "4bd9165a9165d7b5e33ae57f3eecbcb28fb231c9", "type": "github" }, "original": { @@ -1127,11 +1127,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1775745684, - "narHash": "sha256-8MbfLwd60FNa8dRFkjE+G3TT/x21G3Rsplm1bMBQUtU=", + "lastModified": 1776343166, + "narHash": "sha256-ZiHQPWwuUZk44epAZRbyFz23Kd4CYaq8WlBgAmCqAzQ=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "64ddb549bc9a70d011328746fa46a8883f937b6b", + "rev": "b8458013c217be4fccefc4e4f194026fa04ab4ca", "type": "github" }, "original": { @@ -1148,11 +1148,11 @@ ] }, "locked": { - "lastModified": 1775659564, - "narHash": "sha256-WFLi+JOeit3ymB0gw+hswtVuks0+qOYhJaJR5Y3ARww=", + "lastModified": 1776230713, + "narHash": "sha256-8Rv4J8M09NPJcq4pYfMyi0ibJJQD7/JzKjAqSp2LjZw=", "owner": "Mic92", "repo": "sops-nix", - "rev": "4eac297e5dfce12420988df36defc177c1fe9ff0", + "rev": "105ff9ba631f5e7ee75aac03df941981312d917e", "type": "github" }, "original": { @@ -1182,11 +1182,11 @@ "tinted-zed": "tinted-zed" }, "locked": { - "lastModified": 1775429060, - "narHash": "sha256-wbFF5cRxQOCzL/wHOKYm21t5AHPH2Lfp0mVPCOAvEoc=", + "lastModified": 1776170745, + "narHash": "sha256-Tl1aZVP5EIlT+k0+iAKH018GLHJpLz3hhJ0LNQOWxCc=", "owner": "danth", "repo": "stylix", - "rev": "d27951a6539951d87f75cf0a7cda8a3a24016019", + "rev": "e3861617645a43c9bbefde1aa6ac54dd0a44bfa9", "type": "github" }, "original": { @@ -1352,11 +1352,11 @@ ] }, "locked": { - "lastModified": 1775125835, - "narHash": "sha256-2qYcPgzFhnQWchHo0SlqLHrXpux5i6ay6UHA+v2iH4U=", + "lastModified": 1775636079, + "narHash": "sha256-pc20NRoMdiar8oPQceQT47UUZMBTiMdUuWrYu2obUP0=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "75925962939880974e3ab417879daffcba36c4a3", + "rev": "790751ff7fd3801feeaf96d7dc416a8d581265ba", "type": "github" }, "original": { @@ -1406,11 +1406,11 @@ ] }, "locked": { - "lastModified": 1775744672, - "narHash": "sha256-Qg3Wnn3WYiiii35CE9kE+XX4ooSFzupAnGC1/NjI5C8=", + "lastModified": 1776483758, + "narHash": "sha256-MjoG8oTm3KsPhXemYqnNjpGmE2PbmUdLFOGXRhNQ7sU=", "owner": "0xc000022070", "repo": "zen-browser-flake", - "rev": "14a238beb0621977e9bf04cba68919d5650deea9", + "rev": "44f9a58e8c1fa0a0887f51dd361aa86faa8f759c", "type": "github" }, "original": { diff --git a/hosts/imxyy-nix-server/hardware.nix b/hosts/imxyy-nix-server/hardware.nix index 68752da..c74a483 100644 --- a/hosts/imxyy-nix-server/hardware.nix +++ b/hosts/imxyy-nix-server/hardware.nix @@ -31,13 +31,12 @@ in services.btrfs.autoScrub.enable = true; networking.hostId = "10ca95b4"; - fileSystems."/" = { + my.persist.btrfs = { device = btrfs; - fsType = "btrfs"; - options = [ - "compress=zstd" - "subvol=root" - ]; + mountPoint = "/nix/persist"; + persistSubvol = "persist"; + rootSubvol = "root"; + zstdCompress = true; }; fileSystems."/nix" = { @@ -49,17 +48,6 @@ in ]; }; - my.persist.location = "/nix/persist"; - fileSystems."/nix/persist" = { - device = btrfs; - fsType = "btrfs"; - options = [ - "compress=zstd" - "subvol=persist" - ]; - neededForBoot = true; - }; - boot.initrd.postDeviceCommands = lib.mkAfter '' mkdir /btrfs_tmp mount ${btrfs} /btrfs_tmp diff --git a/hosts/imxyy-nix-x16/hardware.nix b/hosts/imxyy-nix-x16/hardware.nix index 0c01041..1b03b3d 100644 --- a/hosts/imxyy-nix-x16/hardware.nix +++ b/hosts/imxyy-nix-x16/hardware.nix @@ -30,13 +30,12 @@ in }; }; - fileSystems."/" = { + my.persist.btrfs = { device = btrfs; - fsType = "btrfs"; - options = [ - "compress=zstd" - "subvol=root" - ]; + mountPoint = "/nix/persist"; + persistSubvol = "persist"; + rootSubvol = "root"; + zstdCompress = true; }; fileSystems."/nix" = { @@ -48,42 +47,6 @@ in ]; }; - my.persist.location = "/nix/persist"; - fileSystems."/nix/persist" = { - device = btrfs; - fsType = "btrfs"; - options = [ - "compress=zstd" - "subvol=persist" - ]; - neededForBoot = true; - }; - - boot.initrd.postDeviceCommands = lib.mkAfter '' - mkdir /btrfs_tmp - mount ${btrfs} /btrfs_tmp - mkdir -p /btrfs_tmp/old_roots - if [[ -e /btrfs_tmp/root ]]; then - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%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 +14); do - delete_subvolume_recursively "$i" - done - - btrfs subvolume create /btrfs_tmp/root - umount /btrfs_tmp - ''; - fileSystems."/boot" = { device = "/dev/disk/by-uuid/96D3-93B0"; fsType = "vfat"; diff --git a/hosts/imxyy-nix/hardware.nix b/hosts/imxyy-nix/hardware.nix index f1ddd9c..7cf4267 100644 --- a/hosts/imxyy-nix/hardware.nix +++ b/hosts/imxyy-nix/hardware.nix @@ -37,13 +37,12 @@ in ]; }; - fileSystems."/" = { + my.persist.btrfs = { device = btrfs; - fsType = "btrfs"; - options = [ - "compress=zstd" - "subvol=root" - ]; + mountPoint = "/nix/persist"; + persistSubvol = "persistent"; + rootSubvol = "root"; + zstdCompress = true; }; fileSystems."/nix" = { @@ -52,17 +51,6 @@ in options = [ "compress=zstd" ]; }; - my.persist.location = "/nix/persist"; - fileSystems."/nix/persist" = { - device = btrfs; - fsType = "btrfs"; - options = [ - "compress=zstd" - "subvol=persistent" - ]; - neededForBoot = true; - }; - fileSystems."/swap" = { device = btrfs; fsType = "btrfs"; @@ -73,31 +61,6 @@ in neededForBoot = true; }; - boot.initrd.postDeviceCommands = lib.mkAfter '' - mkdir /btrfs_tmp - mount ${btrfs} /btrfs_tmp - mkdir -p /btrfs_tmp/old_roots - if [[ -e /btrfs_tmp/root ]]; then - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%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 +14); do - delete_subvolume_recursively "$i" - done - - btrfs subvolume create /btrfs_tmp/root - umount /btrfs_tmp - ''; - fileSystems."/boot" = { device = "/dev/disk/by-uuid/B7DC-E9AC"; fsType = "vfat"; diff --git a/modules/coding/editor/neovim/default.nix b/modules/coding/editor/neovim/default.nix index 1cefa57..1fbb9fb 100644 --- a/modules/coding/editor/neovim/default.nix +++ b/modules/coding/editor/neovim/default.nix @@ -24,6 +24,7 @@ in vimdiffAlias = true; withPython3 = false; withRuby = false; + sideloadInitLua = true; extraPackages = with pkgs; [ # treesitter tree-sitter diff --git a/modules/coding/langs/go.nix b/modules/coding/langs/go.nix index 3a065ad..3b82e99 100644 --- a/modules/coding/langs/go.nix +++ b/modules/coding/langs/go.nix @@ -16,7 +16,7 @@ in my.hm.home.packages = with pkgs; [ go gotools - gopls + (lib.hiPrio gopls) ]; my.persist.homeDirs = [ "go" diff --git a/modules/core/persist.nix b/modules/core/persist.nix index 3e65410..54c7df0 100644 --- a/modules/core/persist.nix +++ b/modules/core/persist.nix @@ -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; diff --git a/modules/sops.nix b/modules/sops.nix index 1065c7a..7e11c59 100644 --- a/modules/sops.nix +++ b/modules/sops.nix @@ -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"; }; }; diff --git a/profiles/desktop.nix b/profiles/desktop.nix index cd8eedc..52fbb28 100644 --- a/profiles/desktop.nix +++ b/profiles/desktop.nix @@ -42,6 +42,5 @@ # Desktop persistence my.persist = { enable = lib.mkDefault true; - location = lib.mkDefault "/nix/persist"; }; } diff --git a/profiles/server.nix b/profiles/server.nix index a91ee29..40a9c04 100644 --- a/profiles/server.nix +++ b/profiles/server.nix @@ -21,6 +21,5 @@ # Server persistence my.persist = { enable = lib.mkDefault true; - location = lib.mkDefault "/nix/persist"; }; }