aboutsummaryrefslogtreecommitdiff
path: root/pkgs/nix-serve/default.nix
blob: e5188f09b8abfcc36c2340bd11af5c6e49cbe443 (plain)
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
{ stdenv, coreutils, pxz, nix, perl, perlPackages }:

let
  inherit (stdenv.lib)
    makeBinPath
    ;

in stdenv.mkDerivation {
  name = "nix-serve";

  src = "${./nix-serve.psgi}";

  buildInputs = [ perl nix.perl-bindings ]
    ++ (with perlPackages; [ DBI DBDSQLite Plack Starman ]);

  phases = [ "installPhase" ];

  installPhase = ''
    mkdir -p $out/libexec/nix-serve
    perl -c "$src"
    cat "$src" > "$out/libexec/nix-serve.psgi"

    mkdir -p $out/bin
    cat > $out/bin/nix-serve <<EOF
    #! ${stdenv.shell}
    export PATH=${makeBinPath [ coreutils pxz nix ]}:\$PATH
    export PERL5LIB=$PERL5LIB
    exec ${perlPackages.Starman}/bin/starman "$out/libexec/nix-serve.psgi" "\$@"
    EOF
    chmod +x $out/bin/nix-serve
  '';
}