Compare commits
No commits in common. "25b9dc42fb9a94b05899cf618eb5797c05bd5894" and "f44d0a4a73cb624044dfba7abe0e782c95066ab0" have entirely different histories.
25b9dc42fb
...
f44d0a4a73
22 changed files with 179 additions and 425 deletions
|
@ -1,115 +0,0 @@
|
||||||
{ lib, config, ... }:
|
|
||||||
let
|
|
||||||
inherit (lib) types mkOption;
|
|
||||||
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 = [
|
|
||||||
./fileSystems/btrfs.nix
|
|
||||||
./fileSystems/disks.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
options = {
|
|
||||||
valhalla = {
|
|
||||||
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 {
|
|
||||||
type = types.str;
|
|
||||||
description = "The script for preparing the system's mounts.";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
|
||||||
valhalla = {
|
|
||||||
fileSystems = {
|
|
||||||
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 ====$(jtput 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}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,108 +0,0 @@
|
||||||
{ 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;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
5
lib/modules/partition.nix
Normal file
5
lib/modules/partition.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{ ... }: {
|
||||||
|
imports = [
|
||||||
|
./partition/disks.nix
|
||||||
|
];
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ function chooseDisk -a outFile message selectScript
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
select "$header" "$outFile" "$message" "No valid device found!" "$(string collect $disks)" false
|
select "$header" "$outFile" "$message" "No valid disk 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,8 +4,7 @@ let
|
||||||
|
|
||||||
fs = import ./fs.nix;
|
fs = import ./fs.nix;
|
||||||
|
|
||||||
cfg = config.valhalla.fileSystems;
|
diskListVarName = "myDisks";
|
||||||
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" [
|
||||||
|
@ -13,35 +12,39 @@ let
|
||||||
"udevadm trigger"
|
"udevadm trigger"
|
||||||
];
|
];
|
||||||
|
|
||||||
mkDeviceType = types.submodule (
|
mkDiskType = osDisk: types.submodule (
|
||||||
{ config, name, ... }: {
|
{ config, name, ... }: {
|
||||||
options = {
|
options = {
|
||||||
id = mkOption {
|
id = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The internal identifier of the device.";
|
description = "The internal identifier of the disk.";
|
||||||
internal = true;
|
internal = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
wipe = mkOption {
|
wipe = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
description = "A value indicating whether the device should be wiped.";
|
description = "A value indicating whether the disk should be wiped.";
|
||||||
default = !(lib.lists.any (_: _.keepExisting) (builtins.attrValues config.partitions));
|
default = !(lib.lists.any (_: _.keepExisting) (builtins.attrValues config.partitions));
|
||||||
};
|
};
|
||||||
|
|
||||||
name = mkOption {
|
deviceName = 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 = if osDisk then null else name;
|
||||||
};
|
};
|
||||||
|
|
||||||
path = mkOption {
|
devicePath = mkOption {
|
||||||
type = types.nullOr types.str;
|
type =
|
||||||
|
if osDisk then
|
||||||
|
types.nullOr types.str
|
||||||
|
else
|
||||||
|
types.str;
|
||||||
description = "The path to the device.";
|
description = "The path to the device.";
|
||||||
default =
|
default =
|
||||||
if config.name == null then
|
if osDisk && config.deviceName == null then
|
||||||
null
|
null
|
||||||
else
|
else
|
||||||
"/dev/${config.name}";
|
"/dev/${config.deviceName}";
|
||||||
};
|
};
|
||||||
|
|
||||||
deviceScript = mkOption {
|
deviceScript = mkOption {
|
||||||
|
@ -62,28 +65,21 @@ let
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
scripts = {
|
script = mkOption {
|
||||||
init = mkOption {
|
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "A script for loading the device path into the device variable";
|
description = "The script for formatting the disk.";
|
||||||
};
|
|
||||||
|
|
||||||
partition = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "A script for partitioning and formatting the device.";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
deviceVarName = "${deviceListVarName}[${config.id}]";
|
diskVarName = "${diskListVarName}[${config.id}]";
|
||||||
deviceVar = "\${${deviceVarName}}";
|
diskVar = "\${${diskVarName}}";
|
||||||
|
|
||||||
deviceSelector = ''
|
diskSelector = ''
|
||||||
result="$(mktemp)"
|
result="$(mktemp)"
|
||||||
fish ${./choose-device.fish} "$result" "Please select the \"${name}\" device:" ${./select.fish}
|
fish ${./choose-disk.fish} "$result" "Which disk do you wish to install the OS on?" ${./select.fish}
|
||||||
${deviceVarName}="$(cat "$result")"
|
${diskVarName}="$(cat "$result")"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
partitions = lib.lists.sortOn (_: _.index)
|
partitions = lib.lists.sortOn (_: _.index)
|
||||||
|
@ -103,12 +99,13 @@ let
|
||||||
"echo ${script} | ${
|
"echo ${script} | ${
|
||||||
fdiskCommand "${builtins.concatStringsSep " " args} ${
|
fdiskCommand "${builtins.concatStringsSep " " args} ${
|
||||||
if append then "--append" else ""
|
if append then "--append" else ""
|
||||||
} ${deviceVar}"
|
} ${diskVar}"
|
||||||
}";
|
}";
|
||||||
|
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 ${deviceVar} ${toString partition.index}"} || true")
|
(partition: "${fdiskCommand "--delete ${diskVar} ${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)));
|
||||||
|
@ -116,7 +113,7 @@ let
|
||||||
fdiskCommands = lib.strings.concatLines
|
fdiskCommands = lib.strings.concatLines
|
||||||
(lib.optionals config.wipe [
|
(lib.optionals config.wipe [
|
||||||
cleanup
|
cleanup
|
||||||
(fdiskScript "label: gpt" [ ] false)
|
(wipeScript "label: gpt")
|
||||||
] ++ (builtins.concatMap
|
] ++ (builtins.concatMap
|
||||||
(
|
(
|
||||||
partition:
|
partition:
|
||||||
|
@ -132,7 +129,6 @@ 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}";
|
||||||
|
@ -140,18 +136,16 @@ 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
|
||||||
|
@ -161,12 +155,11 @@ let
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
''local diskPath="$(find -L /dev/disk/by-diskseq -samefile ${deviceVar})"''
|
''local diskPath="$(find -L /dev/disk/by-diskseq -samefile ${diskVar})"''
|
||||||
''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));
|
||||||
|
|
||||||
|
@ -175,25 +168,25 @@ let
|
||||||
partition:
|
partition:
|
||||||
lib.optional
|
lib.optional
|
||||||
(partition.keepExisting && !(builtins.isNull partition.type))
|
(partition.keepExisting && !(builtins.isNull partition.type))
|
||||||
''sudo sfdisk --part-type ${deviceVar} ${toString partition.index} ${mkType partition.type}''
|
''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${mkType partition.type}''
|
||||||
)
|
)
|
||||||
partitions);
|
partitions);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
id = "disk-${name}";
|
id = if osDisk then "os" else "disk-${name}";
|
||||||
deviceVariable = deviceVar;
|
deviceVariable = diskVar;
|
||||||
|
|
||||||
scripts = {
|
deviceScript =
|
||||||
init =
|
if osDisk && config.devicePath == null then ''
|
||||||
if config.path == null then ''
|
${diskSelector}
|
||||||
${deviceSelector}
|
|
||||||
'' else ''
|
'' else ''
|
||||||
${deviceVarName}=${config.path}
|
${diskVarName}=${config.devicePath}
|
||||||
if [ ! -b ${deviceVar} ]; then
|
${if osDisk then ''
|
||||||
|
if [ ! -b ${diskVar} ]; then
|
||||||
function fallback() {
|
function fallback() {
|
||||||
echo "Couldn't find the specified disk \"${deviceVar}\"."
|
echo "Couldn't find the specified disk \"${diskVar}\"."
|
||||||
if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then
|
if fish ${./confirm.fish} "Do you want to install the OS on another disk?"; then
|
||||||
${deviceSelector}
|
${diskSelector}
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -201,9 +194,11 @@ let
|
||||||
|
|
||||||
fallback
|
fallback
|
||||||
fi
|
fi
|
||||||
|
'' else
|
||||||
|
""}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
partition = lib.mkDefault ''
|
script = lib.mkDefault ''
|
||||||
function partition() {
|
function partition() {
|
||||||
${if (!config.wipe) then cleanup else ""}
|
${if (!config.wipe) then cleanup else ""}
|
||||||
${probeScript}
|
${probeScript}
|
||||||
|
@ -214,7 +209,6 @@ let
|
||||||
partition
|
partition
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -245,13 +239,13 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
format = mkOption {
|
format = mkOption {
|
||||||
type = types.nullOr (types.enum (builtins.attrValues fs));
|
type = 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
|
||||||
null;
|
throw ("Partition format not specified.");
|
||||||
};
|
};
|
||||||
|
|
||||||
size = mkOption {
|
size = mkOption {
|
||||||
|
@ -297,30 +291,27 @@ in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems = {
|
partition = {
|
||||||
diskSetup = {
|
rootDir = mkOption {
|
||||||
devices = mkOption {
|
type = types.str;
|
||||||
type = types.attrsOf (mkDeviceType);
|
description = "The root of the installation directory to mount disks into.";
|
||||||
description = "The disk devices to format.";
|
default = "/mnt";
|
||||||
|
};
|
||||||
|
|
||||||
|
os = mkOption {
|
||||||
|
type = mkDiskType true;
|
||||||
|
description = "The partition layout of the OS disk.";
|
||||||
|
};
|
||||||
|
|
||||||
|
disks = mkOption {
|
||||||
|
type = types.attrsOf (mkDiskType false);
|
||||||
|
description = "The additional disks to format.";
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
scripts = {
|
script = mkOption {
|
||||||
init = mkOption {
|
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The script for initializing the disk partitioning script.";
|
description = "The script for partitioning the system's disks.";
|
||||||
};
|
|
||||||
|
|
||||||
partition = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "The script for partitioning the disks.";
|
|
||||||
};
|
|
||||||
|
|
||||||
swap = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "The script for enabling swap devices.";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -328,48 +319,68 @@ in
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems = {
|
partition = {
|
||||||
mounts = (lib.attrsets.concatMapAttrs
|
script = lib.mkDefault (
|
||||||
(
|
|
||||||
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 =
|
|
||||||
let
|
let
|
||||||
|
cfg = config.valhalla.partition;
|
||||||
|
inherit (cfg) os 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.devices));
|
disks = ([ os ] ++ (builtins.attrValues cfg.disks));
|
||||||
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
|
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
|
||||||
in
|
|
||||||
{
|
mountScript = lib.strings.concatLines (builtins.concatMap
|
||||||
init = lib.strings.concatLines (builtins.map (_: _.scripts.init) disks);
|
(
|
||||||
partition = lib.strings.concatLines (builtins.map (_: _.scripts.partition) disks);
|
_: [
|
||||||
swap = lib.strings.concatLines (
|
probeScript
|
||||||
(builtins.map
|
(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)));
|
||||||
|
|
||||||
|
swapScript = lib.strings.concatLines (builtins.map
|
||||||
(
|
(
|
||||||
_: ''
|
_: ''
|
||||||
${probeScript}
|
${probeScript}
|
||||||
sudo swapon ${partPath _}
|
sudo swapon ${partPath _}
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
(builtins.filter (_: _.useSwap) partitions))
|
(builtins.filter (_: _.useSwap) partitions));
|
||||||
|
in
|
||||||
|
lib.strings.concatLines ([
|
||||||
|
"#!/bin/bash"
|
||||||
|
"set -o errexit"
|
||||||
|
]
|
||||||
|
++ (builtins.map (_: _.deviceScript) disks)
|
||||||
|
++ 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
|
||||||
|
''
|
||||||
|
] ++ (builtins.map (_: _.script) disks) ++ [
|
||||||
|
mountScript
|
||||||
|
swapScript
|
||||||
|
])
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
ext4 = "ext4";
|
ext4 = "ext4";
|
||||||
btrfs = "btrfs";
|
|
||||||
swap = "swap";
|
swap = "swap";
|
||||||
ntfs = "ntfs";
|
ntfs = "ntfs";
|
||||||
fat32 = "fat32";
|
fat32 = "fat32";
|
|
@ -91,7 +91,6 @@ 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
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
{ lib, ... }:
|
|
||||||
let
|
|
||||||
inherit (lib) mkEnableOption;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
valhalla = {
|
|
||||||
linux.programs.btrfs = {
|
|
||||||
enable = mkEnableOption "btrfs tools";
|
|
||||||
pools = mkEnableOption "btrfs pool support in bootloaders";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -2,10 +2,10 @@
|
||||||
let inherit (lib) mkOption types;
|
let inherit (lib) mkOption types;
|
||||||
in {
|
in {
|
||||||
imports = [
|
imports = [
|
||||||
./fileSystems.nix
|
|
||||||
./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.devices.OS.partitions = {
|
partition.os.partitions = {
|
||||||
# Keep Windows' boot partition
|
# Keep Windows' boot partition
|
||||||
Boot.keepExisting = true;
|
Boot.keepExisting = true;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{ lib, config, ... }:
|
{ lib, config, ... }:
|
||||||
let fs = import ../../../../lib/modules/fileSystems/fs.nix;
|
let fs = import ../../../../lib/modules/partition/fs.nix;
|
||||||
in {
|
in {
|
||||||
imports = [ ../defaults.nix ];
|
imports = [ ../defaults.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems.diskSetup.devices = {
|
partition = {
|
||||||
OS = {
|
os = {
|
||||||
partitions = {
|
partitions = {
|
||||||
Boot = {
|
Boot = {
|
||||||
index = 1;
|
index = 1;
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
{ lib, config, ... }:
|
{ lib, config, ... }:
|
||||||
let fs = import ../../../lib/modules/fileSystems/fs.nix;
|
let fs = import ../../../lib/modules/partition/fs.nix;
|
||||||
in {
|
in {
|
||||||
imports = [ ../../users/manuel/config.nix ];
|
imports = [ ../../users/manuel/config.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems = {
|
partition = {
|
||||||
diskSetup.devices = {
|
os = {
|
||||||
OS = {
|
|
||||||
path = "/dev/sda";
|
|
||||||
|
|
||||||
partitions = {
|
partitions = {
|
||||||
Boot = {
|
Boot = {
|
||||||
index = 1;
|
index = 1;
|
||||||
|
@ -28,16 +25,8 @@ 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,7 +91,6 @@ 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"
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
#!/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,7 +71,6 @@ 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
|
||||||
|
|
|
@ -31,6 +31,7 @@ begin
|
||||||
set -l port
|
set -l port
|
||||||
set -l file (mktemp)
|
set -l file (mktemp)
|
||||||
set -l root (getServiceRoot $argv)
|
set -l root (getServiceRoot $argv)
|
||||||
|
set -l bin /usr/local/bin/forgejo
|
||||||
set -l config "$root/docker-compose.base.yml"
|
set -l config "$root/docker-compose.base.yml"
|
||||||
set -l overrides (getServiceOverrides $argv)
|
set -l overrides (getServiceOverrides $argv)
|
||||||
set -l envKey "$(getServiceKey "$service").environment"
|
set -l envKey "$(getServiceKey "$service").environment"
|
||||||
|
@ -71,6 +72,14 @@ begin
|
||||||
end
|
end
|
||||||
|
|
||||||
rm "$file"
|
rm "$file"
|
||||||
|
|
||||||
|
begin
|
||||||
|
printf "%s\n" \
|
||||||
|
"#!/bin/sh" \
|
||||||
|
"ssh -p $port -o StrictHostKeyChecking=no git@127.0.0.1 \"SSH_ORIGINAL_COMMAND=\\\"$SSH_ORIGINAL_COMMAND\\\" \$0 \$@\""
|
||||||
|
end | sudo tee "$bin" >/dev/null
|
||||||
|
|
||||||
|
chmod +x "$bin"
|
||||||
end
|
end
|
||||||
|
|
||||||
function getServiceServers -V server
|
function getServiceServers -V server
|
||||||
|
|
|
@ -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/fileSystems/confirm.fish"
|
set -l confirm fish "$dir/../../lib/modules/partition/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/fileSystems/select.fish"
|
source "$(status dirname)/../../lib/modules/partition/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/fileSystems/choose-disk.fish" "$file" "$message"
|
fish "$(status dirname)/../../lib/modules/partition/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/fileSystems/confirm.fish" $argv
|
fish "$(status dirname)/../../lib/modules/partition/confirm.fish" $argv
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue