Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
qbisi committed Sep 14, 2024
1 parent aae4fc3 commit 33bc8ff
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 108 deletions.
68 changes: 43 additions & 25 deletions devices/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,61 @@
...
}:
with lib;
with self.lib;
let
device = [
"nixos-x86_64-generic-btrfs"
];
x86_64-devices = cartesianProduct {
name = listNixname "${self}/devices/x86_64-linux";
system = [ "x86_64-linux" ];
};
aarch64-devices = cartesianProduct {
name = [ ];
system = [ "aarch64-linux" ];
};
devices = x86_64-devices ++ aarch64-devices;
diskType = [
"mmc"
"sd"
"usb"
"nvme"
"scsi"
];
imageNames = mapCartesianProduct ({ device, diskType }: "${device}-${diskType}") {
inherit device diskType;
};
images =
mapCartesianProduct
(
{ devices, diskType }:
{
name = "${devices.name}-${diskType}";
device = devices.name;
inherit diskType;
inherit (devices) system;
}
)
{
inherit devices diskType;
};
in
{
flake = rec {
nixosConfigurations = listToAttrs (
mapCartesianProduct (
{ device, diskType }:
(nameValuePair "${device}-${diskType}" (
lib.nixosSystem {
specialArgs = {
inherit inputs self;
};
modules = [
{ disko.type = diskType; disko.label = device; }
./${device}.nix
self.nixosModules.default
inputs.disko.nixosModules.default
];
flake = {
nixosConfigurations = genAttrs' images (
image:
(lib.nixosSystem {
system = image.system;
specialArgs = {
inherit inputs self;
};
modules = [
{
disko.type = image.diskType;
disko.label = image.device;
}
))
) { inherit device diskType; }
./${image.system}/${image.device}.nix
self.nixosModules.default
inputs.disko.nixosModules.default
];
})
);
images = genAttrs imageNames (
imageName: nixosConfigurations.${imageName}.config.system.build.diskoImages
images = genAttrs' images (
image: self.nixosConfigurations.${image.name}.config.system.build.diskoImages
);
};
}
17 changes: 17 additions & 0 deletions devices/x86_64-linux/nixos-x86_64-generic-btrfs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
config,
pkgs,
lib,
modulesPath,
inputs,
self,
...
}:
{
imports = [
./nixos-x86_64-uefi-btrfs.nix
];

disko.biosboot.enable = true;
boot.loader.grub.device = "/dev/disk/by-diskseq/1";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
...
}:
{
nixpkgs = {
system = "x86_64-linux";
};

imports = [
(modulesPath + "/profiles/all-hardware.nix")
self.nixosModules.hybrid-btrfs
self.nixosModules.btrfs
];

boot = {
Expand All @@ -31,7 +27,6 @@
enable = true;
efiSupport = true;
efiInstallAsRemovable = true;
device = "/dev/disk/by-diskseq/1";
extraConfig = ''
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal_input --append serial
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
imports = [
./devices
./modules
./lib
];
perSystem =
{ config, pkgs, ... }:
Expand Down
11 changes: 11 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
self,
inputs,
lib,
...
}:
{
flake = {
lib = import ./lib.nix { inherit self inputs lib; };
};
}
15 changes: 15 additions & 0 deletions lib/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
self,
inputs,
lib,
...
}:
with lib;
rec {
genAttrs' = items: v: listToAttrs (map (item: nameValuePair item.name (v item)) items);

listNixfile =
path: with builtins; filter (name: match "(.+)\\.nix" name != null) (attrNames (readDir path));

listNixname = path: with builtins; map (file: head (match "(.+)\\.nix" file)) (listNixfile path);
}
7 changes: 7 additions & 0 deletions modules/all-modules.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
config,
lib,
pkgs,
...
}:
{
imports = [
./disko/label.nix
./system/grow-partition.nix
];
system.stateVersion = config.system.nixos.release;
}
2 changes: 1 addition & 1 deletion modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
./all-modules.nix
];
};
hybrid-btrfs = ./disko/hybrid-btrfs.nix;
btrfs = ./disko/btrfs.nix;
};
};
}
98 changes: 98 additions & 0 deletions modules/disko/btrfs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{ config, lib, ... }:
let
device = config.boot.loader.grub.device;
partitions =
if config.disko.biosboot.enable then
{
boot = {
size = "1M";
type = "EF02";
priority = 0;
};
}
else
{ };
in
{
options = {
disko.biosboot.enable = lib.mkOption {
default = false;
example = true;
type = lib.types.bool;
description = ''
Whether to enable biosboot part in gptdisk
'';
};
};

config = {
disko = {
enableConfig = true;
devices = {
disk.main = {
name = config.disko.type;
imageSize = "2G";
device = if (device != "") then device else "/dev/disk/by-diskseq/1";
type = "disk";
content = {
type = "gpt";
partitions = partitions // {
ESP = {
name = "ESP";
size = "4M";
type = "EF00";
priority = 1;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot/efi";
mountOptions = [
"fmask=0077"
"dmask=0077"
];
};
};
nix = {
size = "100%";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/" = {
mountOptions = [ "noatime" ];
mountpoint = "/.btrfs_root";
};
"/@" = {
mountOptions = [
"compress=zstd"
"noatime"
];
mountpoint = "/";
};
"/@var" = {
mountOptions = [
"compress=zstd"
"noatime"
];
mountpoint = "/var";
};
"/@home" = {
mountOptions = [
"compress=zstd"
"noatime"
];
mountpoint = "/home";
};
"/@swap" = {
mountpoint = "/swap";
};
};
};
};
};
};
};
};
};
};
}
76 changes: 0 additions & 76 deletions modules/disko/hybrid-btrfs.nix

This file was deleted.

0 comments on commit 33bc8ff

Please sign in to comment.