summary refs log tree commit diff
path: root/pkgs/os-specific/linux/spectrum/rootfs/generic.nix
blob: 778b18dafa032792fc6a25e66512d1ec0b2ee9e2 (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
{ runCommandNoCC, writeScript, writeReferencesToFile, makeFontsConf, lib
, dash, execline, s6, s6-portable-utils, s6-linux-utils, s6-linux-init, busybox
, mesa, squashfs-tools-ng
}:

{ services, run, fonts ? [], path ? [] }:

let
  makeStage1 = import ./stage1.nix {
    inherit writeScript lib
      execline s6 s6-portable-utils s6-linux-utils s6-linux-init busybox mesa;
  };

  makeServicesDir = import ./services.nix {
    inherit runCommandNoCC writeScript lib execline;
  };

  fontsConf = makeFontsConf { fontDirectories = fonts; };

  squashfs = runCommandNoCC "root-squashfs" {} ''
    cd ${rootfs}
    (
        grep -v ^${rootfs} ${writeReferencesToFile rootfs}
        printf "%s\n" *
    ) \
        | xargs tar -cP --owner root:0 --group root:0 --hard-dereference \
        | ${squashfs-tools-ng}/bin/tar2sqfs -c gzip -X level=1 $out
  '';

  rootfs = runCommandNoCC "rootfs" { passthru = { inherit squashfs; }; } ''
    mkdir $out
    cd $out

    mkdir bin sbin dev proc run tmp
    ln -s ${dash}/bin/dash bin/sh
    ln -s ${makeStage1 { inherit run; }} sbin/init
    cp -r ${./etc} etc
    chmod u+w etc

    mkdir etc/fonts
    ln -s ${fontsConf} etc/fonts/fonts.conf

    touch etc/login.defs
    cp -r ${makeServicesDir { inherit services; }} etc/service
  '';
in
rootfs