liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

default.nix (3981B)


      1 { config, pkgs, ... }:
      2 let
      3   inherit (pkgs)
      4     execline
      5     s6
      6     s6-init-bin
      7     s6-linux-init
      8     stdenvNoCC;
      9   inherit (pkgs.pseudofile) dir symlink;
     10 
     11   s6-rc-db = pkgs.s6-rc-database.override {
     12     services = builtins.attrValues config.services;
     13   };
     14   s6-init-scripts = stdenvNoCC.mkDerivation {
     15     name = "s6-scripts";
     16     src = ./scripts;
     17     phases = ["unpackPhase" "installPhase" ];
     18     buildInputs = [];
     19     installPhase = ''
     20       mkdir $out
     21       cp -r $src $out/scripts
     22       chmod -R +w $out
     23     '';
     24   };
     25   service = dir  {
     26     s6-linux-init-runleveld = dir {
     27       notification-fd = { file = "3"; };
     28       run = {
     29         file = ''
     30               #!${execline}/bin/execlineb -P
     31               ${execline}/bin/fdmove -c 2 1
     32               ${execline}/bin/fdmove 1 3
     33               ${s6}/bin/s6-ipcserver -1 -a 0700 -c 1 -- s
     34               ${s6}/bin/s6-sudod -dt30000 -- "/etc/s6-linux-init/current"/scripts/runlevel
     35             '';
     36         mode = "0755";
     37       };
     38     };
     39     s6-linux-init-shutdownd = dir {
     40       fifo = {
     41         type = "i";
     42         mode = "0600";
     43       };
     44       run = {
     45         file = ''
     46               #!${execline}/bin/execlineb -P
     47               ${s6-linux-init}/bin/s6-linux-init-shutdownd -c  "/etc/s6-linux-init/current" -g 3000
     48             '';
     49         mode = "0755";
     50       };
     51     };
     52     s6-svscan-log = dir {
     53       fifo = {
     54         type = "i";
     55         mode = "0600";
     56       };
     57       notification-fd = { file = "3"; };
     58       run = {
     59         file = ''
     60               #!${execline}/bin/execlineb -P
     61               ${execline}/bin/redirfd -w 1 /dev/null
     62               ${execline}/bin/redirfd -rnb 0 fifo
     63               ${s6}/bin/s6-log -bpd3 -- t /run/uncaught-logs
     64           '';
     65         mode = "0755";
     66       };
     67     };
     68     getty = dir {
     69       run = {
     70         file = ''
     71               #!${execline}/bin/execlineb -P
     72               /bin/getty -l /bin/login 115200 /dev/console
     73           '';
     74         mode = "0755";
     75       };
     76     };
     77     ".s6-svscan" =
     78       let
     79         quit = message: ''
     80               #!${execline}/bin/execlineb -P
     81               ${execline}/bin/redirfd -w 2 /dev/console
     82               ${execline}/bin/fdmove -c 1 2
     83               ${execline}/bin/foreground { ${s6-linux-init}/bin/s6-linux-init-echo -- ${message} }
     84               ${s6-linux-init}/bin/s6-linux-init-hpr -fr
     85             '';
     86         shutdown = action: ''
     87               #!${execline}/bin/execlineb -P
     88               ${s6-linux-init}/bin/s6-linux-init-hpr -a #{action} -- now
     89             '';
     90         empty = "#!${execline}/bin/execlineb -P\n";
     91       in dir {
     92         crash = {
     93           file = quit "s6-svscan crashed. Rebooting.";
     94           mode = "0755";
     95         };
     96         finish = {
     97           file = quit "s6-svscan exited. Rebooting.";
     98           mode = "0755";
     99         };
    100         SIGINT = {
    101           file = shutdown "-r";
    102           mode = "0755";
    103         };
    104         SIGPWR = {
    105           file = shutdown "-p";
    106           mode = "0755";
    107         };
    108         SIGQUIT = {
    109           file = empty;
    110           mode = "0755";
    111         };
    112         SIGTERM = {
    113           file = empty;
    114           mode = "0755";
    115         };
    116         SIGUSR1 = {
    117           file = shutdown "-p";
    118           mode = "0755";
    119         };
    120         SIGUSR2 = {
    121           file = shutdown "-h";
    122           mode = "0755";
    123         };
    124         SIGWINCH = {
    125           file = empty;
    126           mode = "0755";
    127         };
    128 
    129       };
    130   };
    131 in {
    132   config = {
    133     programs.busybox.applets = [ "login" "getty" ];
    134     filesystem = dir {
    135       etc = dir {
    136         s6-rc = dir {
    137           compiled = symlink "${s6-rc-db}/compiled";
    138         };
    139         s6-linux-init = dir {
    140           current = dir {
    141             scripts = symlink "${s6-init-scripts}/scripts";
    142             env = dir {};
    143             run-image = dir {
    144               uncaught-logs = (dir {}) // {mode = "2750";};
    145               inherit service;
    146             };
    147           };
    148         };
    149       };
    150       bin = dir {
    151         init = symlink "${s6-init-bin}/bin/init";
    152       };
    153     };
    154   };
    155 }