summary refs log tree commit diff
path: root/test/boot-environment.nix
blob: 05099ee97bb2e1cc6ab16ee492438e1fb2b7ec42 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{ system ? __currentSystem
, autoDetectRootDevice ? false
, rootDevice ? ""
, rootLabel ? ""
, stage2Init
, readOnlyRoot
}:

rec {

  pkgs = import ./pkgs/top-level/all-packages.nix {inherit system;};

  pkgsDiet = import ./pkgs/top-level/all-packages.nix {
    inherit system;
    bootStdenv = pkgs.useDietLibC pkgs.stdenv;
  };

  pkgsStatic = import ./pkgs/top-level/all-packages.nix {
    inherit system;
    bootStdenv = pkgs.makeStaticBinaries pkgs.stdenv;
  };

  stdenvLinuxStuff = import ./pkgs/stdenv/linux {
    system = pkgs.stdenv.system;
    allPackages = import ./pkgs/top-level/all-packages.nix;
  };

  nix = pkgs.nixUnstable; # we need the exportReferencesGraph feature


  # Determine the set of modules that we need to mount the root FS.
  modulesClosure = import ./modules-closure.nix {
    inherit (pkgs) stdenv kernel module_init_tools;
    rootModules = ["ide-cd" "ide-disk" "ide-generic"];
  };


  # Some additional utilities needed in stage 1, notably mount.  We
  # don't want to bring in all of util-linux, so we just copy what we
  # need.
  extraUtils = pkgs.stdenv.mkDerivation {
    name = "extra-utils";
    builder = builtins.toFile "builder.sh" "
      source $stdenv/setup
      ensureDir $out/bin
      cp $utillinux/bin/mount $utillinux/bin/umount $utillinux/sbin/pivot_root $out/bin
      cp -p $e2fsprogs/sbin/fsck* $e2fsprogs/sbin/e2fsck $out/bin
      nuke-refs $out/bin/*
    ";
    buildInputs = [pkgs.nukeReferences];
    inherit (pkgsStatic) utillinux;
    e2fsprogs = pkgs.e2fsprogsDiet;
  };
  

  # The init script of boot stage 1 (loading kernel modules for
  # mounting the root FS).
  bootStage1 = import ./boot-stage-1.nix {
    inherit (pkgs) genericSubstituter;
    inherit (pkgsDiet) module_init_tools;
    inherit extraUtils;
    inherit autoDetectRootDevice rootDevice rootLabel;
    inherit stage2Init;
    modules = modulesClosure;
    shell = stdenvLinuxStuff.bootstrapTools.bash;
    staticTools = stdenvLinuxStuff.staticTools;
  };
  

  # The closure of the init script of boot stage 1 is what we put in
  # the initial RAM disk.
  initialRamdisk = import ./make-initrd.nix {
    inherit (pkgs) stdenv cpio;
    init = bootStage1;
  };


  # The installer.
  nixosInstaller = import ./installer.nix {
    inherit (pkgs) stdenv genericSubstituter;
    inherit nix;
    shell = pkgs.bash + "/bin/sh";
  };


  # The services (Upstart) configuration for the system.
  upstartJobs = import ./upstart-jobs/gather.nix {
    inherit (pkgs) stdenv;

    jobs = map makeJob [
      # Syslogd.
      (import ./upstart-jobs/syslogd.nix {
        inherit (pkgs) sysklogd;
      })

      # Hardware scan; loads modules for PCI devices.
      (import ./upstart-jobs/hardware-scan.nix {
        inherit (pkgs) kernel module_init_tools;
      })
      
      # Network interfaces.
      (import ./upstart-jobs/network-interfaces.nix {
        inherit (pkgs) nettools kernel module_init_tools;
      })
      
      # DHCP client.
      (import ./upstart-jobs/dhclient.nix {
        dhcp = pkgs.dhcpWrapper;
      })

      # SSH daemon.
      (import ./upstart-jobs/sshd.nix {
        inherit (pkgs) openssh;
      })

      # Transparent TTY backgrounds.
      (import ./upstart-jobs/tty-backgrounds.nix {
        inherit (pkgs) stdenv splashutils;
        backgrounds = (import ./splash-themes.nix {
          inherit (pkgs) fetchurl;
        }).ttyBackgrounds;
      })

      # Handles the maintenance/stalled event (single-user shell).
      (import ./upstart-jobs/maintenance-shell.nix {
        inherit (pkgs) bash;
      })

      # Ctrl-alt-delete action.
      (import ./upstart-jobs/ctrl-alt-delete.nix)

    ]

    # Handles the reboot/halt events.
    ++ (map
      (event: makeJob (import ./upstart-jobs/halt.nix {
        inherit (pkgs) bash;
        inherit event;
      }))
      ["reboot" "halt" "system-halt" "power-off"]
    )
    
    # The terminals on ttyX.
    ++ (map 
      (ttyNumber: makeJob (import ./upstart-jobs/mingetty.nix {
        mingetty = pkgs.mingettyWrapper;
        inherit ttyNumber;
      }))
      [1 2 3 4 5 6]
    )

    # For the builtin logd job.
    ++ [pkgs.upstart];
  };

  
  makeJob = import ./upstart-jobs/make-job.nix {
    inherit (pkgs) stdenv;
  };


  # The init script of boot stage 2, which is supposed to do
  # everything else to bring up the system.
  bootStage2 = import ./boot-stage-2.nix {
    inherit (pkgs) genericSubstituter coreutils findutils
      utillinux kernel udev
      upstart;
    inherit upstartJobs;
    shell = pkgs.bash + "/bin/sh";

    # Additional stuff; add whatever you want here.
    path = [
      pkgs.bash
      pkgs.bzip2
      pkgs.cpio
      pkgs.curl
      pkgs.e2fsprogs
      pkgs.gnugrep
      pkgs.gnused
      pkgs.gnutar
      pkgs.grub
      pkgs.gzip
      pkgs.iputils
      pkgs.less
      pkgs.module_init_tools
      pkgs.nano
      pkgs.netcat
      pkgs.nettools
      pkgs.perl
      pkgs.procps
      pkgs.rsync
      pkgs.shadowutils
      pkgs.strace
      pkgs.sysklogd
#      pkgs.sysvinit
#      pkgs.vim
      nix
      nixosInstaller
    ];

    inherit readOnlyRoot;
  };


}