Skip to content

Commit 6c9c6a6

Browse files
authored
Update nix packaging (#950)
1 parent e7156f4 commit 6c9c6a6

File tree

6 files changed

+223
-96
lines changed

6 files changed

+223
-96
lines changed

Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,34 @@ bootstrap: $(if $(wildcard build/$(BOOT_NAME)),,boot)
7878
cheat:
7979
$(SET_STDLIB) $(SET_OCAMLPATH) mi compile src/main/mi.mc --output build/$(MI_CHEAT_NAME)
8080

81+
# Umbrella install/uninstall targets, for installing and uninstalling everything
82+
83+
.PHONY: install
84+
install: $(if $(wildcard build/$(MI_NAME)),,bootstrap) install-boot install-stdlib install-mi
85+
86+
.PHONY: uninstall
87+
uninstall: uninstall-boot uninstall-stdlib uninstall-mi
8188

8289
# Installing and uninstalling `mi` and the standard library
8390

84-
.PHONY: install
85-
install: $(if $(wildcard build/$(MI_NAME)),,bootstrap) install-boot
86-
mkdir -p $(bindir) $(mcoredir)
91+
.PHONY: install-mi
92+
install-mi:
93+
mkdir -p $(bindir)
8794
cp -f build/$(MI_NAME) $(bindir)
95+
96+
.PHONY: install-stdlib
97+
install-stdlib:
98+
mkdir -p $(mcoredir)
8899
rm -rf $(mcoredir)/stdlib || true
89100
cp -rf src/stdlib $(mcoredir)
90101

91-
.PHONY: uninstall
92-
uninstall:
93-
rm -f $(bindir)/$(MI_NAME)
102+
.PHONY: uninstall-stdlib
103+
uninstall-stdlib:
94104
rm -rf $(mcoredir)/stdlib
95105

106+
.PHONY: uninstall-mi
107+
uninstall-mi:
108+
rm -f $(bindir)/$(MI_NAME)
96109

97110
# Basic testing (for more granular control, use `misc/test` directly,
98111
# or `misc/watch` to autorun tests when files change)

misc/packaging/flake.lock

Lines changed: 37 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/packaging/flake.nix

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
{
22
inputs = {
33
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
4+
flake-utils.url = "github:numtide/flake-utils";
45
};
56

6-
outputs = { self, nixpkgs }:
7+
outputs = { self, nixpkgs, flake-utils }:
78
let
8-
pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs;
9-
miking = pkgs.callPackage ./miking.nix {};
10-
shell = pkgs.mkShell {
11-
name = "Miking dev shell";
12-
inputsFrom = [ miking ];
13-
buildInputs = [
14-
pkgs.tup
15-
pkgs.ocamlformat
16-
];
9+
mkPkg = system:
10+
let pkgs = nixpkgs.legacyPackages.${system}.pkgs; in
11+
rec {
12+
packages.miking-lib = pkgs.callPackage ./miking-lib.nix {};
13+
packages.miking-unwrapped = pkgs.callPackage ./miking-unwrapped.nix {
14+
inherit (packages) miking-lib;
15+
};
16+
packages.miking = pkgs.callPackage ./miking.nix {
17+
inherit (packages) miking-lib miking-unwrapped;
18+
};
19+
packages.default = packages.miking;
20+
devShells.default = pkgs.mkShell {
21+
name = "Miking dev shell";
22+
inputsFrom = [ packages.miking-lib packages.miking-unwrapped ];
23+
buildInputs = [ pkgs.tup pkgs.ocamlformat ];
24+
};
25+
};
26+
in
27+
flake-utils.lib.eachDefaultSystem mkPkg // rec {
28+
overlays.miking = final: prev: {
29+
miking = final.callPackage ./miking.nix {};
30+
miking-lib = final.callPackage ./miking-lib.nix {};
31+
miking-unwrapped = final.callPackage ./miking-unwrapped.nix {};
32+
};
33+
overlays.default = overlays.miking;
1734
};
18-
in {
19-
packages.x86_64-linux.default = miking;
20-
devShells.x86_64-linux.default = shell;
21-
};
2235
}

misc/packaging/miking-lib.nix

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{ lib, stdenv, nix-gitignore, writeText,
2+
ocamlPackages,
3+
}:
4+
5+
with ocamlPackages;
6+
7+
stdenv.mkDerivation (finalAttrs: {
8+
pname = "miking-lib";
9+
version = "0.0.0+git";
10+
11+
src = nix-gitignore.gitignoreSource [] ../..;
12+
13+
nativeBuildInputs = [
14+
dune_3
15+
ocaml
16+
linenoise
17+
findlib
18+
menhir
19+
];
20+
21+
makeFlags = [ "prefix=$(out)" "ocamllibdir=$(out)/lib/ocaml/${ocaml.version}/site-lib" ];
22+
23+
buildFlags = [ "boot" ];
24+
25+
installTargets = "install-boot install-stdlib";
26+
27+
preConfigure = ''
28+
for f in $(find misc -type f -a -executable); do patchShebangs --build $f; done
29+
'';
30+
31+
setupHook = writeText "setupHook.sh" ''
32+
addMCorePath() {
33+
echo test $1
34+
for dir in "''$1"/lib/mcore/*; do
35+
export MCORE_LIBS="''${MCORE_LIBS-}''${MCORE_LIBS:+:}''$(basename ''$dir)=''$dir"
36+
done
37+
}
38+
addEnvHooks "$targetOffset" addMCorePath
39+
'';
40+
41+
meta = with lib; {
42+
description = "Meta language system for creating embedded DSLs, standard library";
43+
homepage = "https://miking.org";
44+
license = licenses.mit;
45+
longDescription = ''
46+
The supporting libraries needed to run the Miking compiler.
47+
'';
48+
};
49+
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{ lib, stdenv, nix-gitignore,
2+
ocamlPackages, miking-lib,
3+
}:
4+
5+
with ocamlPackages;
6+
7+
stdenv.mkDerivation (finalAttrs: {
8+
pname = "miking";
9+
version = "0.0.0+git";
10+
11+
src = nix-gitignore.gitignoreSource "/misc/packaging\n/result\n" ../..;
12+
13+
nativeBuildInputs = [
14+
miking-lib
15+
dune_3
16+
ocaml
17+
linenoise
18+
findlib
19+
menhir
20+
];
21+
22+
makeFlags = [
23+
"prefix=$(out)"
24+
# NOTE(vipa, 2025-06-09): We want to make it possible to supply a
25+
# different library, thus we stop the Makefile's attempts to use a
26+
# local stdlib and ocamlpath
27+
"SET_STDLIB="
28+
"SET_OCAMLPATH="
29+
];
30+
31+
buildFlags = [ "bootstrap" ];
32+
33+
installTargets = [ "install-mi" ];
34+
35+
preConfigure = ''
36+
for f in $(find misc -type f -a -executable); do patchShebangs --build $f; done
37+
'';
38+
39+
meta = with lib; {
40+
mainProgram = "mi";
41+
description = "Meta language system for creating embedded DSLs";
42+
homepage = "https://miking.org";
43+
license = licenses.mit;
44+
longDescription = ''
45+
Miking (Meta vIKING) is a meta language system for creating
46+
embedded domain-specific and general-purpose languages. The
47+
system features a polymorphic core calculus and a DSL definition
48+
language where languages can be extended and composed from
49+
smaller fragments.
50+
51+
Note: Depending on the target runtime, miking requires the presence of
52+
additional packages within an environment, such as dune, ocaml, findlib
53+
and a C compiler for native builds, node for javascript, and a suitable JDK
54+
when targeting the JVM.
55+
'';
56+
};
57+
})

misc/packaging/miking.nix

Lines changed: 34 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,43 @@
1-
{ lib, stdenv,
1+
{ lib, runCommand, stdenv,
22
coreutils,
33
makeWrapper,
44
ocamlPackages,
5-
writeText
5+
writeText,
6+
miking-lib, miking-unwrapped,
67
}:
78

89
with ocamlPackages;
910

10-
stdenv.mkDerivation (finalAttrs: rec {
11-
pname = "miking";
12-
version = "0.0.0+git";
13-
14-
withLwt = true; # For async-ext.mc
15-
withToml = true; # For dist-ext.mc
16-
withOwl = true; # For toml-ext.mc
17-
18-
src = ../..;
19-
20-
nativeBuildInputs = [
21-
makeWrapper
22-
menhir
23-
dune_3
24-
coreutils
25-
ocaml
26-
findlib
27-
linenoise
28-
]
29-
++ lib.lists.optional finalAttrs.withLwt lwt
30-
++ lib.lists.optional finalAttrs.withOwl owl
31-
++ lib.lists.optional finalAttrs.withToml toml;
32-
33-
propagatedBuildInputs = [
34-
coreutils # Miking currently requires mkdir to be able to run
35-
ocaml
36-
findlib
37-
linenoise
38-
];
39-
40-
makeFlags = [ "prefix=$(out)" "ocamllibdir=$(out)/lib/ocaml/${ocaml.version}/site-lib" ];
41-
42-
preConfigure = ''
43-
for f in $(find misc -type f -a -executable); do patchShebangs --build $f; done
44-
'';
45-
46-
postInstall = ''
47-
wrapProgram $out/bin/mi \
48-
--suffix PATH : ${coreutils}/bin \
49-
--prefix PATH : ${ocaml}/bin \
50-
'';
51-
52-
# doCheck = true;
53-
# checkTarget = "test-compile";
54-
55-
setupHook = writeText "setupHook.sh" ''
56-
addMCorePath() {
57-
echo test $1
58-
for dir in "''$1"/lib/mcore/*; do
59-
export MCORE_LIBS="''${MCORE_LIBS-}''${MCORE_LIBS:+:}''$(basename ''$dir)=''$dir"
60-
done
61-
}
62-
addEnvHooks "$targetOffset" addMCorePath
63-
'';
11+
let
12+
args = {
13+
nativeBuildInputs = [ makeWrapper ];
14+
15+
meta = with lib; {
16+
mainProgram = "mi";
17+
description = "Meta language system for creating embedded DSLs";
18+
homepage = "https://miking.org";
19+
license = licenses.mit;
20+
longDescription = ''
21+
Miking (Meta vIKING) is a meta language system for creating
22+
embedded domain-specific and general-purpose languages. The
23+
system features a polymorphic core calculus and a DSL definition
24+
language where languages can be extended and composed from
25+
smaller fragments.
26+
27+
Note: Depending on the target runtime, miking requires the presence of
28+
additional packages within an environment, such as dune, ocaml, findlib
29+
and a C compiler for native builds, node for javascript, and a suitable JDK
30+
when targeting the JVM.
31+
'';
32+
};
33+
};
34+
in
6435

65-
meta = with lib; {
66-
description = "Meta language system for creating embedded DSLs";
67-
homepage = "https://miking.org";
68-
license = licenses.mit;
69-
longDescription = ''
70-
Miking (Meta vIKING) is a meta language system for creating
71-
embedded domain-specific and general-purpose languages. The
72-
system features a polymorphic core calculus and a DSL definition
73-
language where languages can be extended and composed from
74-
smaller fragments.
36+
runCommand "miking" args ''
37+
mkdir -p $out/bin
38+
makeWrapper ${miking-unwrapped}/bin/mi $out/bin/mi \
39+
--prefix-each PATH : "${coreutils}/bin ${ocaml}/bin ${findlib}/bin ${stdenv.cc}/bin" \
40+
--prefix-each OCAMLPATH : "${miking-lib}/lib/ocaml/${ocaml.version}/site-lib ${linenoise}/lib/ocaml/${ocaml.version}/site-lib" \
41+
--prefix MCORE_LIBS : stdlib=${miking-lib}/lib/mcore/stdlib \
7542
76-
Note: Depending on the target runtime, miking requires the presence of
77-
additional packages within an environment, such as dune, ocaml, findlib
78-
and a C compiler for native builds, node for javascript, and a suitable JDK
79-
when targeting the JVM.
80-
'';
81-
};
82-
})
43+
''

0 commit comments

Comments
 (0)