about summary refs log tree commit diff
path: root/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
blob: eb8a9155142656963439fe74907cf79952f5a6e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{ stdenv, fetchurl, lib, patchelf, cdrkit, kernel, which, makeWrapper
, libX11, libXt, libXext, libXmu, libXcomposite, libXfixes, libXrandr, libXcursor}:

stdenv.mkDerivation {
  name = "VirtualBox-GuestAdditions-3.2.8";
  src = fetchurl {
    url = http://download.virtualbox.org/virtualbox/3.2.8/VBoxGuestAdditions_3.2.8.iso;
    sha256 = "1pyfgrcdmw6zf3yxgzcd8c5qzqqn62bz4085ka453gfmi9d65lys";
  };
  KERN_DIR = "${kernel}/lib/modules/*/build";
  buildInputs = [ patchelf cdrkit makeWrapper ];

  installPhase = ''
    ensureDir $out
    cp -r install/* $out

  '';
  
  buildCommand = ''
    ${if stdenv.system == "i686-linux" then ''
        isoinfo -J -i $src -x /VBoxLinuxAdditions-x86.run > ./VBoxLinuxAdditions-x86.run
        chmod 755 ./VBoxLinuxAdditions-x86.run
        ./VBoxLinuxAdditions-x86.run --noexec --keep
      ''
      else if stdenv.system == "x86_64-linux" then ''
        isoinfo -J -i $src -x /VBoxLinuxAdditions-amd64.run > ./VBoxLinuxAdditions-amd64.run
        chmod 755 ./VBoxLinuxAdditions-amd64.run
	./VBoxLinuxAdditions-amd64.run --noexec --keep
      ''
      else throw ("Architecture: "+stdenv.system+" not supported for VirtualBox guest additions")
    }
    
    # Unpack files
    cd install
    tar xfvj VBoxGuestAdditions.tar.bz2
    
    # Build kernel modules    
    cd src        

    for i in *
    do
	cd $i
	sed -i -e "s/depmod/echo/g" Makefile
	make
	cd ..
    done
    cd ..
    
    # Change the interpreter for various binaries
    for i in sbin/VBoxService bin/{VBoxClient,VBoxControl}
    do
        ${if stdenv.system == "i686-linux" then ''
          patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 $i
	''
	else if stdenv.system == "x86_64-linux" then ''
	  patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $i
	''
	else throw ("Architecture: "+stdenv.system+" not supported for VirtualBox guest additions")
	}
    done

    # Change rpath for various binaries and libraries
    patchelf --set-rpath ${stdenv.gcc.gcc}/lib:${libX11}/lib:${libXt}/lib:${libXext}/lib:${libXmu}/lib:${libXfixes}/lib:${libXrandr}/lib:${libXcursor}/lib bin/VBoxClient

    for i in lib/VBoxOGL*.so
    do
        patchelf --set-rpath $out/lib $i
    done
    
    # Remove references to /usr from various scripts and files
    sed -i -e "s|/usr/bin|$out/bin|" share/VBoxGuestAdditions/vboxclient.desktop
    sed -i -e "s|/usr/bin|$out/bin|" bin/VBoxClient-all
    
    # Install binaries
    ensureDir $out/sbin
    install -m 755 sbin/VBoxService $out/sbin

    ensureDir $out/bin
    install -m 755 bin/VBoxClient $out/bin
    install -m 755 bin/VBoxControl $out/bin
    install -m 755 bin/VBoxClient-all $out/bin

    wrapProgram $out/bin/VBoxClient-all \
            --prefix PATH : "${which}/bin"

    # Install OpenGL libraries
    ensureDir $out/lib
    cp -v lib/VBoxOGL*.so $out/lib
    ensureDir $out/lib/dri
    ln -s $out/lib/VBoxOGL.so $out/lib/dri/vboxvideo_dri.so
    
    # Install desktop file
    ensureDir $out/share/autostart
    cp -v share/VBoxGuestAdditions/vboxclient.desktop $out/share/autostart
    
    # Install HAL FDI file
    ensureDir $out/share/hal/fdi/policy
    install -m 644 share/VBoxGuestAdditions/90-vboxguest.fdi $out/share/hal/fdi/policy
    
    # Install Xorg drivers
    ensureDir $out/lib/xorg/modules/{drivers,input}
    install -m 644 lib/VBoxGuestAdditions/vboxvideo_drv_18.so $out/lib/xorg/modules/drivers/vboxvideo_drv.so
    install -m 644 lib/VBoxGuestAdditions/vboxmouse_drv_18.so $out/lib/xorg/modules/input/vboxmouse_drv.so
    
    # Install kernel modules
    cd src
    
    for i in *
    do
        cd $i
	kernelVersion=$(cd ${kernel}/lib/modules; ls)
	export MODULE_DIR=$out/lib/modules/$kernelVersion/misc
	sed -i -e "s|-o root||g" \
	       -e "s|-g root||g" Makefile
	make install
	cd ..
    done    
  '';
  
  meta = {
    description = "Guest additions for VirtualBox";
    longDescriptions = ''
      Various add-ons which makes NixOS work better as guest OS inside VirtualBox.
      This add-on provides support for dynamic resizing of the X Display, shared
      host/guest clipboard support and guest OpenGL support.
    '';
    license = "GPL";
    maintainers = [ lib.maintainers.sander ];
  };
}