From 3c941b4ce2b8dabcb400fca937ff0b70a2927a90 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 7 Jan 2024 16:43:43 +0000 Subject: [PATCH] partial btrfs support doesn't actually know how to make the filesystem, just kernel config and accept it as a valid option --- examples/rotuer.nix | 3 +++ modules/base.nix | 1 + modules/outputs/btrfs.nix | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 modules/outputs/btrfs.nix diff --git a/examples/rotuer.nix b/examples/rotuer.nix index 058eff2..c7890bf 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -43,8 +43,11 @@ in rec { ../modules/bridge ../modules/ntp ../modules/ssh + ../modules/outputs/btrfs.nix + ]; hostname = "rotuer"; + rootfsType = "btrfs"; services.hostap = svc.hostapd.build { interface = config.hardware.networkInterfaces.wlan; diff --git a/modules/base.nix b/modules/base.nix index 11357ab..0826ce8 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -40,6 +40,7 @@ in { rootfsType = mkOption { default = "squashfs"; type = types.enum [ + "btrfs" "ext4" "jffs2" "squashfs" diff --git a/modules/outputs/btrfs.nix b/modules/outputs/btrfs.nix new file mode 100644 index 0000000..3617724 --- /dev/null +++ b/modules/outputs/btrfs.nix @@ -0,0 +1,37 @@ +{ + config +, pkgs +, lib +, ... +}: +let + inherit (lib) mkIf mkOption types; + o = config.system.outputs; +in +{ + imports = [ + ./initramfs.nix + ]; + config = mkIf (config.rootfsType == "btrfs") { + kernel.config = { + BTRFS_FS = "y"; + }; + boot.initramfs.enable = true; + system.outputs = { + rootfs = + let + inherit (pkgs.pkgsBuildBuild) runCommand e2fsprogs; + in runCommand "mkfs.btrfs" { + depsBuildBuild = [ e2fsprogs ]; + } '' + tree=${o.bootablerootdir} + size=$(du -s --apparent-size --block-size 1024 $tree |cut -f1) + # add 25% for filesystem overhead + size=$(( 5 * $size / 4)) + dd if=/dev/zero of=$out bs=1024 count=$size + echo "not implemented" ; exit 1 + # mke2fs -t ext4 -j -d $tree $out + ''; + }; + }; +}