From 3b50015cb99ed6800251b7a3ef5e2afd680265ae Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Sat, 26 Oct 2024 17:06:28 -0500 Subject: [PATCH] zfs init --- README.md | 4 + disko.nix | 96 ---------------- flake.nix | 72 +++++++++--- src/home/default.nix | 44 +++++++ src/home/gui/1password.nix | 9 ++ src/home/gui/default.nix | 6 + src/home/gui/firefox.nix | 41 +++++++ src/hosts/default.nix | 63 ++++++++++ .../hosts/pickwick/default.nix | 35 +----- src/hosts/pickwick/disko.nix | 108 ++++++++++++++++++ .../hosts/pickwick/hardware.nix | 10 +- home.nix => src/hosts/pickwick/home.nix | 95 --------------- 12 files changed, 344 insertions(+), 239 deletions(-) delete mode 100644 disko.nix create mode 100644 src/home/default.nix create mode 100644 src/home/gui/1password.nix create mode 100644 src/home/gui/default.nix create mode 100644 src/home/gui/firefox.nix create mode 100644 src/hosts/default.nix rename configuration.nix => src/hosts/pickwick/default.nix (83%) create mode 100644 src/hosts/pickwick/disko.nix rename hardware-configuration.nix => src/hosts/pickwick/hardware.nix (82%) rename home.nix => src/hosts/pickwick/home.nix (72%) diff --git a/README.md b/README.md index e8ae5ca..f8004e7 100644 --- a/README.md +++ b/README.md @@ -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/impermanence.nix#L69 - https://github.com/maydayv7/dotfiles diff --git a/disko.nix b/disko.nix deleted file mode 100644 index 4c2301c..0000000 --- a/disko.nix +++ /dev/null @@ -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"; - }; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/flake.nix b/flake.nix index 82d1f01..6e30e20 100644 --- a/flake.nix +++ b/flake.nix @@ -9,21 +9,65 @@ home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; 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: - { - 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 - ]; + 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 + { + inherit lib self; + nixosConfigurations = (import ./src/hosts/nixos.nix commonArgs); }; - }; + + # 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 + # ]; + # }; + # }; } diff --git a/src/home/default.nix b/src/home/default.nix new file mode 100644 index 0000000..5ef0475 --- /dev/null +++ b/src/home/default.nix @@ -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" + ]; + }; + }; + }; +} diff --git a/src/home/gui/1password.nix b/src/home/gui/1password.nix new file mode 100644 index 0000000..e590571 --- /dev/null +++ b/src/home/gui/1password.nix @@ -0,0 +1,9 @@ +{ config, pkgs, ... }: + +{ + custom.persist = { + home.directories = [ + ".config/1Password" + ]; + }; +} diff --git a/src/home/gui/default.nix b/src/home/gui/default.nix new file mode 100644 index 0000000..232f6b5 --- /dev/null +++ b/src/home/gui/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./firefox.nix + ./1password.nix + ]; +} diff --git a/src/home/gui/firefox.nix b/src/home/gui/firefox.nix new file mode 100644 index 0000000..8c3bc93 --- /dev/null +++ b/src/home/gui/firefox.nix @@ -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" + ]; + ]; +} diff --git a/src/hosts/default.nix b/src/hosts/default.nix new file mode 100644 index 0000000..d45568e --- /dev/null +++ b/src/hosts/default.nix @@ -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" { }; +} diff --git a/configuration.nix b/src/hosts/pickwick/default.nix similarity index 83% rename from configuration.nix rename to src/hosts/pickwick/default.nix index 0e6969e..1fb381b 100644 --- a/configuration.nix +++ b/src/hosts/pickwick/default.nix @@ -2,8 +2,6 @@ { imports = [ - ./hardware-configuration.nix - inputs.nixos-hardware.nixosModules.framework-13-7040-amd ]; nixpkgs.config.allowUnfree = true; @@ -21,13 +19,10 @@ i18n.defaultLocale = "en_US.UTF-8"; services.xserver.enable = true; - # services.displayManager.sddm.enable = true; - # services.desktopManager.plasma6.enable = true; services.xserver.displayManager.gdm.enable = true; services.xserver.desktopManager.gnome.enable = true; services.xserver.xkb.layout = "us"; - # services.xserver.xkb.options = "caps:ctrl_modifier"; security.sudo.extraConfig = "Defaults lecture=never"; security.pam.services.login.fprintAuth = false; @@ -69,16 +64,7 @@ vim wget htop-vim - - # gnome keyd - # gnomeExtensions.pop-launcher-super-key - ]; - - environment.plasma6.excludePackages = with pkgs.kdePackages; [ - # plasma-browser-integration - # konsole - oxygen ]; environment.gnome.excludePackages = with pkgs; [ @@ -117,8 +103,6 @@ environment.persistence."/persist/system" = { hideMounts = true; directories = [ - "/etc/nixos" - # "/etc/gdm" "/var/log" "/var/lib/fprint" "/var/lib/nixos" @@ -142,16 +126,6 @@ useUserPackages = true; }; - - # xdg.portal = { - # enable = true; - # xdgOpenUsePortal = true; - # extraPortals = [ - # pkgs.xdg-desktop-portal-gnome - # pkgs.xdg-desktop-portal-gtk - # ]; - # }; - services.keyd = { enable = true; keyboards = { @@ -161,7 +135,6 @@ main = { capslock = "layer(capslock)"; insert = "S-insert"; - # capslock = "layer(control)"; }; meta = { w = "macro(C-w)"; @@ -195,9 +168,11 @@ "CAP_SETGID" ]; - swapDevices = [ - { device = "/swap/swapfile"; } - ]; + # swapDevices = [ + # { device = "/swap/swapfile"; } + # ]; + swapDevices = [ { device = "/dev/disk/by-label/SWAP"; } ]; + zramSwap.enable = true; system.stateVersion = "24.11"; } diff --git a/src/hosts/pickwick/disko.nix b/src/hosts/pickwick/disko.nix new file mode 100644 index 0000000..1cfe5f9 --- /dev/null +++ b/src/hosts/pickwick/disko.nix @@ -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"; + }; + }; + }; + }; + }; +} diff --git a/hardware-configuration.nix b/src/hosts/pickwick/hardware.nix similarity index 82% rename from hardware-configuration.nix rename to src/hosts/pickwick/hardware.nix index 9ded9b2..71a87ed 100644 --- a/hardware-configuration.nix +++ b/src/hosts/pickwick/hardware.nix @@ -1,12 +1,14 @@ # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs, modulesPath, ... }: +{ input, config, lib, pkgs, modulesPath, ... }: { - imports = - [ (modulesPath + "/installer/scan/not-detected.nix") - ]; + imports = [ + (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.kernelModules = [ "dm-snapshot" ]; diff --git a/home.nix b/src/hosts/pickwick/home.nix similarity index 72% rename from home.nix rename to src/hosts/pickwick/home.nix index e954d3a..d1b24f2 100644 --- a/home.nix +++ b/src/hosts/pickwick/home.nix @@ -26,101 +26,6 @@ ".bash_history" ".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; };