initial commit
This commit is contained in:
commit
8a53607ed9
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*.~undo-tree~
|
27
example/example.nix
Normal file
27
example/example.nix
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
import ../psDeriver.nix {
|
||||||
|
inherit pkgs;
|
||||||
|
deps = [
|
||||||
|
{
|
||||||
|
name = "console";
|
||||||
|
version = "v6.0.0";
|
||||||
|
gitUrl = https://github.com/purescript/purescript-console.git;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "effect";
|
||||||
|
version = "v4.0.0";
|
||||||
|
gitUrl = https://github.com/purescript/purescript-effect.git;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "prelude";
|
||||||
|
version = "v6.0.1";
|
||||||
|
gitUrl = https://github.com/purescript/purescript-prelude.git;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
out = {
|
||||||
|
name = "example";
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ./src;
|
||||||
|
executable = "example";
|
||||||
|
};
|
||||||
|
}
|
7
example/shell.nix
Normal file
7
example/shell.nix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
let pkgs = import <nixpkgs> {};
|
||||||
|
example = import ./example.nix { inherit pkgs; };
|
||||||
|
in pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
example
|
||||||
|
];
|
||||||
|
}
|
10
example/src/Main.purs
Normal file
10
example/src/Main.purs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Effect (Effect)
|
||||||
|
import Effect.Console (log)
|
||||||
|
|
||||||
|
main :: Effect Unit
|
||||||
|
main = do
|
||||||
|
log "Hej!"
|
75
psDeriver.nix
Normal file
75
psDeriver.nix
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
# pkgs: nixpkgs
|
||||||
|
#
|
||||||
|
# nodejs?: node derivation to use for running executables
|
||||||
|
#
|
||||||
|
# deps:
|
||||||
|
# {
|
||||||
|
# name
|
||||||
|
# version
|
||||||
|
# src
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# or
|
||||||
|
#
|
||||||
|
# {
|
||||||
|
# name
|
||||||
|
# version
|
||||||
|
# gitUrl
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# out:
|
||||||
|
#
|
||||||
|
# {
|
||||||
|
# name
|
||||||
|
# version
|
||||||
|
# src
|
||||||
|
# executable?
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
{ pkgs
|
||||||
|
, nodejs ? pkgs.nodejs
|
||||||
|
, deps
|
||||||
|
, out }:
|
||||||
|
with pkgs; with builtins;
|
||||||
|
let inputs =
|
||||||
|
map (d: stdenv.mkDerivation {
|
||||||
|
name = d.name;
|
||||||
|
version = d.version;
|
||||||
|
src = d.src or fetchGit {
|
||||||
|
url = d.gitUrl;
|
||||||
|
ref = "refs/tags/${d.version}";
|
||||||
|
};
|
||||||
|
installPhase = ''cp -r "$src" "$out"'';
|
||||||
|
})
|
||||||
|
deps;
|
||||||
|
in stdenv.mkDerivation {
|
||||||
|
pname = out.name;
|
||||||
|
version = out.version;
|
||||||
|
src = out.src;
|
||||||
|
|
||||||
|
buildInputs = [ purescript ] ++ inputs;
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
purs compile "$src/**/*.purs" ${concatStringsSep " "
|
||||||
|
(map (x: ''"${x}/src/**/*.purs"'') inputs)}
|
||||||
|
'' + (if hasAttr "executable" out then ''
|
||||||
|
cat > output/runMain.js <<-EOF
|
||||||
|
import * as Main from "$out/lib/Main/index.js"
|
||||||
|
Main.main()
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > ${out.executable} <<-EOF
|
||||||
|
#!/bin/sh
|
||||||
|
exec ${nodejs}/bin/node "$out/lib/runMain.js" "$@"
|
||||||
|
EOF
|
||||||
|
'' else "");
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p "$out/lib"
|
||||||
|
mv output/* "$out/lib"
|
||||||
|
'' + (if hasAttr "executable" out then ''
|
||||||
|
mkdir -p "$out/bin"
|
||||||
|
install -Dm 755 ${out.executable} "$out/bin"
|
||||||
|
'' else "");
|
||||||
|
}
|
32
readme.md
Normal file
32
readme.md
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# psDeriver
|
||||||
|
|
||||||
|
`psDeriver` is a file which lets one define postscript derivations simply. It handles specified dependencies (no dependency tree resolution), and can optionally generate an executable which runs the main function if present.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
See `example/example.nix` for an example.
|
||||||
|
|
||||||
|
Import `psDeriver.nix` and pass the following arguments:
|
||||||
|
|
||||||
|
### `pkgs`
|
||||||
|
The usual nixpkgs
|
||||||
|
|
||||||
|
### `nodejs` (optional)
|
||||||
|
Nodejs derivation to use for running executables. If not specified then `pkgs.nodejs` will be used.
|
||||||
|
|
||||||
|
### `deps`
|
||||||
|
A list of dependencies in one of the following formats:
|
||||||
|
|
||||||
|
* `{ name; version; src; }`
|
||||||
|
|
||||||
|
* `{ name; version; gitUrl; }`
|
||||||
|
|
||||||
|
If the second format is used then version will be used as a tag of the git repository. This is the style demonstrated in `example/example.nix`.
|
||||||
|
|
||||||
|
### `out`
|
||||||
|
Information about the output derivation, given in the following attributes.
|
||||||
|
|
||||||
|
* `name` - name of package
|
||||||
|
* `version` - version of package
|
||||||
|
* `src` - source directory for purescript code (usually `./src`)
|
||||||
|
* `executable` (optional) - if specified an executable with this name will be created which calls `Main.main`.
|
Loading…
Reference in New Issue
Block a user