Store device scripts in scripts
option
This commit is contained in:
parent
25ba2fbe8a
commit
f9af3388a7
1 changed files with 56 additions and 46 deletions
|
@ -61,9 +61,16 @@ let
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
script = mkOption {
|
scripts = {
|
||||||
type = types.str;
|
init = mkOption {
|
||||||
description = "The script for formatting the disk.";
|
type = types.str;
|
||||||
|
description = "A script for loading the device path into the device variable";
|
||||||
|
};
|
||||||
|
|
||||||
|
partition = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "A script for partitioning and formatting the device.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -172,35 +179,37 @@ let
|
||||||
id = "disk-${name}";
|
id = "disk-${name}";
|
||||||
deviceVariable = deviceVar;
|
deviceVariable = deviceVar;
|
||||||
|
|
||||||
deviceScript =
|
scripts = {
|
||||||
if config.path == null then ''
|
init =
|
||||||
${deviceSelector}
|
if config.path == null then ''
|
||||||
'' else ''
|
${deviceSelector}
|
||||||
${deviceVarName}=${config.path}
|
'' else ''
|
||||||
if [ ! -b ${deviceVar} ]; then
|
${deviceVarName}=${config.path}
|
||||||
function fallback() {
|
if [ ! -b ${deviceVar} ]; then
|
||||||
echo "Couldn't find the specified disk \"${deviceVar}\"."
|
function fallback() {
|
||||||
if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then
|
echo "Couldn't find the specified disk \"${deviceVar}\"."
|
||||||
${deviceSelector}
|
if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then
|
||||||
else
|
${deviceSelector}
|
||||||
exit 1
|
else
|
||||||
fi
|
exit 1
|
||||||
}
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
fallback
|
fallback
|
||||||
fi
|
fi
|
||||||
|
'';
|
||||||
|
|
||||||
|
partition = lib.mkDefault ''
|
||||||
|
function partition() {
|
||||||
|
${if (!config.wipe) then cleanup else ""}
|
||||||
|
${probeScript}
|
||||||
|
${fdiskCommands}
|
||||||
|
${fixType}
|
||||||
|
}
|
||||||
|
|
||||||
|
partition
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
script = lib.mkDefault ''
|
|
||||||
function partition() {
|
|
||||||
${if (!config.wipe) then cleanup else ""}
|
|
||||||
${probeScript}
|
|
||||||
${fdiskCommands}
|
|
||||||
${fixType}
|
|
||||||
}
|
|
||||||
|
|
||||||
partition
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -332,8 +341,8 @@ in
|
||||||
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
|
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
init = lib.strings.concatLines (builtins.map (_: _.deviceScript) disks);
|
init = lib.strings.concatLines (builtins.map (_: _.scripts.init) disks);
|
||||||
partition = lib.strings.concatLines (builtins.map (_: _.script) disks);
|
partition = lib.strings.concatLines (builtins.map (_: _.scripts.partition) disks);
|
||||||
mount = lib.strings.concatLines (
|
mount = lib.strings.concatLines (
|
||||||
(builtins.concatMap
|
(builtins.concatMap
|
||||||
(
|
(
|
||||||
|
@ -341,26 +350,27 @@ in
|
||||||
probeScript
|
probeScript
|
||||||
(builtins.concatStringsSep " " (
|
(builtins.concatStringsSep " " (
|
||||||
[ "sudo" "mount" "--mkdir" ] ++
|
[ "sudo" "mount" "--mkdir" ] ++
|
||||||
(lib.optionals (_.format == "ntfs") [ "-t" "ntfs3" ]) ++
|
(lib.optionals (_.format == "ntfs") [ "-t" "ntfs3" ]) ++
|
||||||
[
|
[
|
||||||
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.mountOptions))
|
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.mountOptions))
|
||||||
(partPath _)
|
(partPath _)
|
||||||
(normalizePath "/${rootDir}/${_.mountPoint}")
|
(normalizePath "/${rootDir}/${_.mountPoint}")
|
||||||
]
|
]
|
||||||
))
|
))
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(lib.lists.sortOn
|
(lib.lists.sortOn
|
||||||
(_: normalizePath "/${_.mountPoint}")
|
(_: normalizePath "/${_.mountPoint}")
|
||||||
(builtins.filter (_: _.mountPoint != null) partitions))) ++
|
(builtins.filter (_: _.mountPoint != null) partitions))) ++
|
||||||
(builtins.map
|
(builtins.map
|
||||||
(
|
(
|
||||||
_: ''
|
_: ''
|
||||||
${probeScript}
|
${probeScript}
|
||||||
sudo swapon ${partPath _}
|
sudo swapon ${partPath _}
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
(builtins.filter (_: _.useSwap) partitions)));
|
(builtins.filter (_: _.useSwap) partitions))
|
||||||
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue