mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-11 23:50:05 +01:00
types: refactor into diskoLib
This commit is contained in:
parent
efb2016c8e
commit
22b33a4fd6
21 changed files with 146 additions and 146 deletions
46
default.nix
46
default.nix
|
|
@ -3,45 +3,45 @@
|
||||||
, checked ? false
|
, checked ? false
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
types = import ./types { inherit lib rootMountPoint; };
|
diskoLib = import ./lib { inherit lib rootMountPoint; };
|
||||||
eval = cfg: lib.evalModules {
|
eval = cfg: lib.evalModules {
|
||||||
modules = lib.singleton {
|
modules = lib.singleton {
|
||||||
# _file = toString input;
|
# _file = toString input;
|
||||||
imports = lib.singleton { disko.devices = cfg.disko.devices; };
|
imports = lib.singleton { disko.devices = cfg.disko.devices; };
|
||||||
options = {
|
options = {
|
||||||
disko.devices = lib.mkOption {
|
disko.devices = lib.mkOption {
|
||||||
type = types.devices;
|
type = diskoLib.devices;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
types = types;
|
lib = diskoLib;
|
||||||
create = cfg: types.diskoLib.create (eval cfg).config.disko.devices;
|
create = cfg: diskoLib.create (eval cfg).config.disko.devices;
|
||||||
createScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" ''
|
createScript = cfg: pkgs: (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" ''
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
|
export PATH=${lib.makeBinPath (diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
|
||||||
${types.diskoLib.create (eval cfg).config.disko.devices}
|
${diskoLib.create (eval cfg).config.disko.devices}
|
||||||
'';
|
'';
|
||||||
createScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-create" ''
|
createScriptNoDeps = cfg: pkgs: (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-create" ''
|
||||||
${types.diskoLib.create (eval cfg).config.disko.devices}
|
${diskoLib.create (eval cfg).config.disko.devices}
|
||||||
'';
|
'';
|
||||||
mount = cfg: types.diskoLib.mount (eval cfg).config.disko.devices;
|
mount = cfg: diskoLib.mount (eval cfg).config.disko.devices;
|
||||||
mountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
mountScript = cfg: pkgs: (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
|
export PATH=${lib.makeBinPath (diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
|
||||||
${types.diskoLib.mount (eval cfg).config.disko.devices}
|
${diskoLib.mount (eval cfg).config.disko.devices}
|
||||||
'';
|
'';
|
||||||
mountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" ''
|
mountScriptNoDeps = cfg: pkgs: (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" ''
|
||||||
${types.diskoLib.mount (eval cfg).config.disko.devices}
|
${diskoLib.mount (eval cfg).config.disko.devices}
|
||||||
'';
|
'';
|
||||||
zapCreateMount = cfg: types.diskoLib.zapCreateMount (eval cfg).config.disko.devices;
|
zapCreateMount = cfg: diskoLib.zapCreateMount (eval cfg).config.disko.devices;
|
||||||
zapCreateMountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-zap-create-mount" ''
|
zapCreateMountScript = cfg: pkgs: (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-zap-create-mount" ''
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
|
export PATH=${lib.makeBinPath (diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
|
||||||
${types.diskoLib.zapCreateMount (eval cfg).config.disko.devices}
|
${diskoLib.zapCreateMount (eval cfg).config.disko.devices}
|
||||||
'';
|
'';
|
||||||
zapCreateMountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-zap-create-mount" ''
|
zapCreateMountScriptNoDeps = cfg: pkgs: (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-zap-create-mount" ''
|
||||||
${types.diskoLib.zapCreateMount (eval cfg).config.disko.devices}
|
${diskoLib.zapCreateMount (eval cfg).config.disko.devices}
|
||||||
'';
|
'';
|
||||||
config = cfg: { imports = types.diskoLib.config (eval cfg).config.disko.devices; };
|
config = cfg: { imports = diskoLib.config (eval cfg).config.disko.devices; };
|
||||||
packages = cfg: types.diskoLib.packages (eval cfg).config.disko.devices;
|
packages = cfg: diskoLib.packages (eval cfg).config.disko.devices;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
doc.nix
4
doc.nix
|
|
@ -1,7 +1,7 @@
|
||||||
{ lib, nixosOptionsDoc, runCommand, fetchurl, pandoc }:
|
{ lib, nixosOptionsDoc, runCommand, fetchurl, pandoc }:
|
||||||
|
|
||||||
let
|
let
|
||||||
types = import ./types {
|
diskoLib = import ./lib {
|
||||||
inherit lib;
|
inherit lib;
|
||||||
rootMountPoint = "/mnt";
|
rootMountPoint = "/mnt";
|
||||||
};
|
};
|
||||||
|
|
@ -10,7 +10,7 @@ let
|
||||||
{
|
{
|
||||||
options.disko = {
|
options.disko = {
|
||||||
devices = lib.mkOption {
|
devices = lib.mkOption {
|
||||||
type = types.devices;
|
type = diskoLib.devices;
|
||||||
default = { };
|
default = { };
|
||||||
description = "The devices to set up";
|
description = "The devices to set up";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
({ config, options, diskoLib, lib, subTypes, optionTypes, rootMountPoint, ... }:
|
{ config, options, diskoLib, lib, rootMountPoint, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
|
|
@ -17,12 +17,12 @@
|
||||||
description = "A list of options to pass to mount.";
|
description = "A list of options to pass to mount.";
|
||||||
};
|
};
|
||||||
subvolumes = lib.mkOption {
|
subvolumes = lib.mkOption {
|
||||||
type = lib.types.attrsOf subTypes.btrfs_subvol;
|
type = lib.types.attrsOf diskoLib.types.btrfs_subvol;
|
||||||
default = { };
|
default = { };
|
||||||
description = "Subvolumes to define for BTRFS.";
|
description = "Subvolumes to define for BTRFS.";
|
||||||
};
|
};
|
||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = "A path to mount the BTRFS filesystem to.";
|
description = "A path to mount the BTRFS filesystem to.";
|
||||||
};
|
};
|
||||||
|
|
@ -83,4 +83,4 @@
|
||||||
description = "Packages";
|
description = "Packages";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, diskoLib, lib, optionTypes, rootMountPoint, ... }:
|
{ config, options, diskoLib, lib, rootMountPoint, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
description = "Options to pass to mount";
|
description = "Options to pass to mount";
|
||||||
};
|
};
|
||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Location to mount the subvolume to.";
|
description = "Location to mount the subvolume to.";
|
||||||
};
|
};
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
with lib;
|
with lib;
|
||||||
with builtins;
|
with builtins;
|
||||||
|
|
||||||
rec {
|
let
|
||||||
|
|
||||||
diskoLib = {
|
diskoLib = {
|
||||||
# like lib.types.oneOf but instead of a list takes an attrset
|
# like lib.types.oneOf but instead of a list takes an attrset
|
||||||
|
|
@ -17,14 +17,14 @@ rec {
|
||||||
|
|
||||||
# option for valid contents of partitions (basically like devices, but without tables)
|
# option for valid contents of partitions (basically like devices, but without tables)
|
||||||
partitionType = lib.mkOption {
|
partitionType = lib.mkOption {
|
||||||
type = lib.types.nullOr (diskoLib.subType { inherit (subTypes) btrfs filesystem zfs mdraid luks lvm_pv swap; });
|
type = lib.types.nullOr (diskoLib.subType { inherit (diskoLib.types) btrfs filesystem zfs mdraid luks lvm_pv swap; });
|
||||||
default = null;
|
default = null;
|
||||||
description = "The type of partition";
|
description = "The type of partition";
|
||||||
};
|
};
|
||||||
|
|
||||||
# option for valid contents of devices
|
# option for valid contents of devices
|
||||||
deviceType = lib.mkOption {
|
deviceType = lib.mkOption {
|
||||||
type = lib.types.nullOr (diskoLib.subType { inherit (subTypes) table btrfs filesystem zfs mdraid luks lvm_pv swap; });
|
type = lib.types.nullOr (diskoLib.subType { inherit (diskoLib.types) table btrfs filesystem zfs mdraid luks lvm_pv swap; });
|
||||||
default = null;
|
default = null;
|
||||||
description = "The type of device";
|
description = "The type of device";
|
||||||
};
|
};
|
||||||
|
|
@ -160,7 +160,7 @@ rec {
|
||||||
postMountHook = diskoLib.mkHook "shell commands to run after mount";
|
postMountHook = diskoLib.mkHook "shell commands to run after mount";
|
||||||
};
|
};
|
||||||
config._module.args = {
|
config._module.args = {
|
||||||
inherit diskoLib optionTypes subTypes rootMountPoint;
|
inherit diskoLib rootMountPoint;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
@ -274,87 +274,88 @@ rec {
|
||||||
packages :: lib.types.devices -> pkgs -> [ derivation ]
|
packages :: lib.types.devices -> pkgs -> [ derivation ]
|
||||||
*/
|
*/
|
||||||
packages = devices: pkgs: unique (flatten (map (dev: dev._pkgs pkgs) (flatten (map attrValues (attrValues devices)))));
|
packages = devices: pkgs: unique (flatten (map (dev: dev._pkgs pkgs) (flatten (map attrValues (attrValues devices)))));
|
||||||
};
|
|
||||||
|
|
||||||
optionTypes = rec {
|
optionTypes = rec {
|
||||||
filename = lib.mkOptionType {
|
filename = lib.mkOptionType {
|
||||||
name = "filename";
|
name = "filename";
|
||||||
check = isString;
|
check = isString;
|
||||||
merge = mergeOneOption;
|
merge = mergeOneOption;
|
||||||
description = "A filename";
|
description = "A filename";
|
||||||
};
|
};
|
||||||
|
|
||||||
absolute-pathname = lib.mkOptionType {
|
absolute-pathname = lib.mkOptionType {
|
||||||
name = "absolute pathname";
|
name = "absolute pathname";
|
||||||
check = x: isString x && substring 0 1 x == "/" && pathname.check x;
|
check = x: isString x && substring 0 1 x == "/" && pathname.check x;
|
||||||
merge = mergeOneOption;
|
merge = mergeOneOption;
|
||||||
description = "An absolute path";
|
description = "An absolute path";
|
||||||
};
|
};
|
||||||
|
|
||||||
pathname = lib.mkOptionType {
|
pathname = lib.mkOptionType {
|
||||||
name = "pathname";
|
name = "pathname";
|
||||||
check = x:
|
check = x:
|
||||||
let
|
let
|
||||||
# The filter is used to normalize paths, i.e. to remove duplicated and
|
# The filter is used to normalize paths, i.e. to remove duplicated and
|
||||||
# trailing slashes. It also removes leading slashes, thus we have to
|
# trailing slashes. It also removes leading slashes, thus we have to
|
||||||
# check for "/" explicitly below.
|
# check for "/" explicitly below.
|
||||||
xs = filter (s: stringLength s > 0) (splitString "/" x);
|
xs = filter (s: stringLength s > 0) (splitString "/" x);
|
||||||
in
|
in
|
||||||
isString x && (x == "/" || (length xs > 0 && all filename.check xs));
|
isString x && (x == "/" || (length xs > 0 && all filename.check xs));
|
||||||
merge = mergeOneOption;
|
merge = mergeOneOption;
|
||||||
description = "A path name";
|
description = "A path name";
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/* topLevel type of the disko config, takes attrsets of disks, mdadms, zpools, nodevs, and lvm vgs.
|
|
||||||
*/
|
|
||||||
devices = lib.types.submodule {
|
|
||||||
options = {
|
|
||||||
disk = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf subTypes.disk;
|
|
||||||
default = { };
|
|
||||||
description = "Block device";
|
|
||||||
};
|
|
||||||
mdadm = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf subTypes.mdadm;
|
|
||||||
default = { };
|
|
||||||
description = "mdadm device";
|
|
||||||
};
|
|
||||||
zpool = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf subTypes.zpool;
|
|
||||||
default = { };
|
|
||||||
description = "ZFS pool device";
|
|
||||||
};
|
|
||||||
lvm_vg = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf subTypes.lvm_vg;
|
|
||||||
default = { };
|
|
||||||
description = "LVM VG device";
|
|
||||||
};
|
|
||||||
nodev = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf subTypes.nodev;
|
|
||||||
default = { };
|
|
||||||
description = "A non-block device";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
subTypes = lib.mapAttrs (_: diskoLib.mkSubType) {
|
/* topLevel type of the disko config, takes attrsets of disks, mdadms, zpools, nodevs, and lvm vgs.
|
||||||
nodev = ./nodev.nix;
|
*/
|
||||||
btrfs = ./btrfs.nix;
|
devices = lib.types.submodule {
|
||||||
btrfs_subvol = ./btrfs_subvol.nix;
|
options = {
|
||||||
filesystem = ./filesystem.nix;
|
disk = lib.mkOption {
|
||||||
table = ./table.nix;
|
type = lib.types.attrsOf diskoLib.types.disk;
|
||||||
swap = ./swap.nix;
|
default = { };
|
||||||
lvm_pv = ./lvm_pv.nix;
|
description = "Block device";
|
||||||
lvm_vg = ./lvm_vg.nix;
|
};
|
||||||
zfs = ./zfs.nix;
|
mdadm = lib.mkOption {
|
||||||
zpool = ./zpool.nix;
|
type = lib.types.attrsOf diskoLib.types.mdadm;
|
||||||
zfs_dataset = ./zfs_dataset.nix;
|
default = { };
|
||||||
zfs_fs = ./zfs_fs.nix;
|
description = "mdadm device";
|
||||||
zfs_volume = ./zfs_volume.nix;
|
};
|
||||||
mdadm = ./mdadm.nix;
|
zpool = lib.mkOption {
|
||||||
mdraid = ./mdraid.nix;
|
type = lib.types.attrsOf diskoLib.types.zpool;
|
||||||
luks = ./luks.nix;
|
default = { };
|
||||||
disk = ./disk.nix;
|
description = "ZFS pool device";
|
||||||
|
};
|
||||||
|
lvm_vg = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf diskoLib.types.lvm_vg;
|
||||||
|
default = { };
|
||||||
|
description = "LVM VG device";
|
||||||
|
};
|
||||||
|
nodev = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf diskoLib.types.nodev;
|
||||||
|
default = { };
|
||||||
|
description = "A non-block device";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
types = lib.mapAttrs (_: diskoLib.mkSubType) {
|
||||||
|
nodev = ./nodev.nix;
|
||||||
|
btrfs = ./btrfs.nix;
|
||||||
|
btrfs_subvol = ./btrfs_subvol.nix;
|
||||||
|
filesystem = ./filesystem.nix;
|
||||||
|
table = ./table.nix;
|
||||||
|
swap = ./swap.nix;
|
||||||
|
lvm_pv = ./lvm_pv.nix;
|
||||||
|
lvm_vg = ./lvm_vg.nix;
|
||||||
|
zfs = ./zfs.nix;
|
||||||
|
zpool = ./zpool.nix;
|
||||||
|
zfs_dataset = ./zfs_dataset.nix;
|
||||||
|
zfs_fs = ./zfs_fs.nix;
|
||||||
|
zfs_volume = ./zfs_volume.nix;
|
||||||
|
mdadm = ./mdadm.nix;
|
||||||
|
mdraid = ./mdraid.nix;
|
||||||
|
luks = ./luks.nix;
|
||||||
|
disk = ./disk.nix;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
in
|
||||||
|
diskoLib
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, optionTypes, ... }:
|
{ config, options, lib, diskoLib, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
description = "Type";
|
description = "Type";
|
||||||
};
|
};
|
||||||
device = lib.mkOption {
|
device = lib.mkOption {
|
||||||
type = optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
|
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
|
||||||
description = "Device path";
|
description = "Device path";
|
||||||
};
|
};
|
||||||
content = diskoLib.deviceType;
|
content = diskoLib.deviceType;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, optionTypes, rootMountPoint, ... }:
|
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
description = "Options to pass to mount";
|
description = "Options to pass to mount";
|
||||||
};
|
};
|
||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Path to mount the filesystem to";
|
description = "Path to mount the filesystem to";
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, optionTypes, ... }:
|
{ config, options, lib, diskoLib, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
description = "Name of the LUKS";
|
description = "Name of the LUKS";
|
||||||
};
|
};
|
||||||
keyFile = lib.mkOption {
|
keyFile = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Path to the key for encryption";
|
description = "Path to the key for encryption";
|
||||||
example = "/tmp/disk.key";
|
example = "/tmp/disk.key";
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, subTypes, ... }:
|
{ config, options, lib, diskoLib, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ lib, config, options, diskoLib, optionTypes, rootMountPoint, ... }:
|
{ lib, config, options, diskoLib, rootMountPoint, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
description = "Device to use";
|
description = "Device to use";
|
||||||
};
|
};
|
||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = config._module.args.name;
|
default = config._module.args.name;
|
||||||
description = "Location to mount the file system at";
|
description = "Location to mount the file system at";
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, subTypes, ... }:
|
{ config, options, lib, diskoLib, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, optionTypes, rootMountPoint, ... }:
|
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Path to mount the dataset to";
|
description = "Path to mount the dataset to";
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, optionTypes, rootMountPoint, ... }:
|
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, options, lib, diskoLib, optionTypes, subTypes, rootMountPoint, ... }:
|
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
description = "Options for the root filesystem";
|
description = "Options for the root filesystem";
|
||||||
};
|
};
|
||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = "The mountpoint of the pool";
|
description = "The mountpoint of the pool";
|
||||||
};
|
};
|
||||||
|
|
@ -49,8 +49,7 @@
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
datasets = lib.mkOption {
|
datasets = lib.mkOption {
|
||||||
type = lib.types.attrsOf (diskoLib.subType { inherit (subTypes) zfs_fs zfs_volume; });
|
type = lib.types.attrsOf (diskoLib.subType { inherit (diskoLib.types) zfs_fs zfs_volume; });
|
||||||
# type = lib.types.attrsOf subTypes.zfs_fs;
|
|
||||||
description = "List of datasets to define";
|
description = "List of datasets to define";
|
||||||
};
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
32
module.nix
32
module.nix
|
|
@ -1,6 +1,6 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
types = import ./types {
|
diskoLib = import ./lib {
|
||||||
inherit lib;
|
inherit lib;
|
||||||
rootMountPoint = config.disko.rootMountPoint;
|
rootMountPoint = config.disko.rootMountPoint;
|
||||||
};
|
};
|
||||||
|
|
@ -10,7 +10,7 @@ in
|
||||||
{
|
{
|
||||||
options.disko = {
|
options.disko = {
|
||||||
devices = lib.mkOption {
|
devices = lib.mkOption {
|
||||||
type = types.devices;
|
type = diskoLib.devices;
|
||||||
default = { };
|
default = { };
|
||||||
description = "The devices to set up";
|
description = "The devices to set up";
|
||||||
};
|
};
|
||||||
|
|
@ -37,29 +37,29 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = lib.mkIf (cfg.devices.disk != { }) {
|
config = lib.mkIf (cfg.devices.disk != { }) {
|
||||||
system.build.formatScript = (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" ''
|
system.build.formatScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" ''
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH
|
export PATH=${lib.makeBinPath (diskoLib.packages cfg.devices pkgs)}:$PATH
|
||||||
${types.diskoLib.create cfg.devices}
|
${diskoLib.create cfg.devices}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
system.build.mountScript = (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
system.build.mountScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH
|
export PATH=${lib.makeBinPath (diskoLib.packages cfg.devices pkgs)}:$PATH
|
||||||
${types.diskoLib.mount cfg.devices}
|
${diskoLib.mount cfg.devices}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
system.build.disko = (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko" ''
|
system.build.disko = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko" ''
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH
|
export PATH=${lib.makeBinPath (diskoLib.packages cfg.devices pkgs)}:$PATH
|
||||||
${types.diskoLib.zapCreateMount cfg.devices}
|
${diskoLib.zapCreateMount cfg.devices}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# This is useful to skip copying executables uploading a script to an in-memory installer
|
# This is useful to skip copying executables uploading a script to an in-memory installer
|
||||||
system.build.diskoNoDeps = (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko" ''
|
system.build.diskoNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko" ''
|
||||||
${types.diskoLib.zapCreateMount cfg.devices}
|
${diskoLib.zapCreateMount cfg.devices}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Remember to add config keys here if they are added to types
|
# 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)));
|
fileSystems = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "fileSystems" (diskoLib.config cfg.devices)));
|
||||||
boot = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "boot" (types.diskoLib.config cfg.devices)));
|
boot = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "boot" (diskoLib.config cfg.devices)));
|
||||||
swapDevices = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "swapDevices" (types.diskoLib.config cfg.devices)));
|
swapDevices = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "swapDevices" (diskoLib.config cfg.devices)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ stdenvNoCC.mkDerivation rec {
|
||||||
];
|
];
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin $out/share/disko
|
mkdir -p $out/bin $out/share/disko
|
||||||
cp -r cli.nix default.nix disk-deactivate types $out/share/disko
|
cp -r cli.nix default.nix disk-deactivate lib $out/share/disko
|
||||||
sed \
|
sed \
|
||||||
-e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \
|
-e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \
|
||||||
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
|
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue