Skip to content

Commit

Permalink
nixos/filesystems: add option to enable each FS
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulGrandperrin committed Apr 18, 2024
1 parent 4b31cc7 commit ce8b8ee
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions nixos/modules/tasks/filesystems.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ let
isNonEmpty = s: (builtins.match "[ \t\n]*" s) == null;
nonEmptyStr = addCheckDesc "non-empty" types.str isNonEmpty;

fileSystems' = toposort fsBefore (attrValues config.fileSystems);
enabledFileSystems = lib.filterAttrs (n: v: v.enable) config.fileSystems;
enabledSpecialFileSystems = lib.filterAttrs (n: v: v.enable) config.specialFileSystems;

fileSystems' = toposort fsBefore (attrValues enabledFileSystems);

fileSystems = if fileSystems' ? result
then # use topologically sorted fileSystems everywhere
Expand All @@ -20,7 +23,7 @@ let
# but we fall back to the original order
# anyway so that other modules could check
# their assertions too
(attrValues config.fileSystems);
(attrValues enabledFileSystems);

specialFSTypes = [ "proc" "sysfs" "tmpfs" "ramfs" "devtmpfs" "devpts" ];

Expand All @@ -30,6 +33,15 @@ let
coreFileSystemOpts = { name, config, ... }: {

options = {
enable = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Whether this file system mount should be generated. This
option allows specific file system mounts to be disabled.
'';
};

mountPoint = mkOption {
example = "/mnt/usb";
type = nonEmptyWithoutTrailingSlash;
Expand Down Expand Up @@ -268,7 +280,7 @@ in

# Export for use in other modules
system.build.fileSystems = fileSystems;
system.build.earlyMountScript = makeSpecialMounts (toposort fsBefore (attrValues config.boot.specialFileSystems)).result;
system.build.earlyMountScript = makeSpecialMounts (toposort fsBefore (attrValues enabledSpecialFileSystems)).result;

boot.supportedFilesystems = map (fs: fs.fsType) fileSystems;

Expand Down

0 comments on commit ce8b8ee

Please sign in to comment.