summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorWilliam A. Kennington III <william@wkennington.com>2014-05-02 02:53:32 -0500
committerWilliam A. Kennington III <william@wkennington.com>2014-08-28 13:35:36 -0700
commit4f096c044f987f036af3fc1888090e6567aaf7b1 (patch)
tree8a5f625e272c200637242c845b2293ccea7675fc /nixos
parentc02bc3a9de319195597a16173e04357023e97643 (diff)
downloadnixpkgs-4f096c044f987f036af3fc1888090e6567aaf7b1.tar
nixpkgs-4f096c044f987f036af3fc1888090e6567aaf7b1.tar.gz
nixpkgs-4f096c044f987f036af3fc1888090e6567aaf7b1.tar.bz2
nixpkgs-4f096c044f987f036af3fc1888090e6567aaf7b1.tar.lz
nixpkgs-4f096c044f987f036af3fc1888090e6567aaf7b1.tar.xz
nixpkgs-4f096c044f987f036af3fc1888090e6567aaf7b1.tar.zst
nixpkgs-4f096c044f987f036af3fc1888090e6567aaf7b1.zip
nixos/grub: Simplify detection of labels / uuids for provided device names
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/system/boot/loader/grub/install-grub.pl22
-rw-r--r--nixos/tests/installer.nix2
2 files changed, 11 insertions, 13 deletions
diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl
index 2725cea5996..3c84fccac34 100644
--- a/nixos/modules/system/boot/loader/grub/install-grub.pl
+++ b/nixos/modules/system/boot/loader/grub/install-grub.pl
@@ -104,28 +104,26 @@ sub GrubFs {
                 $path = '/' . substr($fs->device, $sid) . '/@' . $path;
             }
         } else {
+            my %types = ('uuid' => '--fs-uuid', 'label' => '--label');
+
             if ($fsIdentifier eq 'provided') {
                 # If the provided dev is identifying the partition using a label or uuid,
                 # we should get the label / uuid and do a proper search
-                my $lbl = '/dev/disk/by-label/';
-                if (index($fs->device, $lbl) == 0) {
-                    $search = '--label ' . substr($fs->device, length($lbl));
-                }
-
-                my $uuid = '/dev/disk/by-uuid/';
-                if (index($fs->device, $uuid) == 0) {
-                    $search = '--fs-uuid ' . substr($fs->device, length($uuid));
+                my @matches = $fs->device =~ m/\/dev\/disk\/by-(label|uuid)\/(.*)/;
+                if ($#matches > 1) {
+                    die "Too many matched devices"
+                } elsif ($#matches == 1) {
+                    $search = "$types{$matches[0]} $matches[1]"
                 }
             } else {
                 # Determine the identifying type
-                my %types = ('uuid' => '--fs-uuid', 'label' => '--label');
                 $search = $types{$fsIdentifier} . ' ';
 
                 # Based on the type pull in the identifier from the system
                 my ($status, @devInfo) = runCommand("blkid -o export @{[$fs->device]}");
-				if ($status != 0) {
-					die "Failed to get blkid info for @{[$fs->device]}";
-				}
+                if ($status != 0) {
+                    die "Failed to get blkid info for @{[$fs->device]}";
+                }
                 my @matches = join("", @devInfo) =~ m/@{[uc $fsIdentifier]}=([^\n]*)/;
                 if ($#matches != 0) {
                     die "Couldn't find a $types{$fsIdentifier} for @{[$fs->device]}\n"
diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix
index d15c43d29bb..0eb67eaa813 100644
--- a/nixos/tests/installer.nix
+++ b/nixos/tests/installer.nix
@@ -416,7 +416,7 @@ in {
     createPartitions = ''
       $machine->succeed(
         "sgdisk -Z /dev/vda",
-        "sgdisk -n 1:0:+1M -n 2:0:+1G -n 3:0:+100M -N 4 -t 1:ef02 -t 2:8300 -t 3:8200 -t 4:8300 -c 2:boot -c 4:root /dev/vda",
+        "sgdisk -n 1:0:+1M -n 2:0:+100M -n 3:0:+1G -N 4 -t 1:ef02 -t 2:8300 -t 3:8200 -t 4:8300 -c 2:boot -c 4:root /dev/vda",
         "mkswap /dev/vda3 -L swap",
         "swapon -L swap",
         "mkfs.ext4 -L boot /dev/vda2",