diff --git a/doc/manual/installation.xml b/doc/manual/installation.xml index 0a69ce0ecba8..ed5348829c8b 100644 --- a/doc/manual/installation.xml +++ b/doc/manual/installation.xml @@ -230,11 +230,7 @@ $ reboot { boot.loader.grub.device = "/dev/sda"; - fileSystems = - [ { mountPoint = "/"; - device = "/dev/disk/by-label/nixos"; - } - ]; + fileSystems."/".device = "/dev/disk/by-label/nixos"; swapDevices = [ { device = "/dev/disk/by-label/swap"; } ]; diff --git a/modules/installer/cd-dvd/iso-image.nix b/modules/installer/cd-dvd/iso-image.nix index be4777356e48..96fc8a31dca2 100644 --- a/modules/installer/cd-dvd/iso-image.nix +++ b/modules/installer/cd-dvd/iso-image.nix @@ -184,17 +184,13 @@ in # Note that /dev/root is a symlink to the actual root device # specified on the kernel command line, created in the stage 1 init # script. - fileSystems = - [ { mountPoint = "/"; - device = "/dev/root"; - } - { mountPoint = "/nix/store"; - fsType = "squashfs"; - device = "/nix-store.squashfs"; - options = "loop"; - neededForBoot = true; - } - ]; + fileSystems."/".device = "/dev/root"; + + fileSystems."/nix/store" = + { fsType = "squashfs"; + device = "/nix-store.squashfs"; + options = "loop"; + }; # We need squashfs in the initrd to mount the compressed Nix store, # and aufs to make the root filesystem appear writable. diff --git a/modules/installer/tools/nixos-option.sh b/modules/installer/tools/nixos-option.sh index 656f2a874033..47abac7fddd0 100644 --- a/modules/installer/tools/nixos-option.sh +++ b/modules/installer/tools/nixos-option.sh @@ -239,17 +239,14 @@ if $generate; then # Add filesystem entries for each partition that you want to see # mounted at boot time. This should include at least the root # filesystem. - fileSystems = - [ # { mountPoint = "/"; - # device = "/dev/disk/by-label/nixos"; - # } - # { mountPoint = "/data"; # where you want to mount the device - # device = "/dev/sdb"; # the device - # fsType = "ext3"; # the type of the partition - # options = "data=journal"; - # } - ]; + # fileSystems."/".device = "/dev/disk/by-label/nixos"; + + # fileSystems."/data" = # where you want to mount the device + # { device = "/dev/sdb"; # the device + # fsType = "ext3"; # the type of the partition + # options = "data=journal"; + # }; # List swap partitions activated at boot time. swapDevices = diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index 18d11e2d4025..ac8a3ccc2386 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -99,9 +99,12 @@ let options.neededForBoot = mkOption { default = false; type = types.bool; - description = " - Mount this file system to boot on NixOS. - "; + description = '' + 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 + /nix/store. + ''; }; }; @@ -236,8 +239,8 @@ let # booting (such as the FS containing /nix/store, or an FS needed for # mounting /, like / on a loopback). fileSystems = filter - (fs: fs.mountPoint == "/" || fs.neededForBoot) - config.fileSystems; + (fs: fs.mountPoint == "/" || fs.mountPoint == "/nix" || fs.mountPoint == "/nix/store" || fs.neededForBoot) + (attrValues config.fileSystems); udevRules = pkgs.stdenv.mkDerivation { diff --git a/modules/tasks/filesystems.nix b/modules/tasks/filesystems.nix index 66c97c5fd112..00d711eecd31 100644 --- a/modules/tasks/filesystems.nix +++ b/modules/tasks/filesystems.nix @@ -5,12 +5,14 @@ with utils; let + fileSystems = attrValues config.fileSystems; + fstab = pkgs.writeText "fstab" '' # This is a generated file. Do not edit! # Filesystems. - ${flip concatMapStrings config.fileSystems (fs: + ${flip concatMapStrings fileSystems (fs: (if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}") + " " + fs.mountPoint + " " + 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 blkid, then automatically + format it with the filesystem type specified in + . Use with caution. + ''; + }; + + noCheck = mkOption { + default = false; + type = types.bool; + description = "Disable running fsck on this filesystem."; + }; + + }; + + config = { + mountPoint = mkDefault name; + }; + + }; + in { @@ -36,20 +102,17 @@ in options = { fileSystems = mkOption { - example = [ - { mountPoint = "/"; - device = "/dev/hda1"; - } - { mountPoint = "/data"; + example = { + "/".device = "/dev/hda1"; + "/data" = { device = "/dev/hda2"; fsType = "ext3"; options = "data=journal"; - } - { mountPoint = "/bigdisk"; - label = "bigdisk"; - } - ]; - + }; + "/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 (mountPoint = \"/\"). Each @@ -66,63 +129,6 @@ in systems that support it, such as ext2/ext3 (see mke2fs -L). ''; - - 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 blkid, then automatically - format it with the filesystem type specified in - . Use with caution. - ''; - }; - - noCheck = mkOption { - default = false; - type = types.bool; - description = "Disable running fsck on this filesystem."; - }; - }; }; system.fsPackages = mkOption { @@ -152,12 +158,11 @@ in config = { - boot.supportedFilesystems = - map (fs: fs.fsType) config.fileSystems; + boot.supportedFilesystems = map (fs: fs.fsType) fileSystems; boot.initrd.supportedFilesystems = 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. system.fsPackages = [ pkgs.dosfstools ]; @@ -207,7 +212,7 @@ in serviceConfig.Type = "oneshot"; }; - in listToAttrs (map formatDevice (filter (fs: fs.autoFormat) config.fileSystems)); + in listToAttrs (map formatDevice (filter (fs: fs.autoFormat) fileSystems)); }; diff --git a/modules/virtualisation/amazon-image.nix b/modules/virtualisation/amazon-image.nix index 9ada2b176fe3..da6f6d3afc92 100644 --- a/modules/virtualisation/amazon-image.nix +++ b/modules/virtualisation/amazon-image.nix @@ -62,11 +62,7 @@ with pkgs.lib; '' ); - fileSystems = - [ { mountPoint = "/"; - device = "/dev/disk/by-label/nixos"; - } - ]; + fileSystems."/".device = "/dev/disk/by-label/nixos"; boot.initrd.kernelModules = [ "xen-blkfront" "aufs" ]; boot.kernelModules = [ "xen-netfront" ]; diff --git a/modules/virtualisation/nova-image.nix b/modules/virtualisation/nova-image.nix index ea4dbcc4dd4c..2aa78aeaddab 100644 --- a/modules/virtualisation/nova-image.nix +++ b/modules/virtualisation/nova-image.nix @@ -68,11 +68,7 @@ with pkgs.lib; '' ); - fileSystems = - [ { mountPoint = "/"; - device = "/dev/disk/by-label/nixos"; - } - ]; + fileSystems."/".device = "/dev/disk/by-label/nixos"; boot.kernelParams = [ "console=ttyS0" ]; diff --git a/modules/virtualisation/qemu-vm.nix b/modules/virtualisation/qemu-vm.nix index e3927442821e..22e5017d7c08 100644 --- a/modules/virtualisation/qemu-vm.nix +++ b/modules/virtualisation/qemu-vm.nix @@ -320,35 +320,33 @@ in # where the regular value for the `fileSystems' attribute should be # disregarded for the purpose of building a VM test image (since # those filesystems don't exist in the VM). - fileSystems = mkOverride 50 ( - [ { mountPoint = "/"; - device = "/dev/vda"; - } - { mountPoint = "/nix/store"; - device = "//10.0.2.4/store"; - fsType = "cifs"; - options = "guest,sec=none,noperm,noacl"; - neededForBoot = true; - } - { mountPoint = "/tmp/xchg"; - device = "//10.0.2.4/xchg"; - fsType = "cifs"; - options = "guest,sec=none,noperm,noacl"; - neededForBoot = true; - } - { mountPoint = "/tmp/shared"; - device = "//10.0.2.4/shared"; - fsType = "cifs"; - options = "guest,sec=none,noperm,noacl"; - neededForBoot = true; - } - ] ++ optional cfg.useBootLoader - { mountPoint = "/boot"; - device = "/dev/disk/by-label/boot"; - fsType = "ext4"; - options = "ro"; - noCheck = true; # fsck fails on a r/o filesystem - }); + fileSystems = + { "/".device = "/dev/vda"; + "/nix/store" = + { device = "//10.0.2.4/store"; + fsType = "cifs"; + options = "guest,sec=none,noperm,noacl"; + }; + "/tmp/xchg" = + { device = "//10.0.2.4/xchg"; + fsType = "cifs"; + options = "guest,sec=none,noperm,noacl"; + neededForBoot = true; + }; + "/tmp/shared" = + { device = "//10.0.2.4/shared"; + fsType = "cifs"; + options = "guest,sec=none,noperm,noacl"; + neededForBoot = true; + }; + } // optionalAttrs cfg.useBootLoader + { "/boot" = + { device = "/dev/disk/by-label/boot"; + fsType = "ext4"; + options = "ro"; + noCheck = true; # fsck fails on a r/o filesystem + }; + }; swapDevices = mkOverride 50 [ ]; diff --git a/modules/virtualisation/virtualbox-image.nix b/modules/virtualisation/virtualbox-image.nix index f049c5eb348a..8fe0030946a6 100644 --- a/modules/virtualisation/virtualbox-image.nix +++ b/modules/virtualisation/virtualbox-image.nix @@ -71,11 +71,7 @@ with pkgs.lib; '' ); - fileSystems = - [ { mountPoint = "/"; - device = "/dev/disk/by-label/nixos"; - } - ]; + fileSystems."/".device = "/dev/disk/by-label/nixos"; boot.loader.grub.version = 2; boot.loader.grub.device = "/dev/sda";