{ lib, pkgs, ... }: with lib; let makeScript = name: service: pkgs.writeScript "${name}-runner" '' #! ${pkgs.perl.withPackages (p: [ p.FileSlurp ])}/bin/perl -w use File::Slurp; sub run { my ($cmd) = @_; my @args = (); while ($cmd =~ /([^ \t\n']+)|(\'([^'])\')\s*/g) { push @args, $1; } my $prog; if (substr($args[0], 0, 1) eq "@") { $prog = substr($args[0], 1); shift @args; } else { $prog = $args[0]; } my $pid = fork; if ($pid == 0) { setpgrp; # don't receive SIGINT etc. from terminal exec { $prog } @args; die "failed to exec $prog\n"; } elsif (!defined $pid) { die "failed to fork: $!\n"; } return $pid; }; sub run_wait { my ($cmd) = @_; my $pid = run $cmd; die if waitpid($pid, 0) != $pid; return $?; }; # Set the environment. FIXME: escaping. foreach my $key (keys %ENV) { next if $key eq 'LOCALE_ARCHIVE'; delete $ENV{$key}; } ${concatStrings (mapAttrsToList (n: v: '' $ENV{'${n}'} = '${v}'; '') service.environment)} # Run the ExecStartPre program. FIXME: this could be a list. my $preStart = <