Compare commits
14 commits
25b9dc42fb
...
d0dbae683d
Author | SHA1 | Date | |
---|---|---|---|
d0dbae683d | |||
4dfeb4f26a | |||
cd83727d54 | |||
9cfb27902a | |||
120c766c4c | |||
1a60425386 | |||
10aa988418 | |||
f6fbf7df3d | |||
5cdd1edd5b | |||
6f44a55a35 | |||
f70a1580df | |||
f9af3388a7 | |||
25ba2fbe8a | |||
b62f3e13c7 |
21 changed files with 386 additions and 170 deletions
|
@ -1,14 +1,59 @@
|
||||||
{ lib, config, ... }:
|
{ lib, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) types mkOption;
|
inherit (lib) types mkOption;
|
||||||
in {
|
cfg = config.valhalla.fileSystems;
|
||||||
|
|
||||||
|
mountType = types.submodule (
|
||||||
|
{ config, name, ... }: {
|
||||||
|
options = {
|
||||||
|
device = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = "The device to mount.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
mountPoint = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "The path to mount the device to.";
|
||||||
|
default = name;
|
||||||
|
};
|
||||||
|
|
||||||
|
fsType = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = "The file system type of the mount.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
options = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description = "The options of the mount.";
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./partition/disks.nix
|
./fileSystems/btrfs.nix
|
||||||
|
./fileSystems/disks.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems = {
|
fileSystems = {
|
||||||
|
rootDir = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "The root of the installation directory to mount disks into.";
|
||||||
|
default = "/mnt";
|
||||||
|
};
|
||||||
|
|
||||||
|
mounts = mkOption {
|
||||||
|
type = types.attrsOf mountType;
|
||||||
|
description = "The devices to mount.";
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
|
||||||
script = mkOption {
|
script = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The script for preparing the system's mounts.";
|
description = "The script for preparing the system's mounts.";
|
||||||
|
@ -20,7 +65,50 @@ in {
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems = {
|
fileSystems = {
|
||||||
script = config.valhalla.fileSystems.diskSetup.script;
|
script =
|
||||||
|
let
|
||||||
|
inherit (lib.strings) normalizePath removeSuffix;
|
||||||
|
devices = (builtins.attrValues cfg.diskSetup.devices);
|
||||||
|
mountScript = lib.strings.concatLines (
|
||||||
|
(builtins.concatMap
|
||||||
|
(
|
||||||
|
_: [
|
||||||
|
"partprobe 2> /dev/null || true"
|
||||||
|
"udevadm trigger"
|
||||||
|
(builtins.concatStringsSep " " (
|
||||||
|
[ "sudo" "mount" "--mkdir" ] ++
|
||||||
|
(lib.optionals (_.fsType == "ntfs") [ "-t" "ntfs3" ]) ++
|
||||||
|
[
|
||||||
|
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.options))
|
||||||
|
(_.device)
|
||||||
|
(removeSuffix "/" (normalizePath "/${cfg.rootDir}/${_.mountPoint}"))
|
||||||
|
]
|
||||||
|
))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
(builtins.attrValues cfg.mounts))
|
||||||
|
);
|
||||||
|
in
|
||||||
|
''
|
||||||
|
#!/bin/bash
|
||||||
|
set -o errexit
|
||||||
|
${cfg.diskSetup.scripts.init}
|
||||||
|
${lib.strings.concatLines (lib.optionals ((builtins.length devices) > 0) [
|
||||||
|
''echo "$(tput setaf 3)=== WARNING ====$(tput sgr0)"''
|
||||||
|
(''echo "Continuing this script will alter the partitions of ''
|
||||||
|
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init devices)))
|
||||||
|
+ (if (builtins.length devices) > 1 then " and " else "") + (lib.lists.last devices).deviceVariable + ''"'')
|
||||||
|
''
|
||||||
|
if ! fish ${./fileSystems/confirm.fish} "Are you sure you want to continue?" "n"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
''
|
||||||
|
])}
|
||||||
|
${cfg.diskSetup.scripts.partition}
|
||||||
|
${cfg.btrfs.script}
|
||||||
|
${mountScript}
|
||||||
|
${cfg.diskSetup.scripts.swap}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
108
lib/modules/fileSystems/btrfs.nix
Normal file
108
lib/modules/fileSystems/btrfs.nix
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
{ lib, config, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) types mkOption;
|
||||||
|
cfg = config.valhalla.fileSystems.btrfs;
|
||||||
|
|
||||||
|
profileType = types.enum [
|
||||||
|
"raid0"
|
||||||
|
"raid1"
|
||||||
|
"raid1c3"
|
||||||
|
"raid1c4"
|
||||||
|
"raid5"
|
||||||
|
"raid6"
|
||||||
|
"raid10"
|
||||||
|
"dup"
|
||||||
|
"single"
|
||||||
|
];
|
||||||
|
|
||||||
|
volumeType = types.submodule (
|
||||||
|
{ config, name, ... }: {
|
||||||
|
options = {
|
||||||
|
mountPoint = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = "The path to mount the volume to.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
devices = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description = "The devices of the btrfs volume.";
|
||||||
|
};
|
||||||
|
|
||||||
|
label = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = "The label of the volume.";
|
||||||
|
default = name;
|
||||||
|
};
|
||||||
|
|
||||||
|
dataProfile = mkOption {
|
||||||
|
type = types.nullOr profileType;
|
||||||
|
description = "The data profile.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
metadataProfile = mkOption {
|
||||||
|
type = types.nullOr profileType;
|
||||||
|
description = "The metadata profile.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
valhalla = {
|
||||||
|
fileSystems.btrfs = {
|
||||||
|
volumes = mkOption {
|
||||||
|
type = types.attrsOf volumeType;
|
||||||
|
description = "The btrfs volumes of the system.";
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
script = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "The script for creating the btrfs volumes.";
|
||||||
|
default = lib.strings.concatLines (
|
||||||
|
builtins.map
|
||||||
|
(
|
||||||
|
_: builtins.concatStringsSep " " (
|
||||||
|
[ "mkfs.btrfs" ] ++
|
||||||
|
(lib.optionals (_.metadataProfile != null) [ "--metadata" "${_.metadataProfile}" ]) ++
|
||||||
|
(lib.optionals (_.dataProfile != null) [ "--data" "${_.dataProfile}" ]) ++
|
||||||
|
(lib.optionals (_.label != null) [ "--label" "${_.label}" ]) ++
|
||||||
|
_.devices
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(builtins.attrValues cfg.volumes)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
valhalla = {
|
||||||
|
linux.programs.btrfs = lib.optionalAttrs
|
||||||
|
(builtins.any
|
||||||
|
(_: (builtins.length _.devices) > 1)
|
||||||
|
(builtins.attrValues cfg.volumes))
|
||||||
|
{
|
||||||
|
enable = true;
|
||||||
|
pools = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fileSystems.mounts = lib.attrsets.concatMapAttrs
|
||||||
|
(
|
||||||
|
name: volume:
|
||||||
|
if (volume.mountPoint != null) then {
|
||||||
|
${volume.mountPoint} = {
|
||||||
|
device = builtins.elemAt volume.devices 0;
|
||||||
|
fsType = "btrfs";
|
||||||
|
};
|
||||||
|
} else { }
|
||||||
|
)
|
||||||
|
cfg.volumes;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ function chooseDisk -a outFile message selectScript
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
select "$header" "$outFile" "$message" "No valid disk found!" "$(string collect $disks)" false
|
select "$header" "$outFile" "$message" "No valid device found!" "$(string collect $disks)" false
|
||||||
and begin
|
and begin
|
||||||
set -l disk (string split -n " " (cat "$outFile"))
|
set -l disk (string split -n " " (cat "$outFile"))
|
||||||
echo "/dev/$disk[1]" >$outFile
|
echo "/dev/$disk[1]" >$outFile
|
|
@ -4,7 +4,8 @@ let
|
||||||
|
|
||||||
fs = import ./fs.nix;
|
fs = import ./fs.nix;
|
||||||
|
|
||||||
diskListVarName = "myDisks";
|
cfg = config.valhalla.fileSystems;
|
||||||
|
deviceListVarName = "myDevices";
|
||||||
isSwap = partition: builtins.elem partition.type [ fs.swap 19 ];
|
isSwap = partition: builtins.elem partition.type [ fs.swap 19 ];
|
||||||
|
|
||||||
probeScript = builtins.concatStringsSep "\n" [
|
probeScript = builtins.concatStringsSep "\n" [
|
||||||
|
@ -12,35 +13,35 @@ let
|
||||||
"udevadm trigger"
|
"udevadm trigger"
|
||||||
];
|
];
|
||||||
|
|
||||||
mkDiskType = types.submodule (
|
mkDeviceType = types.submodule (
|
||||||
{ config, name, ... }: {
|
{ config, name, ... }: {
|
||||||
options = {
|
options = {
|
||||||
id = mkOption {
|
id = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The internal identifier of the disk.";
|
description = "The internal identifier of the device.";
|
||||||
internal = true;
|
internal = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
wipe = mkOption {
|
wipe = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
description = "A value indicating whether the disk should be wiped.";
|
description = "A value indicating whether the device should be wiped.";
|
||||||
default = !(lib.lists.any (_: _.keepExisting) (builtins.attrValues config.partitions));
|
default = !(lib.lists.any (_: _.keepExisting) (builtins.attrValues config.partitions));
|
||||||
};
|
};
|
||||||
|
|
||||||
deviceName = mkOption {
|
name = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
description = "The name of the device.";
|
description = "The name of the device.";
|
||||||
default = name;
|
default = name;
|
||||||
};
|
};
|
||||||
|
|
||||||
devicePath = mkOption {
|
path = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
description = "The path to the device.";
|
description = "The path to the device.";
|
||||||
default =
|
default =
|
||||||
if config.deviceName == null then
|
if config.name == null then
|
||||||
null
|
null
|
||||||
else
|
else
|
||||||
"/dev/${config.deviceName}";
|
"/dev/${config.name}";
|
||||||
};
|
};
|
||||||
|
|
||||||
deviceScript = mkOption {
|
deviceScript = mkOption {
|
||||||
|
@ -61,21 +62,28 @@ let
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
script = mkOption {
|
scripts = {
|
||||||
|
init = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The script for formatting the disk.";
|
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.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
diskVarName = "${diskListVarName}[${config.id}]";
|
deviceVarName = "${deviceListVarName}[${config.id}]";
|
||||||
diskVar = "\${${diskVarName}}";
|
deviceVar = "\${${deviceVarName}}";
|
||||||
|
|
||||||
diskSelector = ''
|
deviceSelector = ''
|
||||||
result="$(mktemp)"
|
result="$(mktemp)"
|
||||||
fish ${./choose-disk.fish} "$result" "Please specify the \"${name}\" disk:" ${./select.fish}
|
fish ${./choose-device.fish} "$result" "Please select the \"${name}\" device:" ${./select.fish}
|
||||||
${diskVarName}="$(cat "$result")"
|
${deviceVarName}="$(cat "$result")"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
partitions = lib.lists.sortOn (_: _.index)
|
partitions = lib.lists.sortOn (_: _.index)
|
||||||
|
@ -95,13 +103,12 @@ let
|
||||||
"echo ${script} | ${
|
"echo ${script} | ${
|
||||||
fdiskCommand "${builtins.concatStringsSep " " args} ${
|
fdiskCommand "${builtins.concatStringsSep " " args} ${
|
||||||
if append then "--append" else ""
|
if append then "--append" else ""
|
||||||
} ${diskVar}"
|
} ${deviceVar}"
|
||||||
}";
|
}";
|
||||||
wipeScript = script: fdiskScript script [ ] false;
|
|
||||||
appendScript = index: script: fdiskScript script [ "-N" (builtins.toString index) ] true;
|
appendScript = index: script: fdiskScript script [ "-N" (builtins.toString index) ] true;
|
||||||
|
|
||||||
cleanup = lib.strings.concatLines (builtins.map
|
cleanup = lib.strings.concatLines (builtins.map
|
||||||
(partition: "${fdiskCommand "--delete ${diskVar} ${toString partition.index}"} || true")
|
(partition: "${fdiskCommand "--delete ${deviceVar} ${toString partition.index}"} || true")
|
||||||
(lib.lists.sortOn
|
(lib.lists.sortOn
|
||||||
(partition: partition.index * -1)
|
(partition: partition.index * -1)
|
||||||
(builtins.filter (_: !_.keepExisting) partitions)));
|
(builtins.filter (_: !_.keepExisting) partitions)));
|
||||||
|
@ -109,7 +116,7 @@ let
|
||||||
fdiskCommands = lib.strings.concatLines
|
fdiskCommands = lib.strings.concatLines
|
||||||
(lib.optionals config.wipe [
|
(lib.optionals config.wipe [
|
||||||
cleanup
|
cleanup
|
||||||
(wipeScript "label: gpt")
|
(fdiskScript "label: gpt" [ ] false)
|
||||||
] ++ (builtins.concatMap
|
] ++ (builtins.concatMap
|
||||||
(
|
(
|
||||||
partition:
|
partition:
|
||||||
|
@ -125,6 +132,7 @@ let
|
||||||
|
|
||||||
formatScripts = {
|
formatScripts = {
|
||||||
${fs.ext4} = "mkfs.ext4 -F ${partVar}";
|
${fs.ext4} = "mkfs.ext4 -F ${partVar}";
|
||||||
|
${fs.btrfs} = "mkfs.btrfs ${partVar}";
|
||||||
${fs.swap} = "mkswap ${partVar}";
|
${fs.swap} = "mkswap ${partVar}";
|
||||||
${fs.ntfs} = "mkfs.ntfs -F ${partVar}";
|
${fs.ntfs} = "mkfs.ntfs -F ${partVar}";
|
||||||
${fs.fat32} = "mkfs.fat -F 32 ${partVar}";
|
${fs.fat32} = "mkfs.fat -F 32 ${partVar}";
|
||||||
|
@ -132,16 +140,18 @@ let
|
||||||
|
|
||||||
labelScripts = {
|
labelScripts = {
|
||||||
${fs.ext4} = label: "e2label ${partVar} ${label}";
|
${fs.ext4} = label: "e2label ${partVar} ${label}";
|
||||||
|
${fs.btrfs} = label: "btrfs filesystem label ${partVar} ${label}";
|
||||||
${fs.swap} = label: "swaplabel ${partVar} --label ${label}";
|
${fs.swap} = label: "swaplabel ${partVar} --label ${label}";
|
||||||
${fs.ntfs} = label: "ntfslabel ${partVar} ${label}";
|
${fs.ntfs} = label: "ntfslabel ${partVar} ${label}";
|
||||||
${fs.fat32} = label: "fatlabel ${partVar} ${label}";
|
${fs.fat32} = label: "fatlabel ${partVar} ${label}";
|
||||||
};
|
};
|
||||||
|
|
||||||
create = lib.strings.concatLines [
|
create = lib.strings.concatLines ([
|
||||||
(appendScript index ''${toString index}: "$(${sizeOption})" type=${mkType type}'')
|
(appendScript index ''${toString index}: "$(${sizeOption})" type=${mkType type}'')
|
||||||
probeScript
|
probeScript
|
||||||
|
] ++ (lib.optionals (format != null) [
|
||||||
"sudo ${formatScripts.${format}}"
|
"sudo ${formatScripts.${format}}"
|
||||||
];
|
]));
|
||||||
|
|
||||||
fallback = ''
|
fallback = ''
|
||||||
if ! { ls "${partVar}" 2>&1; } > /dev/null
|
if ! { ls "${partVar}" 2>&1; } > /dev/null
|
||||||
|
@ -151,11 +161,12 @@ let
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
''local diskPath="$(find -L /dev/disk/by-diskseq -samefile ${diskVar})"''
|
''local diskPath="$(find -L /dev/disk/by-diskseq -samefile ${deviceVar})"''
|
||||||
''local ${partVarName}="$diskPath-part${toString index}"''
|
''local ${partVarName}="$diskPath-part${toString index}"''
|
||||||
(if keepExisting then fallback else create)
|
(if keepExisting then fallback else create)
|
||||||
|
] ++ (lib.optionals (format != null) [
|
||||||
"sudo ${labelScripts.${format} label}"
|
"sudo ${labelScripts.${format} label}"
|
||||||
]
|
])
|
||||||
)
|
)
|
||||||
partitions));
|
partitions));
|
||||||
|
|
||||||
|
@ -164,24 +175,25 @@ let
|
||||||
partition:
|
partition:
|
||||||
lib.optional
|
lib.optional
|
||||||
(partition.keepExisting && !(builtins.isNull partition.type))
|
(partition.keepExisting && !(builtins.isNull partition.type))
|
||||||
''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${mkType partition.type}''
|
''sudo sfdisk --part-type ${deviceVar} ${toString partition.index} ${mkType partition.type}''
|
||||||
)
|
)
|
||||||
partitions);
|
partitions);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
id = "disk-${name}";
|
id = "disk-${name}";
|
||||||
deviceVariable = diskVar;
|
deviceVariable = deviceVar;
|
||||||
|
|
||||||
deviceScript =
|
scripts = {
|
||||||
if config.devicePath == null then ''
|
init =
|
||||||
${diskSelector}
|
if config.path == null then ''
|
||||||
|
${deviceSelector}
|
||||||
'' else ''
|
'' else ''
|
||||||
${diskVarName}=${config.devicePath}
|
${deviceVarName}=${config.path}
|
||||||
if [ ! -b ${diskVar} ]; then
|
if [ ! -b ${deviceVar} ]; then
|
||||||
function fallback() {
|
function fallback() {
|
||||||
echo "Couldn't find the specified disk \"${diskVar}\"."
|
echo "Couldn't find the specified disk \"${deviceVar}\"."
|
||||||
if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then
|
if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then
|
||||||
${diskSelector}
|
${deviceSelector}
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -191,7 +203,7 @@ let
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
script = lib.mkDefault ''
|
partition = lib.mkDefault ''
|
||||||
function partition() {
|
function partition() {
|
||||||
${if (!config.wipe) then cleanup else ""}
|
${if (!config.wipe) then cleanup else ""}
|
||||||
${probeScript}
|
${probeScript}
|
||||||
|
@ -202,6 +214,7 @@ let
|
||||||
partition
|
partition
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -232,13 +245,13 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
format = mkOption {
|
format = mkOption {
|
||||||
type = types.enum (builtins.attrValues fs);
|
type = types.nullOr (types.enum (builtins.attrValues fs));
|
||||||
description = "The file system format of the partition.";
|
description = "The file system format of the partition.";
|
||||||
default =
|
default =
|
||||||
if (isSwap config) then
|
if (isSwap config) then
|
||||||
fs.swap
|
fs.swap
|
||||||
else
|
else
|
||||||
throw ("Partition format not specified.");
|
null;
|
||||||
};
|
};
|
||||||
|
|
||||||
size = mkOption {
|
size = mkOption {
|
||||||
|
@ -285,16 +298,10 @@ in
|
||||||
options = {
|
options = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems = {
|
fileSystems = {
|
||||||
rootDir = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "The root of the installation directory to mount disks into.";
|
|
||||||
default = "/mnt";
|
|
||||||
};
|
|
||||||
|
|
||||||
diskSetup = {
|
diskSetup = {
|
||||||
disks = mkOption {
|
devices = mkOption {
|
||||||
type = types.attrsOf (mkDiskType);
|
type = types.attrsOf (mkDeviceType);
|
||||||
description = "The additional disks to format.";
|
description = "The disk devices to format.";
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -309,40 +316,11 @@ in
|
||||||
description = "The script for partitioning the disks.";
|
description = "The script for partitioning the disks.";
|
||||||
};
|
};
|
||||||
|
|
||||||
mount = mkOption {
|
swap = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The script for mounting the partitioned disks.";
|
description = "The script for enabling swap devices.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
script = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "The script for partitioning the system's disks.";
|
|
||||||
default =
|
|
||||||
let
|
|
||||||
cfg = config.valhalla.fileSystems.diskSetup;
|
|
||||||
inherit (cfg) scripts;
|
|
||||||
disks = (builtins.attrValues cfg.disks);
|
|
||||||
in
|
|
||||||
''
|
|
||||||
#!/bin/bash
|
|
||||||
set -o errexit
|
|
||||||
${scripts.init}
|
|
||||||
${lib.strings.concatLines (lib.optionals ((builtins.length disks) > 0) [
|
|
||||||
''echo "$(tput setaf 3)==== WARNING ====$(tput sgr0)"''
|
|
||||||
(''echo "Continuing this script will alter the partitions of ''
|
|
||||||
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init disks)))
|
|
||||||
+ (if (builtins.length disks) > 1 then " and " else "") + (lib.lists.last disks).deviceVariable + ''"'')
|
|
||||||
''
|
|
||||||
if ! fish ${./confirm.fish} "Are you sure you want to continue?" "n"; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
''
|
|
||||||
])}
|
|
||||||
${scripts.partition}
|
|
||||||
${scripts.mount}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -350,38 +328,36 @@ in
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems.diskSetup = {
|
fileSystems = {
|
||||||
|
mounts = (lib.attrsets.concatMapAttrs
|
||||||
|
(
|
||||||
|
name: device:
|
||||||
|
lib.attrsets.concatMapAttrs
|
||||||
|
(
|
||||||
|
name: partition:
|
||||||
|
if partition.mountPoint != null then {
|
||||||
|
${partition.mountPoint} = {
|
||||||
|
device = "/dev/disk/by-label/${partition.label}";
|
||||||
|
fsType = partition.format;
|
||||||
|
options = partition.mountOptions;
|
||||||
|
};
|
||||||
|
} else { }
|
||||||
|
)
|
||||||
|
device.partitions
|
||||||
|
)
|
||||||
|
cfg.diskSetup.devices);
|
||||||
|
|
||||||
|
diskSetup = {
|
||||||
scripts =
|
scripts =
|
||||||
let
|
let
|
||||||
cfg = config.valhalla.fileSystems;
|
|
||||||
inherit (cfg) rootDir;
|
|
||||||
inherit (lib.strings) normalizePath;
|
|
||||||
partPath = part: "/dev/disk/by-label/${part.label}";
|
partPath = part: "/dev/disk/by-label/${part.label}";
|
||||||
disks = ((builtins.attrValues cfg.diskSetup.disks));
|
disks = ((builtins.attrValues cfg.diskSetup.devices));
|
||||||
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 (
|
swap = lib.strings.concatLines (
|
||||||
(builtins.concatMap
|
|
||||||
(
|
|
||||||
_: [
|
|
||||||
probeScript
|
|
||||||
(builtins.concatStringsSep " " (
|
|
||||||
[ "sudo" "mount" "--mkdir" ] ++
|
|
||||||
(lib.optionals (_.format == "ntfs") [ "-t" "ntfs3" ]) ++
|
|
||||||
[
|
|
||||||
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.mountOptions))
|
|
||||||
(partPath _)
|
|
||||||
(normalizePath "/${rootDir}/${_.mountPoint}")
|
|
||||||
]
|
|
||||||
))
|
|
||||||
]
|
|
||||||
)
|
|
||||||
(lib.lists.sortOn
|
|
||||||
(_: normalizePath "/${_.mountPoint}")
|
|
||||||
(builtins.filter (_: _.mountPoint != null) partitions))) ++
|
|
||||||
(builtins.map
|
(builtins.map
|
||||||
(
|
(
|
||||||
_: ''
|
_: ''
|
||||||
|
@ -389,7 +365,9 @@ in
|
||||||
sudo swapon ${partPath _}
|
sudo swapon ${partPath _}
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
(builtins.filter (_: _.useSwap) partitions)));
|
(builtins.filter (_: _.useSwap) partitions))
|
||||||
|
);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
ext4 = "ext4";
|
ext4 = "ext4";
|
||||||
|
btrfs = "btrfs";
|
||||||
swap = "swap";
|
swap = "swap";
|
||||||
ntfs = "ntfs";
|
ntfs = "ntfs";
|
||||||
fat32 = "fat32";
|
fat32 = "fat32";
|
|
@ -1,5 +0,0 @@
|
||||||
{ ... }: {
|
|
||||||
imports = [
|
|
||||||
./partition/disks.nix
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -91,6 +91,7 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
./programs/btrfs.nix
|
||||||
./programs/docker.nix
|
./programs/docker.nix
|
||||||
./programs/git.nix
|
./programs/git.nix
|
||||||
./programs/nextcloud.nix
|
./programs/nextcloud.nix
|
||||||
|
|
14
lib/modules/programs/btrfs.nix
Normal file
14
lib/modules/programs/btrfs.nix
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) mkEnableOption;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
valhalla = {
|
||||||
|
linux.programs.btrfs = {
|
||||||
|
enable = mkEnableOption "btrfs tools";
|
||||||
|
pools = mkEnableOption "btrfs pool support in bootloaders";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -6,7 +6,6 @@ in {
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
./i18n.nix
|
./i18n.nix
|
||||||
./os.nix
|
./os.nix
|
||||||
./partition.nix
|
|
||||||
./programs.nix
|
./programs.nix
|
||||||
./software.nix
|
./software.nix
|
||||||
./users.nix
|
./users.nix
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSystems.diskSetup.disks.OS.partitions = {
|
fileSystems.diskSetup.devices.OS.partitions = {
|
||||||
# Keep Windows' boot partition
|
# Keep Windows' boot partition
|
||||||
Boot.keepExisting = true;
|
Boot.keepExisting = true;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
{ lib, config, ... }:
|
{ lib, config, ... }:
|
||||||
let fs = import ../../../../lib/modules/partition/fs.nix;
|
let fs = import ../../../../lib/modules/fileSystems/fs.nix;
|
||||||
in {
|
in {
|
||||||
imports = [ ../defaults.nix ];
|
imports = [ ../defaults.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems.diskSetup.disks = {
|
fileSystems.diskSetup.devices = {
|
||||||
OS = {
|
OS = {
|
||||||
partitions = {
|
partitions = {
|
||||||
Boot = {
|
Boot = {
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
{ lib, config, ... }:
|
{ lib, config, ... }:
|
||||||
let fs = import ../../../lib/modules/partition/fs.nix;
|
let fs = import ../../../lib/modules/fileSystems/fs.nix;
|
||||||
in {
|
in {
|
||||||
imports = [ ../../users/manuel/config.nix ];
|
imports = [ ../../users/manuel/config.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems.diskSetup.disks = {
|
fileSystems = {
|
||||||
|
diskSetup.devices = {
|
||||||
OS = {
|
OS = {
|
||||||
|
path = "/dev/sda";
|
||||||
|
|
||||||
partitions = {
|
partitions = {
|
||||||
Boot = {
|
Boot = {
|
||||||
index = 1;
|
index = 1;
|
||||||
|
@ -25,8 +28,16 @@ in {
|
||||||
index = 3;
|
index = 3;
|
||||||
label = lib.mkDefault config.valhalla.boot.label;
|
label = lib.mkDefault config.valhalla.boot.label;
|
||||||
type = "linux";
|
type = "linux";
|
||||||
format = fs.ext4;
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
btrfs = {
|
||||||
|
volumes = {
|
||||||
|
OS = {
|
||||||
mountPoint = "/";
|
mountPoint = "/";
|
||||||
|
devices = [ "/dev/sda3" "/dev/sdb" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -91,6 +91,7 @@ begin
|
||||||
|
|
||||||
and echo (getOSConfig hostname) | arch-chroot "$mountDir" tee /etc/hostname >/dev/null
|
and echo (getOSConfig hostname) | arch-chroot "$mountDir" tee /etc/hostname >/dev/null
|
||||||
|
|
||||||
|
and runInOS fish "$tempDir/../Software/btrfs/main.fish"
|
||||||
and arch-chroot "$mountDir" mkinitcpio -P
|
and arch-chroot "$mountDir" mkinitcpio -P
|
||||||
and runInOS fish "$tempDir/../Software/grub/main.fish"
|
and runInOS fish "$tempDir/../Software/grub/main.fish"
|
||||||
|
|
||||||
|
|
19
scripts/Arch/Software/btrfs/main.fish
Executable file
19
scripts/Arch/Software/btrfs/main.fish
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/env fish
|
||||||
|
begin
|
||||||
|
set -l dir (status dirname)
|
||||||
|
source "$dir/../../lib/software.fish"
|
||||||
|
|
||||||
|
function installSW
|
||||||
|
pacinst btrfs-progs
|
||||||
|
end
|
||||||
|
|
||||||
|
function configureSW -V dir
|
||||||
|
source "$dir/../../../lib/settings.fish"
|
||||||
|
|
||||||
|
if isOSEnabled "programs.btrfs.pools"
|
||||||
|
echo "HOOKS+=(btrfs)" | sudo tee /etc/mkinitcpio.conf.d/btrfs.conf >/dev/null
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
runInstaller $argv
|
||||||
|
end
|
|
@ -71,6 +71,7 @@ function deploySoftware -d "Deploys a the specified software action" -a action
|
||||||
end
|
end
|
||||||
|
|
||||||
and source "$dir/../../Common/Software/bash/main.fish" $argv
|
and source "$dir/../../Common/Software/bash/main.fish" $argv
|
||||||
|
and source "$dir/../Software/btrfs/main.fish" $argv
|
||||||
and source "$dir/../../Common/Software/nuke-usb/main.fish" $argv
|
and source "$dir/../../Common/Software/nuke-usb/main.fish" $argv
|
||||||
and source "$dir/../Software/sudo/main.fish" $argv
|
and source "$dir/../Software/sudo/main.fish" $argv
|
||||||
and source "$dir/../Software/aliae/main.fish" $argv
|
and source "$dir/../Software/aliae/main.fish" $argv
|
||||||
|
|
|
@ -7,7 +7,7 @@ function initBackupConfig -V dir -d "Fetches the configuration by prompting the
|
||||||
if [ -z "$VALHALLA_BACKUP_DIR" ]
|
if [ -z "$VALHALLA_BACKUP_DIR" ]
|
||||||
argparse -i "action=" -- $argv
|
argparse -i "action=" -- $argv
|
||||||
set -l index
|
set -l index
|
||||||
set -l confirm fish "$dir/../../lib/modules/partition/confirm.fish"
|
set -l confirm fish "$dir/../../lib/modules/fileSystems/confirm.fish"
|
||||||
|
|
||||||
switch "$_flag_action"
|
switch "$_flag_action"
|
||||||
case backup
|
case backup
|
||||||
|
|
|
@ -4,7 +4,7 @@ function isConfigured -S
|
||||||
end
|
end
|
||||||
|
|
||||||
function selectProfile -S -a result
|
function selectProfile -S -a result
|
||||||
source "$(status dirname)/../../lib/modules/partition/select.fish"
|
source "$(status dirname)/../../lib/modules/fileSystems/select.fish"
|
||||||
set -l file (mktemp)
|
set -l file (mktemp)
|
||||||
set -l header NAME
|
set -l header NAME
|
||||||
set -l profiles
|
set -l profiles
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/env fish
|
#!/bin/env fish
|
||||||
function chooseDisk -a result message
|
function chooseDisk -a result message
|
||||||
set -l file (mktemp)
|
set -l file (mktemp)
|
||||||
fish "$(status dirname)/../../lib/modules/partition/choose-disk.fish" "$file" "$message"
|
fish "$(status dirname)/../../lib/modules/fileSystems/choose-disk.fish" "$file" "$message"
|
||||||
set -g "$result" (cat "$file")
|
set -g "$result" (cat "$file")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/env fish
|
#!/bin/env fish
|
||||||
function confirm -a message default
|
function confirm -a message default
|
||||||
fish "$(status dirname)/../../lib/modules/partition/confirm.fish" $argv
|
fish "$(status dirname)/../../lib/modules/fileSystems/confirm.fish" $argv
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue