2019-12-24 08:20:30 +03:00
|
|
|
module Mounting
|
|
|
|
def self.auto_depend_mount_points(mount_points)
|
|
|
|
mount_points.each do |_, target|
|
|
|
|
mount_points.each do |_, higher|
|
|
|
|
next if target == higher
|
|
|
|
# We're using +#mount_point+ on the tasks to use the normalized mount point
|
|
|
|
# names.
|
|
|
|
# If the higher mount point is found at the start of the target mount point.
|
|
|
|
# This will match /dev for /dev/shm, but not the reverse.
|
|
|
|
if target.mount_point.index(higher.mount_point) == 0 then
|
|
|
|
$logger.debug("#{target.mount_point} is under #{higher.mount_point}")
|
|
|
|
target.add_dependency(:Mount, higher.mount_point)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Creates tasks to mount all special mount points.
|
|
|
|
# Dependencies on other mount points is being handled here.
|
|
|
|
def self.create_special_mount_points()
|
|
|
|
# Create all mount points.
|
|
|
|
mount_points = Configuration["nixos"]["boot"]["specialFileSystems"].map do |mount_point, config|
|
2020-01-13 01:10:53 +03:00
|
|
|
args = []
|
|
|
|
args << config["device"] if config["device"]
|
|
|
|
args << mount_point
|
|
|
|
|
2019-12-24 08:20:30 +03:00
|
|
|
task = Tasks::Mount.new(
|
2020-01-13 01:10:53 +03:00
|
|
|
*args,
|
2019-12-24 08:20:30 +03:00
|
|
|
type: config["fsType"],
|
|
|
|
options: config["options"],
|
|
|
|
)
|
|
|
|
|
|
|
|
[mount_point, task]
|
|
|
|
end.to_h
|
|
|
|
auto_depend_mount_points(mount_points)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Creates tasks to mount all mount points required for boot.
|
|
|
|
# Dependencies on other mount points is being handled here.
|
|
|
|
def self.create_boot_mount_points()
|
|
|
|
mount_points = Configuration["bootFileSystems"].map do |mount_point, config|
|
2019-12-28 04:56:12 +03:00
|
|
|
mount_point = File.join(Tasks::SwitchRoot::SYSTEM_MOUNT_POINT, mount_point)
|
2019-12-24 08:20:30 +03:00
|
|
|
|
|
|
|
device =
|
|
|
|
if config["label"]
|
|
|
|
"/dev/disk/by-label/#{config["label"]}"
|
|
|
|
else
|
|
|
|
config["device"]
|
|
|
|
end
|
|
|
|
|
|
|
|
options = config["options"].reject { |str| str.match(/^x-nixos\./) }
|
|
|
|
|
|
|
|
task = Tasks::Mount.new(
|
|
|
|
device,
|
|
|
|
mount_point,
|
|
|
|
type: config["fsType"],
|
|
|
|
options: options,
|
|
|
|
)
|
|
|
|
|
|
|
|
# TODO: Handle failures gracefully
|
|
|
|
# init_fail FFFF00 root_mount_failure "Could not mount root filesystem"
|
|
|
|
|
2020-02-04 05:57:21 +03:00
|
|
|
if config["autoResize"]
|
|
|
|
resize_task = Tasks::AutoResize.new(
|
|
|
|
device,
|
|
|
|
type: config["fsType"],
|
|
|
|
)
|
|
|
|
task.add_dependency(:Task, resize_task)
|
|
|
|
end
|
2019-12-24 08:20:30 +03:00
|
|
|
|
|
|
|
# Makes sure switching root waits until *all* mount points needed for
|
|
|
|
# boot are fulfilled.
|
|
|
|
Targets[:SwitchRoot].add_dependency(:Mount, mount_point)
|
|
|
|
|
|
|
|
[mount_point, task]
|
|
|
|
end.to_h
|
|
|
|
auto_depend_mount_points(mount_points)
|
2020-11-01 23:44:48 +03:00
|
|
|
|
|
|
|
(Configuration["luksDevices"] or []).each do |mapper, info|
|
|
|
|
Tasks::Luks.new(info["device"], mapper)
|
|
|
|
end
|
2019-12-24 08:20:30 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|