Skip to content

Commit

Permalink
Implement disko as a module
Browse files Browse the repository at this point in the history
This allows us to build it independently when bootstraping a system
  • Loading branch information
Baitinq committed Aug 25, 2022
1 parent 6d2e193 commit eb159f1
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 106 deletions.
109 changes: 3 additions & 106 deletions hosts/luna/disks.nix
Original file line number Diff line number Diff line change
@@ -1,104 +1,7 @@
{ inputs, pkgs, ... }:
let
partitionsConfig = {
type = "devices";
content = {
"disk/by-path/platform-80860F14:00" = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-label = "efi";
flags = [ "esp" ];
start = "0";
end = "64M";
fs-type = "fat32";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot/esp";
};
}
{
type = "partition";
start = "64M";
end = "264M";
part-label = "boot";
content = {
type = "luks";
name = "encrypted_boot";
extraArgs = [ "--type luks1" ];
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/boot";
};
};
}
{
type = "partition";
start = "264M";
end = "100%";
part-label = "nix";
content = {
type = "luks";
name = "encrypted_nix";
extraArgs = [ "--type luks2" ];
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/nix";
};
};
}
];
};
"disk/by-path/pci-0000:00:14.0-usb-0:2.3:1.0-scsi-0:0:0:0" = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-label = "home_and_persist";
start = "0";
end = "100%";
content = {
type = "luks";
name = "encrypted_home_and_persist";
extraArgs = [ "--type luks2" ];
content = {
type = "lvm";
name = "pool";
lvs = {
_persist = {
type = "lv";
size = "4G";
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/persist";
};
};
home = {
type = "lv";
size = "100%FREE";
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/home";
};
};
};
};
};
}
];
};
};
};
in
{ inputs, lib, config, pkgs, ... }:
{
imports = [ ./partitions.nix ];

fileSystems."/" = {
device = "none";
fsType = "tmpfs";
Expand Down Expand Up @@ -149,10 +52,4 @@ in

zramSwap.enable = true;


environment.systemPackages = with pkgs;[
parted
(pkgs.writeScriptBin "disko-create" (inputs.disko.lib.create partitionsConfig))
(pkgs.writeScriptBin "disko-mount" (inputs.disko.lib.mount partitionsConfig))
];
}
125 changes: 125 additions & 0 deletions hosts/luna/partitions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{ inputs, lib, config, pkgs, ... }:
let
partitionsConfig = {
type = "devices";
content = {
"disk/by-path/platform-80860F14:00" = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-label = "efi";
flags = [ "esp" ];
start = "0";
end = "64M";
fs-type = "fat32";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot/esp";
};
}
{
type = "partition";
start = "64M";
end = "264M";
part-label = "boot";
content = {
type = "luks";
name = "encrypted_boot";
extraArgs = [ "--type luks1" ];
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/boot";
};
};
}
{
type = "partition";
start = "264M";
end = "100%";
part-label = "nix";
content = {
type = "luks";
name = "encrypted_nix";
extraArgs = [ "--type luks2" ];
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/nix";
};
};
}
];
};
"disk/by-path/pci-0000:00:14.0-usb-0:2.3:1.0-scsi-0:0:0:0" = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-label = "home_and_persist";
start = "0";
end = "100%";
content = {
type = "luks";
name = "encrypted_home_and_persist";
extraArgs = [ "--type luks2" ];
content = {
type = "lvm";
name = "pool";
lvs = {
_persist = {
type = "lv";
size = "4G";
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/persist";
};
};
home = {
type = "lv";
size = "100%FREE";
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/home";
};
};
};
};
};
}
];
};
};
};
in
{
options.disko-create = with lib; mkOption {
type = types.package;
default = pkgs.buildEnv {
name = "disko-create";
paths = [ (pkgs.writeScriptBin "disko-create" (inputs.disko.lib.create partitionsConfig)) pkgs.parted ];
};
};

options.disko-mount = with lib; mkOption {
type = types.package;
default = pkgs.buildEnv {
name = "disko-mount";
paths = [ (pkgs.writeScriptBin "disko-mount" (inputs.disko.lib.mount partitionsConfig)) pkgs.parted ];
};
};

config = {
environment.systemPackages = [
config.disko-create
config.disko-mount
];
};

}

0 comments on commit eb159f1

Please sign in to comment.