Git Product home page Git Product logo

disko's Introduction

disko - declarative disk partitioning

Disko takes the NixOS module system and makes it work for disk partitioning as well.

I wanted to write a curses NixOS installer, and that was the first step that I hit; the disk formatting is a manual process. Once that's done, the NixOS system itself is declarative, but the actual formatting of disks is manual.

Features

  • supports LVM, ZFS, btrfs, GPT, mdadm, ext4, ...
  • supports recursive layouts
  • outputs a NixOS-compatible module
  • CLI

How-to guides

NixOS installation

For a NixOS installation follow this quickstart guid.

Using without NixOS

Reference

Module options

TODO: link to generated module options

Examples

./examples

CLI

$ nix run github:nix-community/disko --

disko [options] disk-config.nix
or disko [options] --flake github:somebody/somewhere

Options:

* -m, --mode mode
  set the mode, either create or mount
* -f, --flake uri
  fetch the disko config relative to this flake's root
* --arg name value
  pass value to nix-build. can be used to set disk-names for example
* --argstr name value
  pass value to nix-build as string
* --root-mountpoint /mnt
  where to mount the device tree
* --dry-run
  just show the path to the script instead of running it
* --debug
  run with set -x

Installing NixOS module

You can use the NixOS module in one of the following ways:

Flakes (Current recommendation)

If you use nix flakes support:

{
  inputs.disko.url = "github:nix-community/disko";
  inputs.disko.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, disko }: {
    # change `yourhostname` to your actual hostname
    nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
      # change to your system:
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        disko.nixosModules.disko
      ];
    };
  };
}
niv

First add it to niv:

$ niv add nix-community/disko

Then add the following to your configuration.nix in the imports list:

{
  imports = [ "${(import ./nix/sources.nix).disko}/modules/disko.nix" ];
}
nix-channel

As root run:

$ nix-channel --add https://github.com/nix-community/disko/archive/master.tar.gz disko
$ nix-channel --update

Then add the following to your configuration.nix in the imports list:

{
  imports = [ <disko/modules/disko.nix> ];
}
fetchTarball

Add the following to your configuration.nix:

{
  imports = [ "${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix" ];
}

or with pinning:

{
  imports = let
    # replace this with an actual commit id or tag
    commit = "f2783a8ef91624b375a3cf665c3af4ac60b7c278";
  in [ 
    "${builtins.fetchTarball {
      url = "https://github.com/nix-community/disko/archive/${commit}.tar.gz";
      # replace this with an actual hash
      sha256 = "0000000000000000000000000000000000000000000000000000";
    }}/module.nix"
  ];
}

Using the NixOS module

{
  # checkout the example folder for how to configure different disko layouts
  disko.devices = {
    disk.sda = {
      device = "/dev/sda";
      type = "disk";
      content = {
        type = "table";
        format = "gpt";
        partitions = [
          {
            type = "partition";
            name = "ESP";
            start = "1MiB";
            end = "100MiB";
            bootable = true;
            content = {
              type = "filesystem";
              format = "vfat";
              mountpoint = "/boot";
            };
          }
          {
            name = "root";
            type = "partition";
            start = "100MiB";
            end = "100%";
            part-type = "primary";
            bootable = true;
            content = {
              type = "filesystem";
              format = "ext4";
              mountpoint = "/";
            };
          }
        ];
      };
    };
  };
}

this will configure fileSystems and other required NixOS options to boot the specified configuration.

If you are on an installer, you probably want to disable enableConfig.

disko will create the scripts disko-create and disko-mount which can be used to create/mount the configured disk layout.

disko's People

Contributors

4z3 avatar a-kenji avatar aidenscott2016 avatar baitinq avatar blaggacao avatar bors[bot] avatar cscutcher avatar dependabot[bot] avatar github-actions[bot] avatar kranzes avatar l0b0 avatar lassulus avatar lilyinstarlight avatar makefu avatar matthewcash avatar mergify[bot] avatar mic92 avatar mweinelt avatar phaer avatar rosscomputerguy avatar tomaszal avatar yajo avatar zimbatm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.