151 lines
4.3 KiB
Nix
151 lines
4.3 KiB
Nix
|
# nix run github:nix-community/disko -- --mode zap_create_mount ./disko-config.nix
|
||
|
# nixos-generate-config --no-filesystems --root /mnt
|
||
|
# vim /mnt/configuration.nix
|
||
|
# nixos-install
|
||
|
{ config, lib, ... }:
|
||
|
let
|
||
|
disks = [ "sda" "sdb" ];
|
||
|
in
|
||
|
{
|
||
|
# ZFS already has its own scheduler. Without this my(@Artturin) computer froze for a second when i nix build something.
|
||
|
# copied from : https://github.com/numtide/srvos/blob/main/nixos/common/zfs.nix
|
||
|
|
||
|
services.udev.extraRules = lib.optionalString (config.boot.zfs.enabled) ''
|
||
|
ACTION=="add|change", KERNEL=="sd[a-z]*[0-9]*|mmcblk[0-9]*p[0-9]*|nvme[0-9]*n[0-9]*p[0-9]*", ENV{ID_FS_TYPE}=="zfs_member", ATTR{../queue/scheduler}="none"
|
||
|
'';
|
||
|
|
||
|
disko.devices = {
|
||
|
disk =
|
||
|
lib.genAttrs disks (disk: {
|
||
|
name = disk;
|
||
|
type = "disk";
|
||
|
device = "/dev/${disk}";
|
||
|
content = {
|
||
|
type = "table";
|
||
|
format = "gpt";
|
||
|
partitions = [
|
||
|
{
|
||
|
name = "ESP";
|
||
|
start = "0";
|
||
|
end = "500MiB";
|
||
|
bootable = true;
|
||
|
content = {
|
||
|
type = "filesystem";
|
||
|
format = "vfat";
|
||
|
mountpoint = "/boot_${disk}";
|
||
|
mountOptions = [ "defaults" ];
|
||
|
};
|
||
|
}
|
||
|
{
|
||
|
name = "zfs";
|
||
|
start = "500MiB";
|
||
|
size = "500GB";
|
||
|
content = {
|
||
|
type = "luks";
|
||
|
name = "root_${disk}";
|
||
|
settings = {
|
||
|
# if you want to use the key for interactive login be sure there is no trailing newline
|
||
|
# for example use `echo -n "password" > /tmp/secret.key`
|
||
|
keyFile = "/tmp/secret.key";
|
||
|
allowDiscards = true;
|
||
|
};
|
||
|
content = {
|
||
|
type = "zfs";
|
||
|
pool = "zroot";
|
||
|
};
|
||
|
};
|
||
|
}
|
||
|
{
|
||
|
name = "zfs";
|
||
|
size = "100%";
|
||
|
content = {
|
||
|
type = "luks";
|
||
|
settings = {
|
||
|
# if you want to use the key for interactive login be sure there is no trailing newline
|
||
|
# for example use `echo -n "password" > /tmp/secret.key`
|
||
|
keyFile = "/tmp/secret.key";
|
||
|
allowDiscards = true;
|
||
|
};
|
||
|
name = "media_${disk}";
|
||
|
content = {
|
||
|
type = "zfs";
|
||
|
pool = "zmedia";
|
||
|
};
|
||
|
};
|
||
|
}
|
||
|
];
|
||
|
};
|
||
|
}
|
||
|
);
|
||
|
|
||
|
|
||
|
zpool = {
|
||
|
|
||
|
zroot = {
|
||
|
type = "zpool";
|
||
|
mode = "mirror";
|
||
|
rootFsOptions = {
|
||
|
mountpoint = "none";
|
||
|
canmount = "off";
|
||
|
compression = "lz4";
|
||
|
};
|
||
|
datasets = {
|
||
|
"root" = {
|
||
|
type = "zfs_fs";
|
||
|
mountpoint = "/";
|
||
|
options = {
|
||
|
mountpoint = "legacy";
|
||
|
compression = "lz4";
|
||
|
};
|
||
|
};
|
||
|
"store" = {
|
||
|
type = "zfs_fs";
|
||
|
mountpoint = "/nix/store";
|
||
|
options = {
|
||
|
mountpoint = "legacy";
|
||
|
compression = "lz4";
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
# `zpool import -f zraid` once on the first boot and reboot
|
||
|
zmedia = {
|
||
|
type = "zpool";
|
||
|
rootFsOptions = {
|
||
|
mountpoint = "none";
|
||
|
canmount = "off";
|
||
|
};
|
||
|
datasets = {
|
||
|
"media" = {
|
||
|
type = "zfs_fs";
|
||
|
mountpoint = "/media";
|
||
|
options = {
|
||
|
mountpoint = "legacy";
|
||
|
compression = "lz4";
|
||
|
"com.sun:auto-snapshot:daily" = false;
|
||
|
"com.sun:auto-snapshot:weekly" = false;
|
||
|
"com.sun:auto-snapshot:monthly" = false;
|
||
|
};
|
||
|
};
|
||
|
# todo make sure this disk has some minimum space
|
||
|
"nextcloud" = {
|
||
|
type = "zfs_fs";
|
||
|
mountpoint = "/var/lib/nextcloud/";
|
||
|
options = {
|
||
|
mountpoint = "legacy";
|
||
|
compression = "lz4";
|
||
|
"com.sun:auto-snapshot:hourly" = true;
|
||
|
"com.sun:auto-snapshot:daily" = true;
|
||
|
"com.sun:auto-snapshot:weekly" = false;
|
||
|
"com.sun:auto-snapshot:monthly" = false;
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|