Turn fileSystems into an attribute set

So now you can write

  fileSystems =
    [ { mountPoint = "/";
        device = "/dev/sda1";
      }
    ];

as

  fileSystems."/".device = "/dev/sda1";
This commit is contained in:
Eelco Dolstra 2012-11-02 18:02:12 +01:00
parent 97f087cd44
commit 458f36f5f1
9 changed files with 131 additions and 148 deletions

View File

@ -230,11 +230,7 @@ $ reboot</screen>
{ {
boot.loader.grub.device = "/dev/sda"; boot.loader.grub.device = "/dev/sda";
fileSystems = fileSystems."/".device = "/dev/disk/by-label/nixos";
[ { mountPoint = "/";
device = "/dev/disk/by-label/nixos";
}
];
swapDevices = swapDevices =
[ { device = "/dev/disk/by-label/swap"; } ]; [ { device = "/dev/disk/by-label/swap"; } ];

View File

@ -184,17 +184,13 @@ in
# Note that /dev/root is a symlink to the actual root device # Note that /dev/root is a symlink to the actual root device
# specified on the kernel command line, created in the stage 1 init # specified on the kernel command line, created in the stage 1 init
# script. # script.
fileSystems = fileSystems."/".device = "/dev/root";
[ { mountPoint = "/";
device = "/dev/root"; fileSystems."/nix/store" =
} { fsType = "squashfs";
{ mountPoint = "/nix/store";
fsType = "squashfs";
device = "/nix-store.squashfs"; device = "/nix-store.squashfs";
options = "loop"; options = "loop";
neededForBoot = true; };
}
];
# We need squashfs in the initrd to mount the compressed Nix store, # We need squashfs in the initrd to mount the compressed Nix store,
# and aufs to make the root filesystem appear writable. # and aufs to make the root filesystem appear writable.

View File

@ -239,17 +239,14 @@ if $generate; then
# Add filesystem entries for each partition that you want to see # Add filesystem entries for each partition that you want to see
# mounted at boot time. This should include at least the root # mounted at boot time. This should include at least the root
# filesystem. # filesystem.
fileSystems =
[ # { mountPoint = "/";
# device = "/dev/disk/by-label/nixos";
# }
# { mountPoint = "/data"; # where you want to mount the device # fileSystems."/".device = "/dev/disk/by-label/nixos";
# device = "/dev/sdb"; # the device
# fileSystems."/data" = # where you want to mount the device
# { device = "/dev/sdb"; # the device
# fsType = "ext3"; # the type of the partition # fsType = "ext3"; # the type of the partition
# options = "data=journal"; # options = "data=journal";
# } # };
];
# List swap partitions activated at boot time. # List swap partitions activated at boot time.
swapDevices = swapDevices =

View File

@ -99,9 +99,12 @@ let
options.neededForBoot = mkOption { options.neededForBoot = mkOption {
default = false; default = false;
type = types.bool; type = types.bool;
description = " description = ''
Mount this file system to boot on NixOS. If set, this file system will be mounted in the initial
"; ramdisk. By default, this applies to the root file system
and to the file system containing
<filename>/nix/store</filename>.
'';
}; };
}; };
@ -236,8 +239,8 @@ let
# booting (such as the FS containing /nix/store, or an FS needed for # booting (such as the FS containing /nix/store, or an FS needed for
# mounting /, like / on a loopback). # mounting /, like / on a loopback).
fileSystems = filter fileSystems = filter
(fs: fs.mountPoint == "/" || fs.neededForBoot) (fs: fs.mountPoint == "/" || fs.mountPoint == "/nix" || fs.mountPoint == "/nix/store" || fs.neededForBoot)
config.fileSystems; (attrValues config.fileSystems);
udevRules = pkgs.stdenv.mkDerivation { udevRules = pkgs.stdenv.mkDerivation {

View File

@ -5,12 +5,14 @@ with utils;
let let
fileSystems = attrValues config.fileSystems;
fstab = pkgs.writeText "fstab" fstab = pkgs.writeText "fstab"
'' ''
# This is a generated file. Do not edit! # This is a generated file. Do not edit!
# Filesystems. # Filesystems.
${flip concatMapStrings config.fileSystems (fs: ${flip concatMapStrings fileSystems (fs:
(if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}") (if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}")
+ " " + fs.mountPoint + " " + fs.mountPoint
+ " " + fs.fsType + " " + fs.fsType
@ -27,47 +29,7 @@ let
)} )}
''; '';
in fileSystemOpts = { name, ... }: {
{
###### interface
options = {
fileSystems = mkOption {
example = [
{ mountPoint = "/";
device = "/dev/hda1";
}
{ mountPoint = "/data";
device = "/dev/hda2";
fsType = "ext3";
options = "data=journal";
}
{ mountPoint = "/bigdisk";
label = "bigdisk";
}
];
description = ''
The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = \"/\"</literal>). Each
entry in the list is an attribute set with the following fields:
<literal>mountPoint</literal>, <literal>device</literal>,
<literal>fsType</literal> (a file system type recognised by
<command>mount</command>; defaults to
<literal>\"auto\"</literal>), and <literal>options</literal>
(the mount options passed to <command>mount</command> using the
<option>-o</option> flag; defaults to <literal>\"defaults\"</literal>).
Instead of specifying <literal>device</literal>, you can also
specify a volume label (<literal>label</literal>) for file
systems that support it, such as ext2/ext3 (see <command>mke2fs
-L</command>).
'';
type = types.list types.optionSet;
options = { options = {
@ -122,7 +84,51 @@ in
type = types.bool; type = types.bool;
description = "Disable running fsck on this filesystem."; description = "Disable running fsck on this filesystem.";
}; };
}; };
config = {
mountPoint = mkDefault name;
};
};
in
{
###### interface
options = {
fileSystems = mkOption {
example = {
"/".device = "/dev/hda1";
"/data" = {
device = "/dev/hda2";
fsType = "ext3";
options = "data=journal";
};
"/bigdisk".label = "bigdisk";
};
type = types.loaOf types.optionSet;
options = [ fileSystemOpts ];
description = ''
The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = \"/\"</literal>). Each
entry in the list is an attribute set with the following fields:
<literal>mountPoint</literal>, <literal>device</literal>,
<literal>fsType</literal> (a file system type recognised by
<command>mount</command>; defaults to
<literal>\"auto\"</literal>), and <literal>options</literal>
(the mount options passed to <command>mount</command> using the
<option>-o</option> flag; defaults to <literal>\"defaults\"</literal>).
Instead of specifying <literal>device</literal>, you can also
specify a volume label (<literal>label</literal>) for file
systems that support it, such as ext2/ext3 (see <command>mke2fs
-L</command>).
'';
}; };
system.fsPackages = mkOption { system.fsPackages = mkOption {
@ -152,12 +158,11 @@ in
config = { config = {
boot.supportedFilesystems = boot.supportedFilesystems = map (fs: fs.fsType) fileSystems;
map (fs: fs.fsType) config.fileSystems;
boot.initrd.supportedFilesystems = boot.initrd.supportedFilesystems =
map (fs: fs.fsType) map (fs: fs.fsType)
(filter (fs: fs.mountPoint == "/" || fs.neededForBoot) config.fileSystems); (filter (fs: fs.mountPoint == "/" || fs.neededForBoot) fileSystems);
# Add the mount helpers to the system path so that `mount' can find them. # Add the mount helpers to the system path so that `mount' can find them.
system.fsPackages = [ pkgs.dosfstools ]; system.fsPackages = [ pkgs.dosfstools ];
@ -207,7 +212,7 @@ in
serviceConfig.Type = "oneshot"; serviceConfig.Type = "oneshot";
}; };
in listToAttrs (map formatDevice (filter (fs: fs.autoFormat) config.fileSystems)); in listToAttrs (map formatDevice (filter (fs: fs.autoFormat) fileSystems));
}; };

View File

@ -62,11 +62,7 @@ with pkgs.lib;
'' ''
); );
fileSystems = fileSystems."/".device = "/dev/disk/by-label/nixos";
[ { mountPoint = "/";
device = "/dev/disk/by-label/nixos";
}
];
boot.initrd.kernelModules = [ "xen-blkfront" "aufs" ]; boot.initrd.kernelModules = [ "xen-blkfront" "aufs" ];
boot.kernelModules = [ "xen-netfront" ]; boot.kernelModules = [ "xen-netfront" ];

View File

@ -68,11 +68,7 @@ with pkgs.lib;
'' ''
); );
fileSystems = fileSystems."/".device = "/dev/disk/by-label/nixos";
[ { mountPoint = "/";
device = "/dev/disk/by-label/nixos";
}
];
boot.kernelParams = [ "console=ttyS0" ]; boot.kernelParams = [ "console=ttyS0" ];

View File

@ -320,35 +320,33 @@ in
# where the regular value for the `fileSystems' attribute should be # where the regular value for the `fileSystems' attribute should be
# disregarded for the purpose of building a VM test image (since # disregarded for the purpose of building a VM test image (since
# those filesystems don't exist in the VM). # those filesystems don't exist in the VM).
fileSystems = mkOverride 50 ( fileSystems =
[ { mountPoint = "/"; { "/".device = "/dev/vda";
device = "/dev/vda"; "/nix/store" =
} { device = "//10.0.2.4/store";
{ mountPoint = "/nix/store"; fsType = "cifs";
device = "//10.0.2.4/store"; options = "guest,sec=none,noperm,noacl";
};
"/tmp/xchg" =
{ device = "//10.0.2.4/xchg";
fsType = "cifs"; fsType = "cifs";
options = "guest,sec=none,noperm,noacl"; options = "guest,sec=none,noperm,noacl";
neededForBoot = true; neededForBoot = true;
} };
{ mountPoint = "/tmp/xchg"; "/tmp/shared" =
device = "//10.0.2.4/xchg"; { device = "//10.0.2.4/shared";
fsType = "cifs"; fsType = "cifs";
options = "guest,sec=none,noperm,noacl"; options = "guest,sec=none,noperm,noacl";
neededForBoot = true; neededForBoot = true;
} };
{ mountPoint = "/tmp/shared"; } // optionalAttrs cfg.useBootLoader
device = "//10.0.2.4/shared"; { "/boot" =
fsType = "cifs"; { device = "/dev/disk/by-label/boot";
options = "guest,sec=none,noperm,noacl";
neededForBoot = true;
}
] ++ optional cfg.useBootLoader
{ mountPoint = "/boot";
device = "/dev/disk/by-label/boot";
fsType = "ext4"; fsType = "ext4";
options = "ro"; options = "ro";
noCheck = true; # fsck fails on a r/o filesystem noCheck = true; # fsck fails on a r/o filesystem
}); };
};
swapDevices = mkOverride 50 [ ]; swapDevices = mkOverride 50 [ ];

View File

@ -71,11 +71,7 @@ with pkgs.lib;
'' ''
); );
fileSystems = fileSystems."/".device = "/dev/disk/by-label/nixos";
[ { mountPoint = "/";
device = "/dev/disk/by-label/nixos";
}
];
boot.loader.grub.version = 2; boot.loader.grub.version = 2;
boot.loader.grub.device = "/dev/sda"; boot.loader.grub.device = "/dev/sda";