improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
/*
2023-06-16 02:14:51 +02:00
# Additions to `fileSystems`
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
2023-06-16 02:14:51 +02:00
Currently, this just adds `preMountCommands` .
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
## Implementation
```nix
#*/# end of MarkDown, beginning of NixOS module:
2023-06-16 02:14:51 +02:00
dirname: inputs: moduleArgs@{ config, pkgs, lib, utils, ... }: let lib = inputs.self.lib.__internal__; in let
inherit (inputs.config.rename) preMountCommands;
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
in {
options = {
fileSystems = lib.mkOption { type = lib.types.attrsOf (lib.types.submodule [ { options = {
2023-06-16 02:14:51 +02:00
${preMountCommands} = lib.mkOption { description = ''
2023-05-02 02:13:24 +02:00
Commands to be run as root every time before mounting this filesystem, but after all its dependents were mounted (TODO: or does this run just once per boot?).
This does not order itself before or after `systemd-fsck@''${utils.escapeSystemdPath device}.service` .
2023-06-16 02:14:51 +02:00
This is not implemented for mounts in the initrd (those that are `neededForBoot` ) yet.
Note that if a symlink exists at a mount point when systemd's fstab-generator runs, it will read/resolve the symlink and use that as the mount point, resulting in mismatching unit names for that mount, effectively disabling its `${preMountCommands}` .
2023-05-02 02:13:24 +02:00
''; type = lib.types.lines; default = ""; };
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
}; } ]);
}; };
config = let
in ({
2023-06-16 02:14:51 +02:00
assertions = lib.mapAttrsToList (name: fs: {
assertion = (fs.${preMountCommands} == "") || (!utils.fsNeededForBoot fs);
message = ''The filesystem "${name}" has `.${preMountCommands}` but is also (possibly implicitly) `.neededForBoot` . This is not currently supported.'';
}) config.fileSystems;
2022-12-27 15:37:27 +01:00
# The implementation is derived from the "mkfs-${device'}" service in nixpkgs.
2023-06-16 02:14:51 +02:00
systemd.services = lib.fun.mapMergeUnique (_: args@{ mountPoint, device, depends, ... }: if (args.${preMountCommands} != "") then let
isDevice = lib.fun.startsWith "/dev/" device;
2022-12-27 15:37:27 +01:00
mountPoint' = utils.escapeSystemdPath mountPoint;
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
device' = utils.escapeSystemdPath device;
2022-12-27 15:37:27 +01:00
in { "pre-mount-${mountPoint'}" = {
description = "Prepare mounting ${device} at ${mountPoint}";
wantedBy = [ "${mountPoint'}.mount" ]; before = [ "${mountPoint'}.mount" ];
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
requires = lib.optional isDevice "${device'}.device"; after = lib.optional isDevice "${device'}.device";
2022-12-27 15:37:27 +01:00
unitConfig.RequiresMountsFor = depends ++ [ (builtins.dirOf device) (builtins.dirOf mountPoint) ];
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
unitConfig.DefaultDependencies = false;
2023-06-16 02:14:51 +02:00
serviceConfig.Type = "oneshot"; script = args.${preMountCommands};
improve installation, add support for:
ZFS, encryption (keys, keystore, LUKS), bootFS, ephemeral root (tmpfs, ZFS, F2FS, ...), testing in qemu, options & debugging, ... and many small things
2022-05-31 03:41:28 +02:00
}; } else { }) config.fileSystems;
});
}