default.nix (2155B)
1 { 2 stdenvNoCC 3 , s6-rc 4 , s6 5 , lib 6 , callPackage 7 , writeScript 8 , serviceFns 9 }: 10 let 11 inherit (builtins) concatStringsSep; 12 output = service: name: "/run/service-state/${service.name}/${name}"; 13 serviceScript = commands : '' 14 #!/bin/sh 15 exec 2>&1 16 . ${serviceFns} 17 ${commands} 18 ''; 19 service = { 20 name 21 , serviceType 22 , run ? null 23 , up ? null 24 , down ? null 25 , outputs ? [] 26 , notification-fd ? null 27 , producer-for ? null 28 , consumer-for ? null 29 , pipeline-name ? null 30 , dependencies ? [] 31 , contents ? [] 32 , buildInputs ? [] 33 } @ args: 34 stdenvNoCC.mkDerivation { 35 # we use stdenvNoCC to avoid generating derivations with names 36 # like foo.service-mips-linux-musl 37 inherit name serviceType up down run notification-fd 38 producer-for consumer-for pipeline-name; 39 buildInputs = buildInputs ++ dependencies ++ contents; 40 dependencies = builtins.map (d: d.name) dependencies; 41 contents = builtins.map (d: d.name) contents; 42 builder = ./builder.sh; 43 }; 44 45 longrun = { 46 name 47 , run 48 , outputs ? [] 49 , notification-fd ? null 50 , dependencies ? [] 51 , ... 52 } @ args: 53 let logger = service { 54 serviceType = "longrun"; 55 name = "${name}-log"; 56 run = serviceScript "${s6}/bin/s6-log -d 10 -- p${name} 1"; 57 notification-fd = 10; 58 consumer-for = name; 59 pipeline-name = "${name}-pipeline"; 60 }; 61 in service (args // { 62 buildInputs = [ logger ]; 63 serviceType = "longrun"; 64 run = serviceScript run; 65 producer-for = "${name}-log"; 66 }); 67 68 oneshot = { 69 name 70 , up 71 , down 72 , outputs ? [] 73 , dependencies ? [] 74 , ... 75 } @ args : service (args // { 76 serviceType = "oneshot"; 77 up = writeScript "${name}-up" (serviceScript up); 78 down= writeScript "${name}-down" (serviceScript down); 79 }); 80 bundle = { 81 name 82 , contents ? [] 83 , dependencies ? [] 84 , ... 85 } @ args: service (args // { 86 serviceType = "bundle"; 87 inherit contents dependencies; 88 }); 89 target = bundle; 90 in { 91 inherit target bundle oneshot longrun output; 92 }