disko/README.md
2022-09-04 13:12:43 +02:00

1.9 KiB

disko

nix-powered automatic disk partitioning

Usage

Master Boot Record

This is how your iso configuation may look like

/etc/nixos/configuration.nix

{ pkgs, modulesPath, ... }:
let
  disko = pkgs.callPackage (builtins.fetchGit {
    url = "https://github.com/nix-community/disko";
    ref = "master";
  }) {};
  cfg = {
    disk = {
      sda = {
        device = "/dev/sda";
        type = "device";
        content = {
          type = "table";
          format = "msdos";
          partitions = [
            {
              name = "root";
              type = "partition";
              part-type = "primary";
              start = "1M";
              end = "100%";
              bootable = true;
              content = {
                type = "filesystem";
                format = "ext4";
                mountpoint = "/";
              };
            }
          ];
        };
      };
    };
  };
in {
  imports = [
    (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")
  ];
  environment.systemPackages = with pkgs;[
    (pkgs.writeScriptBin "tsp-create" (disko.create cfg))
    (pkgs.writeScriptBin "tsp-mount" (disko.mount cfg))
  ];
  ## Optional: Automatically creates a service which runs at startup to perform the partitioning
  #systemd.services.install-to-hd = {
  #  enable = true;
  #  wantedBy = ["multi-user.target"];
  #  after = ["getty@tty1.service" ];
  #  serviceConfig = {
  #    Type = "oneshot";
  #    ExecStart = [ (disko.create cfg) (disk.mount cfg) ];
  #    StandardInput = "null";
  #    StandardOutput = "journal+console";
  #    StandardError = "inherit";
  #  };
  #};
}

After nixos-rebuild switch this will add a tsp-create and a tsp-mount command:

  • tsp-create: creates & formats the partitions according to tsp-disk.json
  • tsp-mount: mounts the partitions to /mnt

GUID Partition Table, LVM and dm-crypt

See examples/