use zfs as snapshot #1

Merged
rayandrew merged 8 commits from zfs into main 2024-10-26 21:07:15 -05:00
12 changed files with 344 additions and 239 deletions
Showing only changes of commit 3b50015cb9 - Show all commits

View file

@ -1,4 +1,8 @@
```
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode disko /tmp/disk-config.nix
```
- https://github.com/iynaix/dotfiles/blob/13c2fcec880d292726f52be1075277d521caf3a7/nixos/zfs.nix - https://github.com/iynaix/dotfiles/blob/13c2fcec880d292726f52be1075277d521caf3a7/nixos/zfs.nix
- https://github.com/iynaix/dotfiles/blob/13c2fcec880d292726f52be1075277d521caf3a7/nixos/impermanence.nix#L69 - https://github.com/iynaix/dotfiles/blob/13c2fcec880d292726f52be1075277d521caf3a7/nixos/impermanence.nix#L69
- https://github.com/maydayv7/dotfiles - https://github.com/maydayv7/dotfiles

View file

@ -1,96 +0,0 @@
{
device ? throw "Set this to your disk device, e.g. /dev/sda",
...
}:
{
disko.devices = {
nodev = {
"/" = {
fsType = "tmpfs";
mountOptions = [
"defaults"
"size=8G"
"mode=755"
];
};
};
disk.main = {
type = "disk";
inherit device;
content = {
type = "gpt";
partitions = {
boot = {
name = "boot";
size = "1M";
type = "EF02";
};
esp = {
priority = 1;
size = "512M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"defaults"
"umask=0077"
];
};
};
luks = {
size = "100%";
content = {
type = "luks";
name = "crypted";
settings = {
allowDiscards = true;
};
content = {
type = "lvm_pv";
vg = "pool";
};
};
};
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
size = "100%FREE";
content = {
type = "btrfs";
extraArgs = ["-f"];
subvolumes = {
"/persist" = {
mountOptions = ["subvol=persist" "compress=zstd" "noatime"];
mountpoint = "/persist";
};
"/nix" = {
mountOptions = ["subvol=nix" "compress=zstd" "noatime"];
mountpoint = "/nix";
};
"/swap" = {
mountpoint = "/swap";
mountOptions = ["noatime"];
swap.swapfile.size = "108G";
};
};
};
};
};
};
};
};
}

View file

@ -9,21 +9,65 @@
home-manager.url = "github:nix-community/home-manager"; home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs"; home-manager.inputs.nixpkgs.follows = "nixpkgs";
nixos-hardware.url = "github:NixOS/nixos-hardware/master"; nixos-hardware.url = "github:NixOS/nixos-hardware/master";
nix-index-database.url = "github:nix-community/nix-index-database";
nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
}; };
outputs = {nixpkgs, ...} @ inputs: outputs =
inputs@{ nixpkgs, self, ... }:
let
system = "x86_64-linux";
pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
};
lib = import ./lib.nix {
inherit (nixpkgs) lib;
inherit pkgs;
inherit (inputs) home-manager;
};
createCommonArgs = system: {
inherit
self
inputs
nixpkgs
lib
pkgs
system
;
specialArgs = {
inherit self inputs;
};
};
commonArgs = createCommonArgs system;
# call with forAllSystems (commonArgs: function body)
forAllSystems =
fn:
lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
] (system: fn (createCommonArgs system));
in
{ {
nixosConfigurations.pickwick = nixpkgs.lib.nixosSystem { inherit lib self;
specialArgs = { inherit inputs; }; nixosConfigurations = (import ./src/hosts/nixos.nix commonArgs);
modules = [
inputs.disko.nixosModules.default
(import ./disko.nix { device = "/dev/nvme0n1"; })
./configuration.nix
inputs.home-manager.nixosModules.default
inputs.impermanence.nixosModules.impermanence
];
};
}; };
# outputs = {nixpkgs, ...} @ inputs:
# {
# nixosConfigurations.pickwick = nixpkgs.lib.nixosSystem {
# specialArgs = { inherit inputs; };
# modules = [
# inputs.disko.nixosModules.default
# (import ./disko.nix { device = "/dev/nvme0n1"; })
# ./configuration.nix
#
# inputs.home-manager.nixosModules.default
# inputs.impermanence.nixosModules.impermanence
# ];
# };
# };
} }

44
src/home/default.nix Normal file
View file

@ -0,0 +1,44 @@
{
config,
lib,
pkgs,
user,
...
}:
{
imports = [
./impermanence.nix
];
config = {
# setup fonts for other distros, run "fc-cache -f" to refresh fonts
fonts.fontconfig.enable = true;
home = {
stateVersion = "24.11";
username = user;
homeDirectory = "/home/${user}";
};
programs.home-manager.enable = true;
xdg = {
enable = true;
userDirs.enable = true;
mimeApps.enable = true;
};
custom = {
persist = {
home.directories = [
"Documents"
"Downloads"
"Pictures"
"Code"
];
};
};
};
}

View file

@ -0,0 +1,9 @@
{ config, pkgs, ... }:
{
custom.persist = {
home.directories = [
".config/1Password"
];
};
}

6
src/home/gui/default.nix Normal file
View file

@ -0,0 +1,6 @@
_: {
imports = [
./firefox.nix
./1password.nix
];
}

41
src/home/gui/firefox.nix Normal file
View file

@ -0,0 +1,41 @@
{ config, pkgs, ... }:
let
vendorPath = ".config/.mozilla";
configPath = "${vendorPath}/firefox";
in
{
programs.firefox = {
enable = true;
package = pkgs.firefox-bin.overrideAttrs (o: {
buildCommand =
o.buildCommand
+ ''
wrapProgram "$executablePath" \
--set 'HOME' '${config.xdg.configHome}' \
--append-flags "${
lib.concatStringsSep " " (
[
"--name firefox"
# load user firefox profile
"-P ${user}"
# start with urls:
"https://discordapp.com/channels/@me"
]
++ lib.optionals (host == "desktop") [
"https://web.whatsapp.com" # requires access via local network
"http://localhost:9091" # transmission
]
)
}"
'';
});
};
custom.persist = [
home.directories = [
".cache/mozilla"
".config/.mozilla"
];
];
}

63
src/hosts/default.nix Normal file
View file

@ -0,0 +1,63 @@
{
inputs,
lib,
system,
specialArgs,
user ? "rayandrew",
...
}:
let
# provide an optional { pkgs } 2nd argument to override the pkgs
mkNixosConfiguration =
host:
{
pkgs ? (
import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
}
),
}:
lib.nixosSystem {
inherit pkgs;
specialArgs = specialArgs // {
inherit host user;
};
modules = [
inputs.disko.nixosModules.default
inputs.home-manager.nixosModules.home-manager
inputs.impermanence.nixosModules.impermanence
./${host}
./${host}/hardware.nix
{
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = specialArgs // {
inherit host user;
};
users.${user} = {
imports = [
inputs.nix-index-database.hmModules.nix-index
# ./${host}/home.nix
../../home
];
};
};
}
# alias for home-manager
(lib.mkAliasOptionModule [ "hm" ] [
"home-manager"
"users"
user
])
];
};
in
{
pickwick = mkNixosConfiguration "pickwick" { };
}

View file

@ -2,8 +2,6 @@
{ {
imports = [ imports = [
./hardware-configuration.nix
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
]; ];
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
@ -21,13 +19,10 @@
i18n.defaultLocale = "en_US.UTF-8"; i18n.defaultLocale = "en_US.UTF-8";
services.xserver.enable = true; services.xserver.enable = true;
# services.displayManager.sddm.enable = true;
# services.desktopManager.plasma6.enable = true;
services.xserver.displayManager.gdm.enable = true; services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true; services.xserver.desktopManager.gnome.enable = true;
services.xserver.xkb.layout = "us"; services.xserver.xkb.layout = "us";
# services.xserver.xkb.options = "caps:ctrl_modifier";
security.sudo.extraConfig = "Defaults lecture=never"; security.sudo.extraConfig = "Defaults lecture=never";
security.pam.services.login.fprintAuth = false; security.pam.services.login.fprintAuth = false;
@ -69,16 +64,7 @@
vim vim
wget wget
htop-vim htop-vim
# gnome
keyd keyd
# gnomeExtensions.pop-launcher-super-key
];
environment.plasma6.excludePackages = with pkgs.kdePackages; [
# plasma-browser-integration
# konsole
oxygen
]; ];
environment.gnome.excludePackages = with pkgs; [ environment.gnome.excludePackages = with pkgs; [
@ -117,8 +103,6 @@
environment.persistence."/persist/system" = { environment.persistence."/persist/system" = {
hideMounts = true; hideMounts = true;
directories = [ directories = [
"/etc/nixos"
# "/etc/gdm"
"/var/log" "/var/log"
"/var/lib/fprint" "/var/lib/fprint"
"/var/lib/nixos" "/var/lib/nixos"
@ -142,16 +126,6 @@
useUserPackages = true; useUserPackages = true;
}; };
# xdg.portal = {
# enable = true;
# xdgOpenUsePortal = true;
# extraPortals = [
# pkgs.xdg-desktop-portal-gnome
# pkgs.xdg-desktop-portal-gtk
# ];
# };
services.keyd = { services.keyd = {
enable = true; enable = true;
keyboards = { keyboards = {
@ -161,7 +135,6 @@
main = { main = {
capslock = "layer(capslock)"; capslock = "layer(capslock)";
insert = "S-insert"; insert = "S-insert";
# capslock = "layer(control)";
}; };
meta = { meta = {
w = "macro(C-w)"; w = "macro(C-w)";
@ -195,9 +168,11 @@
"CAP_SETGID" "CAP_SETGID"
]; ];
swapDevices = [ # swapDevices = [
{ device = "/swap/swapfile"; } # { device = "/swap/swapfile"; }
]; # ];
swapDevices = [ { device = "/dev/disk/by-label/SWAP"; } ];
zramSwap.enable = true;
system.stateVersion = "24.11"; system.stateVersion = "24.11";
} }

View file

@ -0,0 +1,108 @@
{
device ? throw "Set this to your disk device, e.g. /dev/sda",
...
}:
{
disko.devices = {
nodev = {
"/" = {
fsType = "tmpfs";
mountOptions = [
"defaults"
"size=1G"
"mode=755"
];
};
"/home" = {
fsType = "tmpfs";
mountOptions = [
"defaults"
"size=1G"
"mode=755"
];
};
};
disk.main = {
type = "disk";
inherit device;
content = {
type = "gpt";
partitions = {
boot = {
name = "boot";
size = "1M";
type = "EF02";
};
esp = {
priority = 1;
size = "512M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"defaults"
"umask=0077"
];
};
};
zfs = {
size = "100%";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
options = {
cachefile = "none";
ashift = 12;
autotrim = "on";
};
rootFsOptions = {
compression = "zstd";
acltype = "posixacl";
xattr = "sa";
"com.sun:auto-snapshot" = "false";
mountpoint = "none";
encryption = "aes-256-gcm";
keyformat = "passphrase";
keylocation = "prompt";
};
mountpoint = "none";
postCreateHook = "zfs list -t snapshot -H -o name | grep -E '^zroot@blank$' || zfs snapshot zroot@blank";
datasets = {
nix = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/nix";
};
cache = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/cache";
};
persist = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/persist";
};
tmp = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/tmp";
};
};
};
};
};
}

View file

@ -1,11 +1,13 @@
# Do not modify this file! It was generated by nixos-generate-config # Do not modify this file! It was generated by nixos-generate-config
# and may be overwritten by future invocations. Please make changes # and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead. # to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }: { input, config, lib, pkgs, modulesPath, ... }:
{ {
imports = imports = [
[ (modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")
(import ./disko.nix { device = "/dev/nvme0n1"; })
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
]; ];
boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "usbhid" "sd_mod" ]; boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "usbhid" "sd_mod" ];

View file

@ -26,101 +26,6 @@
".bash_history" ".bash_history"
".config/zoomus.conf" ".config/zoomus.conf"
]; ];
allowOther = false;
};
home.persistence."/persist/home/rayandrew/desktop" = {
removePrefixDirectory = false;
allowOther = false;
directories = [
".config/gtk-3.0"
".config/gtk-4.0"
".config/KDE"
".config/kde.org"
".config/plasma-workspace"
".config/xsettingsd"
".kde"
".local/share/baloo"
".local/share/dolphin"
".local/share/kactivitymanagerd"
".local/share/kate"
".local/share/klipper"
".local/share/konsole"
".local/share/kscreen"
".local/share/kwalletd"
".local/share/kxmlgui5"
".local/share/RecentDocuments"
".local/share/sddm"
];
files = [
".config/monitors.xml"
".config/akregatorrc"
".config/baloofileinformationrc"
".config/baloofilerc"
".config/bluedevilglobalrc"
".config/device_automounter_kcmrc"
".config/dolphinrc"
".config/filetypesrc"
# ".config/gtkrc"
# ".config/gtkrc-2.0"
# ".config/gtkrc-3.0"
".config/gwenviewrc"
".config/kactivitymanagerd-pluginsrc"
".config/kactivitymanagerd-statsrc"
".config/kactivitymanagerd-switcher"
".config/kactivitymanagerdrc"
".config/katemetainfos"
".config/katerc"
".config/kateschemarc"
".config/katevirc"
".config/kcmfonts"
".config/kcminputrc"
".config/kconf_updaterc"
".config/kded5rc"
".config/kdeglobals"
".config/kgammarc"
".config/kglobalshortcutsrc"
".config/khotkeysrc"
".config/kmixrc"
".config/konsolerc"
".config/kscreenlockerrc"
".config/ksmserverrc"
".config/ksplashrc"
".config/ktimezonedrc"
".config/kwinrc"
".config/kwinrulesrc"
".config/kxkbrc"
# ".config/mimeapps.list"
".config/partitionmanagerrc"
".config/plasma-localerc"
".config/plasma-nm"
".config/plasma-org.kde.plasma.desktop-appletsrc"
".config/plasmanotifyrc"
".config/plasmarc"
".config/plasmashellrc"
".config/PlasmaUserFeedback"
".config/plasmawindowed-appletsrc"
".config/plasmawindowedrc"
".config/powermanagementprofilesrc"
".config/spectaclerc"
".config/startkderc"
".config/systemsettingsrc"
".config/Trolltech.conf"
# ".config/user-dirs.dirs"
".config/user-dirs.locale"
".local/share/krunnerstaterc"
".local/share/user-places.xbel"
# ".local/share/user-places.xbel.bak"
".local/share/user-places.xbel.tbcache"
];
};
home.persistence."/persist/home/rayandrew/firefox" = {
directories = [
".mozilla"
];
allowOther = true; allowOther = true;
}; };