From 7a547f99c0f40a52d845b6d4091559e1e800e325 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sat, 25 Feb 2023 09:45:49 -0500 Subject: [PATCH] add disko input and hardware module for swan --- flake.lock | 21 ++ flake.nix | 8 + hosts/swan/default.nix | 10 +- hosts/swan/disks.nix | 272 +++++++++++++++----------- hosts/swan/hardware-configuration.nix | 29 +++ 5 files changed, 219 insertions(+), 121 deletions(-) create mode 100644 hosts/swan/hardware-configuration.nix diff --git a/flake.lock b/flake.lock index 5997d31..5e23f7f 100644 --- a/flake.lock +++ b/flake.lock @@ -69,6 +69,26 @@ "type": "github" } }, + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1677116397, + "narHash": "sha256-2OHwhv4k1SDEuNxhq+zluvrd5pbW8d4TP9NKW4B8iO8=", + "owner": "nix-community", + "repo": "disko", + "rev": "8fddb2fd721365fa77ff68b709539639d4dc65d7", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "firefox-darwin": { "inputs": { "nixpkgs": "nixpkgs" @@ -396,6 +416,7 @@ "bufferline-nvim-src": "bufferline-nvim-src", "cmp-nvim-lsp-src": "cmp-nvim-lsp-src", "darwin": "darwin", + "disko": "disko", "firefox-darwin": "firefox-darwin", "home-manager": "home-manager", "nil": "nil", diff --git a/flake.nix b/flake.nix index 55c564c..7c2cab3 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,12 @@ # Use official Firefox binary for macOS firefox-darwin.url = "github:bandithedoge/nixpkgs-firefox-darwin"; + # Manage disk format and partitioning + disko = { + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + # Wallpapers wallpapers = { url = "gitlab:exorcist365/wallpapers"; @@ -146,6 +152,8 @@ darwinConfigurations.lookingglass.config.home-manager.users."Noah.Masur".home; }; + diskoConfiguration = { swan = import ./hosts/swan/disks.nix { }; }; + # Package servers into images with a generator packages = forAllSystems (system: { diff --git a/hosts/swan/default.nix b/hosts/swan/default.nix index 024cdd4..ba632f0 100644 --- a/hosts/swan/default.nix +++ b/hosts/swan/default.nix @@ -10,11 +10,13 @@ nixpkgs.lib.nixosSystem { specialArgs = { }; modules = [ ./hardware-configuration.nix + ./disks.nix ../../modules/common ../../modules/nixos (removeAttrs globals [ "mail.server" ]) wsl.nixosModules.wsl home-manager.nixosModules.home-manager + disko.nixosModules.disko { server = true; gui.enable = false; @@ -37,11 +39,11 @@ nixpkgs.lib.nixosSystem { boot.zfs.enabled = true; boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; - boot.zfs.extraPools = [ "mypool" ]; - services.zfs.autoScrub.enable = true; - services.zfs.autoScrub.interval = "daily"; + # boot.zfs.extraPools = [ "mypool" ]; + # services.zfs.autoScrub.enable = true; + # services.zfs.autoScrub.interval = "daily"; - services.nfs.server.enable = true; + # services.nfs.server.enable = true; } ]; diff --git a/hosts/swan/disks.nix b/hosts/swan/disks.nix index f1d139c..b12d919 100644 --- a/hosts/swan/disks.nix +++ b/hosts/swan/disks.nix @@ -1,129 +1,167 @@ -{ bootDisk, storageDisks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { - disk = { - boot = { - type = "disk"; - device = "/dev/whatever"; - content = { - type = "table"; - format = "gpt"; - partitions = [ - { +{ ... }: { + disko.devices = { + disk = { + boot = { + type = "disk"; + device = "/dev/nvme0n1"; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + type = "partition"; + name = "ESP"; + start = "0"; + end = "512MiB"; + fs-type = "fat32"; + bootable = true; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + } + { + type = "partition"; + name = "root"; + start = "512MiB"; + end = "100%"; + part-type = "primary"; + bootable = true; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + } + ]; + }; + }; + sda = { + type = "disk"; + device = "/dev/sda"; + content = { + type = "table"; + format = "gpt"; + partitions = [{ type = "partition"; - name = "ESP"; - start = "0"; - end = "512MiB"; - fs-type = "fat32"; - bootable = true; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - }; - } - { - type = "partition"; - name = "root"; - start = "512MiB"; + name = "zfs"; + start = "128MiB"; end = "100%"; - part-type = "primary"; - bootable = true; content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; + type = "zfs"; + pool = "tank"; }; - } - ]; + }]; + }; + }; + sdb = { + type = "disk"; + device = "/dev/sdb"; + content = { + type = "table"; + format = "gpt"; + partitions = [{ + type = "partition"; + name = "zfs"; + start = "128MiB"; + end = "100%"; + content = { + type = "zfs"; + pool = "tank"; + }; + }]; + }; + }; + sdc = { + type = "disk"; + device = "/dev/sdc"; + content = { + type = "table"; + format = "gpt"; + partitions = [{ + type = "partition"; + name = "zfs"; + start = "128MiB"; + end = "100%"; + content = { + type = "zfs"; + pool = "tank"; + }; + }]; + }; }; }; - a = { - type = "disk"; - device = builtins.elemAt storageDisks 1; - content = { - type = "table"; - format = "gpt"; - partitions = [{ - type = "partition"; - name = "zfs"; - start = "128MiB"; - end = "100%"; - content = { - type = "zfs"; - pool = "tank"; - }; - }]; - }; - }; - }; - zpool = { - tank = { - type = "zpool"; - mode = "raidz1"; - rootFsOptions = { - compression = "on"; # lz4 by default - "com.sun:auto-snapshot" = "false"; - ashift = 12; - }; - # mountpoint = "/"; + zpool = { + tank = { + type = "zpool"; + mode = "raidz1"; + rootFsOptions = { + compression = "on"; # lz4 by default + "com.sun:auto-snapshot" = "false"; + ashift = 12; + }; + # mountpoint = "/"; - datasets = { - media = { - zfs_type = "filesystem"; - mountpoint = "none"; - options."com.sun:auto-snapshot" = "false"; - }; - # "media/movies" = { - # zfs_type = "filesystem"; - # mountpoint = "/media/movies"; - # options.recordsize = "1M"; - # }; - # "media/tv" = { - # zfs_type = "filesystem"; - # mountpoint = "/media/tv"; - # options.recordsize = "1M"; - # }; - # "media/books" = { - # zfs_type = "filesystem"; - # mountpoint = "/media/books"; - # }; - # archive = { - # zfs_type = "filesystem"; - # mountpoint = "/archive"; - # options.compression = "zstd"; - # options."com.sun:auto-snapshot" = "true"; - # }; - # zfs_unmounted_fs = { - # zfs_type = "filesystem"; - # options.mountpoint = "none"; - # }; - # zfs_legacy_fs = { - # zfs_type = "filesystem"; - # options.mountpoint = "legacy"; - # mountpoint = "/zfs_legacy_fs"; - # }; - # zfs_testvolume = { - # zfs_type = "volume"; - # size = "10M"; - # content = { - # type = "filesystem"; - # format = "ext4"; - # mountpoint = "/ext4onzfs"; - # }; - # }; - encrypted = { - zfs_type = "filesystem"; - size = "20M"; - options = { + datasets = { + media = { + zfs_type = "filesystem"; mountpoint = "none"; - encryption = "aes-256-gcm"; - keyformat = "passphrase"; - keylocation = "file:///tmp/secret.key"; + options."com.sun:auto-snapshot" = "false"; }; - }; - "encrypted/test" = { - zfs_type = "filesystem"; - size = "2M"; - mountpoint = "/zfs_crypted"; + # "media/movies" = { + # zfs_type = "filesystem"; + # mountpoint = "/media/movies"; + # options.recordsize = "1M"; + # }; + # "media/tv" = { + # zfs_type = "filesystem"; + # mountpoint = "/media/tv"; + # options.recordsize = "1M"; + # }; + # "media/books" = { + # zfs_type = "filesystem"; + # mountpoint = "/media/books"; + # }; + # archive = { + # zfs_type = "filesystem"; + # mountpoint = "/archive"; + # options.compression = "zstd"; + # options."com.sun:auto-snapshot" = "true"; + # }; + # zfs_unmounted_fs = { + # zfs_type = "filesystem"; + # options.mountpoint = "none"; + # }; + # zfs_legacy_fs = { + # zfs_type = "filesystem"; + # options.mountpoint = "legacy"; + # mountpoint = "/zfs_legacy_fs"; + # }; + # zfs_testvolume = { + # zfs_type = "volume"; + # size = "10M"; + # content = { + # type = "filesystem"; + # format = "ext4"; + # mountpoint = "/ext4onzfs"; + # }; + # }; + # encrypted = { + # zfs_type = "filesystem"; + # size = "20M"; + # options = { + # mountpoint = "none"; + # encryption = "aes-256-gcm"; + # keyformat = "passphrase"; + # keylocation = "file:///tmp/secret.key"; + # }; + # }; + # "encrypted/test" = { + # zfs_type = "filesystem"; + # size = "2M"; + # mountpoint = "/zfs_crypted"; + # }; }; }; }; diff --git a/hosts/swan/hardware-configuration.nix b/hosts/swan/hardware-configuration.nix new file mode 100644 index 0000000..bcf62c3 --- /dev/null +++ b/hosts/swan/hardware-configuration.nix @@ -0,0 +1,29 @@ +# 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, ... }: + +{ + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + + boot.initrd.availableKernelModules = + [ "xhci_pci" "ahci" "nvme" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + swapDevices = [ ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp0s31f6.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp3s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; + hardware.cpu.intel.updateMicrocode = + lib.mkDefault config.hardware.enableRedistributableFirmware; +}