on master help sign in
Add nix flake
commit694ece1937ceaa8d9a3838df035b1414ebb06692 authorConnor Brewster <cbrewster@hey.com> dateTue 6 Jul 2021, 09:50 (5 years ago) parentbaf2c24
6 files changed+202−126
.circleci/config.yml+2−7 .gitignore+1 build-prybar.nix+45−55 default.nix+6−64 flake.lock+42 flake.nix+106
.circleci/config.yml+2−7
@@ -21,13 +21,8 @@ jobs:
2121 - checkout
2222 - restore_cache:
2323 key: nix-store
24− - run:
25− # Skipping the julia and closure tests for now since they break in CI
26− name: Run nix build
27− command: |
28− mv ./tests/julia ./tests/julia_skip
29− mv ./tests/clojure ./tests/clojure_skip
30− nix-build
24+ - run: nix-env -iA nixpkgs.git
25+ - run: nix-build
3126 - save_cache:
3227 key: nix-store
3328 when: always
.gitignore+1
@@ -4,3 +4,4 @@ prybar_assets/sqlite/patch.so
44deps.lst
55prybar.tar.gz
66generated_*.go
7+result
build-prybar.nix+45−55
@@ -1,71 +1,61 @@
1−{ language, buildInputs ? [], binaries ? [], setFlags ? false, pkgName ? language, versionArg ? "" }:
1+{ language, buildInputs ? [ ], binaries ? [ ], setFlags ? false
2+, pkgName ? language }:
23
3−{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git, python3, copyPathToStore }:
4+{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git
5+, python3, copyPathToStore, rev }:
46
5−let
6− src = copyPathToStore ./.;
7− revision = runCommand "get-rev" {
8− nativeBuildInputs = [ git python3 ];
9− dummy = builtins.currentTime;
10− } ''
11− if [ -d ${src}/.git ]; then
12− cd ${src}
13− git rev-parse --short HEAD | tr -d '\n' > $out
14− else
15− echo ${versionArg} | tr -d '\n' > $out
16− fi
17− '';
18−in buildGoModule {
19− pname = "prybar-${language}";
20− version = builtins.readFile revision;
7+buildGoModule {
8+ pname = "prybar-${language}";
9+ version = rev;
2110
22− inherit src;
11+ src = ./.;
2312
24− inherit buildInputs;
25− nativeBuildInputs = [ pkg-config ];
13+ inherit buildInputs;
14+ nativeBuildInputs = [ pkg-config ];
2615
27− subPackages = [ "languages/${language}" ];
16+ subPackages = [ "languages/${language}" ];
2817
29− vendorSha256 = null;
18+ vendorSha256 = null;
3019
31− # This prebiuild hook will setup the compiler flags on demand based on the package
32− # If a language requires this, it MUST expost a ${pkgName}.pc file in its `lib/pkg-config`
33− # for pkg-config to detect it. Otherwise, we can't find the required flags.
34− preBuild = ''
35− export CGO_LDFLAGS_ALLOW="-Wl,--compress-debug-sections=zlib"
36− ${if setFlags then ''
37− export NIX_CFLAGS_COMPILE="$(pkg-config --cflags ${pkgName}) $NIX_CFLAGS_COMPILE"
38− export NIX_LDFLAGS="$(pkg-config --libs-only-L ${pkgName}) $(pkg-config --libs-only-l ${pkgName}) $NIX_LDFLAGS"
39− '' else ""}
20+ # This prebiuild hook will setup the compiler flags on demand based on the package
21+ # If a language requires this, it MUST expost a ${pkgName}.pc file in its `lib/pkg-config`
22+ # for pkg-config to detect it. Otherwise, we can't find the required flags.
23+ preBuild = ''
24+ export CGO_LDFLAGS_ALLOW="-Wl,--compress-debug-sections=zlib"
25+ ${if setFlags then ''
26+ export NIX_CFLAGS_COMPILE="$(pkg-config --cflags ${pkgName}) $NIX_CFLAGS_COMPILE"
27+ export NIX_LDFLAGS="$(pkg-config --libs-only-L ${pkgName}) $(pkg-config --libs-only-l ${pkgName}) $NIX_LDFLAGS"
28+ '' else
29+ ""}
4030
41− ${bash}/bin/bash ./scripts/inject.sh ${language}
42− go generate ./languages/${language}/main.go
43− '';
31+ ${bash}/bin/bash ./scripts/inject.sh ${language}
32+ go generate ./languages/${language}/main.go
33+ '';
4434
45− # The test file expect the binary to be in the current directory rather than bin
46− preCheck = ''
47− cp $GOPATH/bin/${language} ./prybar-${language}
48− '';
35+ # The test file expect the binary to be in the current directory rather than bin
36+ preCheck = ''
37+ cp $GOPATH/bin/${language} ./prybar-${language}
38+ '';
4939
50− # Add all the dependencies to the check. Binaries should include the language interpreter/binaries
51− # for testing the language.
52− checkInputs = [ expect ] ++ buildInputs ++ binaries;
40+ # Add all the dependencies to the check. Binaries should include the language interpreter/binaries
41+ # for testing the language.
42+ checkInputs = [ expect ] ++ buildInputs ++ binaries;
5343
54− # Run the end-to-end tests for this specific language
55− checkPhase = ''
56− runHook preCheck
44+ # Run the end-to-end tests for this specific language
45+ checkPhase = ''
46+ runHook preCheck
5747
58− "${bash}/bin/bash" "./run_tests_language" "${language}" "${expect}/bin"
48+ "${bash}/bin/bash" "./run_tests_language" "${language}" "${expect}/bin"
5949
60− runHook postCheck
61− '';
50+ runHook postCheck
51+ '';
6252
63− # Delete the test binary we copied in the preCheck
64− postCheck = ''
65− rm -f ./prybar-${language}
66− '';
53+ # Delete the test binary we copied in the preCheck
54+ postCheck = ''
55+ rm -f ./prybar-${language}
56+ '';
6757
68− postInstall = ''
69− mv $out/bin/${language} $out/bin/prybar-${language}
70− '';
58+ postInstall = ''
59+ mv $out/bin/${language} $out/bin/prybar-${language}
60+ '';
7161}
default.nix+6−64
@@ -1,64 +1,6 @@
1−{ pkgs ? import <nixpkgs>{}, versionArg ? "" } :
2−let
3− buildPrybar = attrs: pkgs.callPackage(import ./build-prybar.nix attrs) {};
4−
5− julia = import ./languages/julia/julia.nix { inherit pkgs; };
6− clojureWithCP = import ./languages/clojure/wrappedClojure.nix { inherit pkgs; };
7−in
8−{
9− prybar-R = buildPrybar {
10− language = "R";
11− buildInputs = [ pkgs.R ];
12− versionArg = versionArg;
13− pkgName = "libR";
14− setFlags = true;
15− };
16−
17− prybar-julia = buildPrybar {
18− language = "julia";
19− buildInputs = [ julia ];
20− versionArg = versionArg;
21− setFlags = true;
22− binaries = [ pkgs.zlib ];
23− };
24−
25− prybar-nodejs = buildPrybar { language = "nodejs"; binaries = [ pkgs.nodejs ]; versionArg = versionArg; };
26−
27− # The official Ruby packages is running ruby 2.7
28− prybar-ruby = buildPrybar {
29− language = "ruby";
30− buildInputs = [ pkgs.ruby ];
31− pkgName = "ruby-2.7";
32− versionArg = versionArg;
33− setFlags = true;
34− };
35−
36− prybar-python2 = buildPrybar { language = "python2"; buildInputs = [ pkgs.python2 ]; versionArg = versionArg; };
37−
38− prybar-python3 = buildPrybar { language = "python3"; buildInputs = [ pkgs.python3 ]; versionArg = versionArg; };
39−
40− prybar-lua = buildPrybar { language = "lua"; buildInputs = [ pkgs.lua5_1 pkgs.readline ]; versionArg = versionArg; };
41−
42− prybar-clojure = buildPrybar {
43− language = "clojure";
44− buildInputs = [ clojureWithCP ];
45− binaries = [ pkgs.jdk11_headless ];
46− versionArg = versionArg;
47− };
48−
49− prybar-elisp = buildPrybar { language = "elisp"; versionArg = versionArg; };
50−
51− prybar-ocaml = buildPrybar {
52− language = "ocaml";
53− # This has to be in the build inputs so it set-ups the library paths before the check phase
54− # It will not be copied over to the final package.
55− buildInputs = [ pkgs.opam pkgs.ocaml pkgs.ocamlPackages.findlib pkgs.ocamlPackages.topkg pkgs.ocamlPackages.reason ];
56− versionArg = versionArg;
57− };
58−
59− prybar-scala = buildPrybar { language = "scala"; versionArg = versionArg; };
60−
61− prybar-sqlite = buildPrybar { language = "sqlite"; binaries = [ pkgs.sqlite ]; versionArg = versionArg; };
62−
63− prybar-tcl = buildPrybar { language = "tcl"; buildInputs = [ pkgs.tcl ]; versionArg = versionArg; };
64−}
1+# flake-compat makes Nix flakes compatible with the old Nix cli commands, like nix-build and nix-shell.
2+(import (fetchTarball {
3+ url =
4+ "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
5+ sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
6+}) { src = ./.; }).defaultNix
flake.locknew file+42
@@ -0,0 +1,42 @@
1+{
2+ "nodes": {
3+ "flake-utils": {
4+ "locked": {
5+ "lastModified": 1623875721,
6+ "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=",
7+ "owner": "numtide",
8+ "repo": "flake-utils",
9+ "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772",
10+ "type": "github"
11+ },
12+ "original": {
13+ "owner": "numtide",
14+ "repo": "flake-utils",
15+ "type": "github"
16+ }
17+ },
18+ "nixpkgs": {
19+ "locked": {
20+ "lastModified": 1625586387,
21+ "narHash": "sha256-E6bgeBk8FXGXYUsYtSMVfKBlwUBBFklkWX/7xxgJTnU=",
22+ "owner": "nixos",
23+ "repo": "nixpkgs",
24+ "rev": "b30e41473deeb5f73fc28e2421da509d818d050b",
25+ "type": "github"
26+ },
27+ "original": {
28+ "owner": "nixos",
29+ "repo": "nixpkgs",
30+ "type": "github"
31+ }
32+ },
33+ "root": {
34+ "inputs": {
35+ "flake-utils": "flake-utils",
36+ "nixpkgs": "nixpkgs"
37+ }
38+ }
39+ },
40+ "root": "root",
41+ "version": 7
42+}
flake.nixnew file+106
@@ -0,0 +1,106 @@
1+{
2+ description = "A universal interpreter front-end";
3+
4+ inputs = {
5+ nixpkgs.url = "github:nixos/nixpkgs";
6+ flake-utils.url = "github:numtide/flake-utils";
7+ };
8+
9+ outputs = { self, nixpkgs, flake-utils }:
10+ flake-utils.lib.eachDefaultSystem (system:
11+ let
12+ pkgs = nixpkgs.legacyPackages.${system};
13+
14+ rev = if self ? rev then
15+ "0.0.0-${builtins.substring 0 7 self.rev}"
16+ else
17+ "0.0.0-dirty";
18+
19+ buildPrybar = attrs:
20+ pkgs.callPackage (import ./build-prybar.nix attrs) { inherit rev; };
21+
22+ julia = import ./languages/julia/julia.nix { inherit pkgs; };
23+
24+ clojureWithCP =
25+ import ./languages/clojure/wrappedClojure.nix { inherit pkgs; };
26+
27+ in {
28+ packages = {
29+ prybar-R = buildPrybar {
30+ language = "R";
31+ buildInputs = [ pkgs.R ];
32+ pkgName = "libR";
33+ setFlags = true;
34+ };
35+
36+ prybar-julia = buildPrybar {
37+ language = "julia";
38+ buildInputs = [ julia ];
39+ setFlags = true;
40+ binaries = [ pkgs.zlib ];
41+ };
42+
43+ prybar-nodejs = buildPrybar {
44+ language = "nodejs";
45+ binaries = [ pkgs.nodejs ];
46+ };
47+
48+ # The official Ruby packages is running ruby 2.7
49+ prybar-ruby = buildPrybar {
50+ language = "ruby";
51+ buildInputs = [ pkgs.ruby ];
52+ pkgName = "ruby-2.7";
53+ setFlags = true;
54+ };
55+
56+ prybar-python2 = buildPrybar {
57+ language = "python2";
58+ buildInputs = [ pkgs.python2 ];
59+ };
60+
61+ prybar-python3 = buildPrybar {
62+ language = "python3";
63+ buildInputs = [ pkgs.python3 ];
64+ };
65+
66+ prybar-lua = buildPrybar {
67+ language = "lua";
68+ buildInputs = [ pkgs.lua5_1 pkgs.readline ];
69+ };
70+
71+ prybar-clojure = buildPrybar {
72+ language = "clojure";
73+ buildInputs = [ clojureWithCP ];
74+ binaries = [ pkgs.jdk11_headless ];
75+ };
76+
77+ prybar-elisp = buildPrybar { language = "elisp"; };
78+
79+ prybar-ocaml = buildPrybar {
80+ language = "ocaml";
81+ # This has to be in the build inputs so it set-ups the library paths before the check phase
82+ # It will not be copied over to the final package.
83+ buildInputs = [
84+ pkgs.opam
85+ pkgs.ocaml
86+ pkgs.ocamlPackages.findlib
87+ pkgs.ocamlPackages.topkg
88+ pkgs.ocamlPackages.reason
89+ ];
90+ };
91+
92+ prybar-scala = buildPrybar { language = "scala"; };
93+
94+ prybar-sqlite = buildPrybar {
95+ language = "sqlite";
96+ binaries = [ pkgs.sqlite ];
97+ };
98+
99+ prybar-tcl = buildPrybar {
100+ language = "tcl";
101+ buildInputs = [ pkgs.tcl ];
102+ };
103+ };
104+ });
105+}
106+