mirror of
https://github.com/nix-community/disko.git
synced 2024-09-17 09:37:17 +03:00
Merge pull request #41 from nix-community/nixpkgs
This commit is contained in:
commit
01eb26ca0c
@ -1,8 +1,6 @@
|
|||||||
{ lib ? import <nixpkgs/lib>
|
{ lib ? import <nixpkgs/lib> }:
|
||||||
, pkgs ? import <nixpkgs> {}
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
types = import ./types.nix { inherit lib pkgs; };
|
types = import ./types.nix { inherit lib; };
|
||||||
eval = cfg: lib.evalModules {
|
eval = cfg: lib.evalModules {
|
||||||
modules = lib.singleton {
|
modules = lib.singleton {
|
||||||
# _file = toString input;
|
# _file = toString input;
|
||||||
|
73
types.nix
73
types.nix
@ -1,4 +1,4 @@
|
|||||||
{ lib, pkgs }:
|
{ lib }:
|
||||||
with lib;
|
with lib;
|
||||||
with builtins;
|
with builtins;
|
||||||
|
|
||||||
@ -66,6 +66,21 @@ rec {
|
|||||||
abort "${dev} seems not to be a supported disk format";
|
abort "${dev} seems not to be a supported disk format";
|
||||||
in schemas.${detectSchema};
|
in schemas.${detectSchema};
|
||||||
|
|
||||||
|
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
|
||||||
|
jsonType = let
|
||||||
|
valueType = types.nullOr (types.oneOf [
|
||||||
|
types.bool
|
||||||
|
types.int
|
||||||
|
types.float
|
||||||
|
types.str
|
||||||
|
types.path
|
||||||
|
(types.attrsOf valueType)
|
||||||
|
(types.listOf valueType)
|
||||||
|
]) // {
|
||||||
|
description = "JSON value";
|
||||||
|
};
|
||||||
|
in valueType;
|
||||||
|
|
||||||
/* Given a attrset of dependencies and a devices attrset
|
/* Given a attrset of dependencies and a devices attrset
|
||||||
returns a sorted list by dependencies. aborts if a loop is found
|
returns a sorted list by dependencies. aborts if a loop is found
|
||||||
|
|
||||||
@ -231,7 +246,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev: {
|
default = dev: {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -254,7 +269,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev: {
|
default = dev: {
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
||||||
@ -305,7 +320,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev: {
|
default = dev: {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -322,7 +337,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev: {
|
default = dev: {
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
||||||
@ -363,7 +378,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
diskoLib.deepMergeMap (partition: partition._meta dev) config.partitions;
|
diskoLib.deepMergeMap (partition: partition._meta dev) config.partitions;
|
||||||
};
|
};
|
||||||
@ -379,7 +394,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
let
|
let
|
||||||
partMounts = diskoLib.deepMergeMap (partition: partition._mount dev) config.partitions;
|
partMounts = diskoLib.deepMergeMap (partition: partition._mount dev) config.partitions;
|
||||||
@ -441,7 +456,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
||||||
};
|
};
|
||||||
@ -472,7 +487,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount (diskoLib.deviceNumbering dev config.index));
|
optionalAttrs (!isNull config.content) (config.content._mount (diskoLib.deviceNumbering dev config.index));
|
||||||
};
|
};
|
||||||
@ -497,7 +512,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev: {
|
default = dev: {
|
||||||
dependencies.lvm_vg.${config.vg} = [ dev ];
|
dependencies.lvm_vg.${config.vg} = [ dev ];
|
||||||
};
|
};
|
||||||
@ -514,7 +529,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
{};
|
{};
|
||||||
};
|
};
|
||||||
@ -543,7 +558,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default =
|
default =
|
||||||
diskoLib.deepMergeMap (lv: lv._meta [ "lvm_vg" config.name ]) (attrValues config.lvs);
|
diskoLib.deepMergeMap (lv: lv._meta [ "lvm_vg" config.name ]) (attrValues config.lvs);
|
||||||
};
|
};
|
||||||
@ -559,7 +574,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default = let
|
default = let
|
||||||
lvMounts = diskoLib.deepMergeMap (lv: lv._mount config.name) (attrValues config.lvs);
|
lvMounts = diskoLib.deepMergeMap (lv: lv._mount config.name) (attrValues config.lvs);
|
||||||
in {
|
in {
|
||||||
@ -605,7 +620,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
||||||
};
|
};
|
||||||
@ -626,7 +641,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = vg:
|
default = vg:
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount "/dev/${vg}/${config.name}");
|
optionalAttrs (!isNull config.content) (config.content._mount "/dev/${vg}/${config.name}");
|
||||||
};
|
};
|
||||||
@ -651,7 +666,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev: {
|
default = dev: {
|
||||||
dependencies.zpool.${config.pool} = [ dev ];
|
dependencies.zpool.${config.pool} = [ dev ];
|
||||||
};
|
};
|
||||||
@ -667,7 +682,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
{};
|
{};
|
||||||
};
|
};
|
||||||
@ -715,7 +730,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default =
|
default =
|
||||||
diskoLib.deepMergeMap (dataset: dataset._meta [ "zpool" config.name ]) (attrValues config.datasets);
|
diskoLib.deepMergeMap (dataset: dataset._meta [ "zpool" config.name ]) (attrValues config.datasets);
|
||||||
};
|
};
|
||||||
@ -735,7 +750,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default = let
|
default = let
|
||||||
datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount config.name) (attrValues config.datasets);
|
datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount config.name) (attrValues config.datasets);
|
||||||
in {
|
in {
|
||||||
@ -812,7 +827,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
||||||
};
|
};
|
||||||
@ -833,7 +848,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = zpool:
|
default = zpool:
|
||||||
optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount "/dev/zvol/${zpool}/${config.name}") //
|
optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount "/dev/zvol/${zpool}/${config.name}") //
|
||||||
optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") { fs.${config.mountpoint} = ''
|
optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") { fs.${config.mountpoint} = ''
|
||||||
@ -881,7 +896,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default =
|
default =
|
||||||
optionalAttrs (!isNull config.content) (config.content._meta [ "mdadm" config.name ]);
|
optionalAttrs (!isNull config.content) (config.content._meta [ "mdadm" config.name ]);
|
||||||
};
|
};
|
||||||
@ -901,7 +916,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default =
|
default =
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount "/dev/md/${config.name}");
|
optionalAttrs (!isNull config.content) (config.content._mount "/dev/md/${config.name}");
|
||||||
# TODO we probably need to assemble the mdadm somehow
|
# TODO we probably need to assemble the mdadm somehow
|
||||||
@ -928,7 +943,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev: {
|
default = dev: {
|
||||||
dependencies.mdadm.${config.name} = [ dev ];
|
dependencies.mdadm.${config.name} = [ dev ];
|
||||||
};
|
};
|
||||||
@ -945,7 +960,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
{};
|
{};
|
||||||
};
|
};
|
||||||
@ -978,7 +993,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
optionalAttrs (!isNull config.content) (config.content._meta dev);
|
||||||
};
|
};
|
||||||
@ -995,7 +1010,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.functionTo (pkgs.formats.json {}).type;
|
type = types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev:
|
||||||
let
|
let
|
||||||
contentMount = config.content._mount "/dev/mapper/${config.name}";
|
contentMount = config.content._mount "/dev/mapper/${config.name}";
|
||||||
@ -1037,7 +1052,7 @@ rec {
|
|||||||
_meta = mkOption {
|
_meta = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default =
|
default =
|
||||||
optionalAttrs (!isNull config.content) (config.content._meta [ "disk" config.device ]);
|
optionalAttrs (!isNull config.content) (config.content._meta [ "disk" config.device ]);
|
||||||
};
|
};
|
||||||
@ -1050,7 +1065,7 @@ rec {
|
|||||||
_mount = mkOption {
|
_mount = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = (pkgs.formats.json {}).type;
|
type = diskoLib.jsonType;
|
||||||
default =
|
default =
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount config.device);
|
optionalAttrs (!isNull config.content) (config.content._mount config.device);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user