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"; device = "/nix-store.squashfs";
fsType = "squashfs"; options = "loop";
device = "/nix-store.squashfs"; };
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
# fsType = "ext3"; # the type of the partition # fileSystems."/data" = # where you want to mount the device
# options = "data=journal"; # { device = "/dev/sdb"; # the device
# } # fsType = "ext3"; # the type of the partition
]; # 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,6 +29,70 @@ let
)} )}
''; '';
fileSystemOpts = { name, ... }: {
options = {
mountPoint = mkOption {
example = "/mnt/usb";
type = types.uniq types.string;
description = "Location of the mounted the file system.";
};
device = mkOption {
default = null;
example = "/dev/sda";
type = types.uniq (types.nullOr types.string);
description = "Location of the device.";
};
label = mkOption {
default = null;
example = "root-partition";
type = types.uniq (types.nullOr types.string);
description = "Label of the device (if any).";
};
fsType = mkOption {
default = "auto";
example = "ext3";
type = types.uniq types.string;
description = "Type of the file system.";
};
options = mkOption {
default = "defaults,relatime";
example = "data=journal";
type = types.string;
merge = pkgs.lib.concatStringsSep ",";
description = "Options used to mount the file system.";
};
autoFormat = mkOption {
default = false;
type = types.bool;
description = ''
If the device does not currently contain a filesystem (as
determined by <command>blkid</command>, then automatically
format it with the filesystem type specified in
<option>fsType</option>. Use with caution.
'';
};
noCheck = mkOption {
default = false;
type = types.bool;
description = "Disable running fsck on this filesystem.";
};
};
config = {
mountPoint = mkDefault name;
};
};
in in
{ {
@ -36,20 +102,17 @@ in
options = { options = {
fileSystems = mkOption { fileSystems = mkOption {
example = [ example = {
{ mountPoint = "/"; "/".device = "/dev/hda1";
device = "/dev/hda1"; "/data" = {
}
{ mountPoint = "/data";
device = "/dev/hda2"; device = "/dev/hda2";
fsType = "ext3"; fsType = "ext3";
options = "data=journal"; options = "data=journal";
} };
{ mountPoint = "/bigdisk"; "/bigdisk".label = "bigdisk";
label = "bigdisk"; };
} type = types.loaOf types.optionSet;
]; options = [ fileSystemOpts ];
description = '' description = ''
The file systems to be mounted. It must include an entry for The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = \"/\"</literal>). Each the root directory (<literal>mountPoint = \"/\"</literal>). Each
@ -66,63 +129,6 @@ in
systems that support it, such as ext2/ext3 (see <command>mke2fs systems that support it, such as ext2/ext3 (see <command>mke2fs
-L</command>). -L</command>).
''; '';
type = types.list types.optionSet;
options = {
mountPoint = mkOption {
example = "/mnt/usb";
type = types.uniq types.string;
description = "Location of the mounted the file system.";
};
device = mkOption {
default = null;
example = "/dev/sda";
type = types.uniq (types.nullOr types.string);
description = "Location of the device.";
};
label = mkOption {
default = null;
example = "root-partition";
type = types.uniq (types.nullOr types.string);
description = "Label of the device (if any).";
};
fsType = mkOption {
default = "auto";
example = "ext3";
type = types.uniq types.string;
description = "Type of the file system.";
};
options = mkOption {
default = "defaults,relatime";
example = "data=journal";
type = types.string;
merge = pkgs.lib.concatStringsSep ",";
description = "Options used to mount the file system.";
};
autoFormat = mkOption {
default = false;
type = types.bool;
description = ''
If the device does not currently contain a filesystem (as
determined by <command>blkid</command>, then automatically
format it with the filesystem type specified in
<option>fsType</option>. Use with caution.
'';
};
noCheck = mkOption {
default = false;
type = types.bool;
description = "Disable running fsck on this filesystem.";
};
};
}; };
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";
fsType = "cifs"; };
options = "guest,sec=none,noperm,noacl"; "/tmp/xchg" =
neededForBoot = true; { device = "//10.0.2.4/xchg";
} fsType = "cifs";
{ mountPoint = "/tmp/xchg"; options = "guest,sec=none,noperm,noacl";
device = "//10.0.2.4/xchg"; neededForBoot = true;
fsType = "cifs"; };
options = "guest,sec=none,noperm,noacl"; "/tmp/shared" =
neededForBoot = true; { device = "//10.0.2.4/shared";
} fsType = "cifs";
{ mountPoint = "/tmp/shared"; options = "guest,sec=none,noperm,noacl";
device = "//10.0.2.4/shared"; neededForBoot = true;
fsType = "cifs"; };
options = "guest,sec=none,noperm,noacl"; } // optionalAttrs cfg.useBootLoader
neededForBoot = true; { "/boot" =
} { device = "/dev/disk/by-label/boot";
] ++ optional cfg.useBootLoader fsType = "ext4";
{ mountPoint = "/boot"; options = "ro";
device = "/dev/disk/by-label/boot"; noCheck = true; # fsck fails on a r/o filesystem
fsType = "ext4"; };
options = "ro"; };
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";