mirror of
https://github.com/nix-community/disko.git
synced 2024-09-11 06:25:33 +03:00
add module
This commit is contained in:
parent
c777d1ca4f
commit
4184cbcd03
198
README.md
198
README.md
@ -1,80 +1,140 @@
|
|||||||
disko
|
# disko
|
||||||
=====
|
|
||||||
|
|
||||||
nix-powered automatic disk partitioning
|
nix-powered automatic disk partitioning. partition your disks declaratively NixOS style.
|
||||||
|
|
||||||
Usage
|
## Installing NixOS module
|
||||||
=====
|
|
||||||
|
|
||||||
Master Boot Record
|
You can use the NixOS module in one of the following ways:
|
||||||
------------------
|
|
||||||
This is how your iso configuation may look like
|
|
||||||
|
|
||||||
/etc/nixos/configuration.nix
|
### Flakes
|
||||||
```nix
|
|
||||||
{ pkgs, modulesPath, ... }:
|
If you use nix flakes support:
|
||||||
let
|
|
||||||
disko = pkgs.callPackage (builtins.fetchGit {
|
``` nix
|
||||||
url = "https://github.com/nix-community/disko";
|
{
|
||||||
ref = "master";
|
inputs.disko.url = "github:nix-community/disko";
|
||||||
}) {};
|
inputs.disko.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
cfg = {
|
|
||||||
disk = {
|
outputs = { self, nixpkgs, disko }: {
|
||||||
sda = {
|
# change `yourhostname` to your actual hostname
|
||||||
device = "/dev/sda";
|
nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
|
||||||
type = "device";
|
# change to your system:
|
||||||
content = {
|
system = "x86_64-linux";
|
||||||
type = "table";
|
modules = [
|
||||||
format = "msdos";
|
./configuration.nix
|
||||||
partitions = [
|
disko.nixosModules.disko
|
||||||
{
|
];
|
||||||
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`
|
### [niv](https://github.com/nmattia/niv) (Current recommendation)
|
||||||
command:
|
First add it to niv:
|
||||||
|
|
||||||
- **tsp-create**: creates & formats the partitions according to `tsp-disk.json`
|
```console
|
||||||
- **tsp-mount**: mounts the partitions to `/mnt`
|
$ niv add nix-community/disko
|
||||||
|
```
|
||||||
|
|
||||||
GUID Partition Table, LVM and dm-crypt
|
Then add the following to your configuration.nix in the `imports` list:
|
||||||
--------------------------------------
|
|
||||||
See `examples/`
|
```nix
|
||||||
|
{
|
||||||
|
imports = [ "${(import ./nix/sources.nix).disko}/modules/disko.nix" ];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### nix-channel
|
||||||
|
|
||||||
|
As root run:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ nix-channel --add https://github.com/nix-community/disko/archive/main.tar.gz disko
|
||||||
|
$ nix-channel --update
|
||||||
|
```
|
||||||
|
|
||||||
|
Then add the following to your configuration.nix in the `imports` list:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
imports = [ <disko/modules/disko.nix> ];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### fetchTarball
|
||||||
|
|
||||||
|
Add the following to your configuration.nix:
|
||||||
|
|
||||||
|
``` nix
|
||||||
|
{
|
||||||
|
imports = [ "${builtins.fetchTarball "https://github.com/nix-community/disko/archive/main.tar.gz"}/modules/disko.nix" ];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
or with pinning:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
# checkout the example folder for how to configure different diska 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.
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
outputs = { self, nixpkgs, ... }: {
|
outputs = { self, nixpkgs, ... }: {
|
||||||
|
nixosModules.disko = import ./module.nix;
|
||||||
lib = import ./. {
|
lib = import ./. {
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
};
|
};
|
||||||
|
43
module.nix
Normal file
43
module.nix
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
types = import ./types.nix { inherit lib; };
|
||||||
|
cfg = config.disko;
|
||||||
|
in {
|
||||||
|
options.disko = {
|
||||||
|
devices = lib.mkOption {
|
||||||
|
type = types.devices;
|
||||||
|
};
|
||||||
|
enableConfig = lib.mkOption {
|
||||||
|
description = ''
|
||||||
|
configure nixos with the specified devices
|
||||||
|
should be true if the system is booted with those devices
|
||||||
|
should be false on an installer image etc.
|
||||||
|
'';
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
addScripts = lib.mkOption {
|
||||||
|
description = ''
|
||||||
|
add disko-create and disko-mount scripts to systemPackages.
|
||||||
|
'';
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = {
|
||||||
|
environment.systemPackages = (lib.optionals cfg.addScripts [
|
||||||
|
(pkgs.writers.writeDashBin "disko-create" ''
|
||||||
|
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}
|
||||||
|
${types.diskoLib.create cfg.devices}
|
||||||
|
'')
|
||||||
|
(pkgs.writers.writeDashBin "disko-mount" ''
|
||||||
|
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}
|
||||||
|
${types.diskoLib.mount cfg.devices}
|
||||||
|
'')
|
||||||
|
]) ++ lib.optionals cfg.enableConfig (types.diskoLib.packages cfg.devices pkgs);
|
||||||
|
|
||||||
|
# Remember to add config keys here if they are added to types
|
||||||
|
fileSystems = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "fileSystems" (types.diskoLib.config cfg.devices)));
|
||||||
|
boot = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "boot" (types.diskoLib.config cfg.devices)));
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user