aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2018-07-31 22:08:44 +0200
committerlassulus <lassulus@lassul.us>2018-07-31 22:09:14 +0200
commit348d4f164ffc506d1cb8e58864e345ce978e3a50 (patch)
tree6eac7f9cc76bee0d8432b7b34edc256e7a1c1ee8
parent9cbf541974bfe67a84f2450f97a8ccad52c6cd89 (diff)
lib.body.*: don't require initial (unused) state
-rw-r--r--example/default.nix6
-rw-r--r--lib/default.nix59
2 files changed, 36 insertions, 29 deletions
diff --git a/example/default.nix b/example/default.nix
index 0fa59c0..aa03d27 100644
--- a/example/default.nix
+++ b/example/default.nix
@@ -3,7 +3,7 @@
with import ../lib;
{
- config = config "/dev/sda" (import ./config.nix);
- create = create "/dev/sda" (import ./config.nix);
- mount = mount "/dev/sda" (import ./config.nix);
+ config = config (import ./config.nix);
+ create = create (import ./config.nix);
+ mount = mount (import ./config.nix);
}
diff --git a/lib/default.nix b/lib/default.nix
index 8b08d01..c6234e0 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -3,11 +3,13 @@ with builtins;
let {
- body.config = q: x: config.${x.type} q x;
- body.create = q: x: create.${x.type} q x;
- body.mount = q: x: mount.${x.type} q x;
+ body.config = config-f {};
+ body.create = create-f {};
+ body.mount = mount-f {};
+ config-f = q: x: config.${x.type} q x;
+
config.filesystem = q: x: {
fileSystems.${x.mountpoint} = {
device = q.device;
@@ -16,48 +18,50 @@ let {
};
config.devices = q: x:
- foldl' mergeAttrs {} (mapAttrsToList (name: body.config { device = "/dev/${name}"; }) x.content);
+ foldl' mergeAttrs {} (mapAttrsToList (name: config-f { device = "/dev/${name}"; }) x.content);
config.luks = q: x: {
boot.initrd.luks.devices.${x.name}.device = q.device;
- } // body.config { device = "/dev/mapper/${x.name}"; } x.content;
+ } // config-f { device = "/dev/mapper/${x.name}"; } x.content;
config.lv = q: x:
- body.config { device = "/dev/${q.vgname}/${q.name}"; } x.content;
+ config-f { device = "/dev/${q.vgname}/${q.name}"; } x.content;
config.lvm = q: x:
- foldl' mergeAttrs {} (mapAttrsToList (name: body.config { inherit name; vgname = x.name; }) x.lvs);
+ foldl' mergeAttrs {} (mapAttrsToList (name: config-f { inherit name; vgname = x.name; }) x.lvs);
config.partition = q: x:
- body.config { device = q.device + toString q.index; } x.content;
+ config-f { device = q.device + toString q.index; } x.content;
config.table = q: x:
- foldl' mergeAttrs {} (imap (index: body.config (q // { inherit index; })) x.partitions);
+ foldl' mergeAttrs {} (imap (index: config-f (q // { inherit index; })) x.partitions);
+
+ create-f = q: x: create.${x.type} q x;
create.filesystem = q: x: ''
mkfs.${x.format} ${q.device}
'';
create.devices = q: x: ''
- ${concatStrings (mapAttrsToList (name: body.create { device = "/dev/${name}"; }) x.content)}
+ ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; }) x.content)}
'';
create.luks = q: x: ''
cryptsetup -q luksFormat ${q.device} ${x.keyfile} ${toString (x.extraArgs or [])}
cryptsetup luksOpen ${q.device} ${x.name} --key-file ${x.keyfile}
- ${body.create { device = "/dev/mapper/${x.name}"; } x.content}
+ ${create-f { device = "/dev/mapper/${x.name}"; } x.content}
'';
create.lv = q: x: ''
lvcreate -L ${x.size} -n ${q.name} ${q.vgname}
- ${body.create { device = "/dev/${q.vgname}/${q.name}"; } x.content}
+ ${create-f { device = "/dev/${q.vgname}/${q.name}"; } x.content}
'';
create.lvm = q: x: ''
pvcreate ${q.device}
vgcreate ${x.name} ${q.device}
- ${concatStrings (mapAttrsToList (name: body.create { inherit name; vgname = x.name; }) x.lvs)}
+ ${concatStrings (mapAttrsToList (name: create-f { inherit name; vgname = x.name; }) x.lvs)}
'';
create.partition = q: x: ''
@@ -65,23 +69,26 @@ let {
${optionalString (x.bootable or false) ''
parted -s ${q.device} set ${toString q.index} boot on
''}
- ${body.create { device = q.device + toString q.index; } x.content}
+ ${create-f { device = q.device + toString q.index; } x.content}
'';
create.table = q: x: ''
parted -s ${q.device} mklabel ${x.format}
- ${concatStrings (imap (index: body.create (q // { inherit index; })) x.partitions)}
+ ${concatStrings (imap (index: create-f (q // { inherit index; })) x.partitions)}
'';
+
+ mount-f = q: x: mount.${x.type} q x;
+
mount.filesystem = q: x: {
- fs.${x.mountpoint} = ''
- mkdir -p ${x.mountpoint}
- mount ${q.device} ${x.mountpoint}
- '';
- };
+ fs.${x.mountpoint} = ''
+ mkdir -p ${x.mountpoint}
+ mount ${q.device} ${x.mountpoint}
+ '';
+ };
mount.devices = q: x: let
- z = foldl' recursiveUpdate {} (mapAttrsToList (name: body.mount { device = "/dev/${name}"; }) x.content);
+ z = foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { device = "/dev/${name}"; }) x.content);
# attrValues returns values sorted by name. This is important, because it
# ensures that "/" is processed before "/foo" etc.
in ''
@@ -92,27 +99,27 @@ let {
mount.luks = q: x: (
recursiveUpdate
- (body.mount { device = "/dev/mapper/${x.name}"; } x.content)
+ (mount-f { device = "/dev/mapper/${x.name}"; } x.content)
{luks.${q.device} = ''
cryptsetup luksOpen ${q.device} ${x.name} --key-file ${x.keyfile}
'';}
);
mount.lv = q: x:
- body.mount { device = "/dev/${q.vgname}/${q.name}"; } x.content;
+ mount-f { device = "/dev/${q.vgname}/${q.name}"; } x.content;
mount.lvm = q: x: (
recursiveUpdate
- (foldl' recursiveUpdate {} (mapAttrsToList (name: body.mount { inherit name; vgname = x.name; }) x.lvs))
+ (foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { inherit name; vgname = x.name; }) x.lvs))
{lvm.${q.device} = ''
vgchange -a y
'';}
);
mount.partition = q: x:
- body.mount { device = q.device + toString q.index; } x.content;
+ mount-f { device = q.device + toString q.index; } x.content;
mount.table = q: x:
- foldl' recursiveUpdate {} (imap (index: body.mount (q // { inherit index; })) x.partitions);
+ foldl' recursiveUpdate {} (imap (index: mount-f (q // { inherit index; })) x.partitions);
}