diff options
| -rw-r--r-- | default.nix | 5 | ||||
| -rw-r--r-- | nix/overlay/default.nix | 13 | ||||
| -rw-r--r-- | nix/overlay/development.nix | 15 | ||||
| -rw-r--r-- | nix/package/dev-shell.nix | 32 | ||||
| -rw-r--r-- | nix/package/nixfmt-3-space.nix | 30 | ||||
| -rw-r--r-- | nix/package/nixtamal.nix | 95 | ||||
| -rw-r--r-- | nix/package/ocamlformat-rpc-bin.nix | 16 | ||||
| -rw-r--r-- | release.nix | 24 | ||||
| -rw-r--r-- | shell.nix | 5 |
9 files changed, 235 insertions, 0 deletions
diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..400c972 --- /dev/null +++ b/default.nix @@ -0,0 +1,5 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +(import ./release.nix).default diff --git a/nix/overlay/default.nix b/nix/overlay/default.nix new file mode 100644 index 0000000..da6c5a1 --- /dev/null +++ b/nix/overlay/default.nix @@ -0,0 +1,13 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +final: prev: { + nixtamal = final.lib.makeScope final.newScope (self: { + nixtamal = self.callPackage ../package/nixtamal.nix { }; + + default = self.nixtamal; + + __functor = _: self.nixtamal; + }); +} diff --git a/nix/overlay/development.nix b/nix/overlay/development.nix new file mode 100644 index 0000000..b414597 --- /dev/null +++ b/nix/overlay/development.nix @@ -0,0 +1,15 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +final: prev: { + nixtamal = prev.nixtamal.overrideScope ( + final': prev': { + dev-shell = final'.callPackage ../package/dev-shell.nix { }; + + nixfmt-3-space = final'.callPackage ../package/nixfmt-3-space.nix { }; + + ocamlformat-rpc-bin = final'.callPackage ../package/ocamlformat-rpc-bin.nix { }; + } + ); +} diff --git a/nix/package/dev-shell.nix b/nix/package/dev-shell.nix new file mode 100644 index 0000000..4ace75c --- /dev/null +++ b/nix/package/dev-shell.nix @@ -0,0 +1,32 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +{ + mkShell, + kdlfmt, + topiary, + ocamlPackages, + nixtamal, + nixfmt-3-space, + ocamlformat-rpc-bin, +}: + +mkShell { + name = "nixtamal"; + inputsFrom = [ + nixtamal + ]; + packages = [ + kdlfmt + nixfmt-3-space + topiary + + ocamlPackages.alcotest + ocamlPackages.ocaml-lsp + ocamlformat-rpc-bin # 💢 why does the LSP depend on ocamlformat‽ + ]; + env = { + TOPIARY_CONFIG_FILE = "${../../.topiary.ncl}"; + }; +} diff --git a/nix/package/nixfmt-3-space.nix b/nix/package/nixfmt-3-space.nix new file mode 100644 index 0000000..fe2b003 --- /dev/null +++ b/nix/package/nixfmt-3-space.nix @@ -0,0 +1,30 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +# I don’t like *this* formatter, but it is *a* formatter. Tweaking it to expand +# to 3 spaces, helps the maker actually read the code since 2 spaces is not +# enough contrast (& Nix magic strings don’t support tabs). +{ + lib, + writeTextFile, + dash, + nixfmt-rfc-style, + stdenvNoCC, +}: + +writeTextFile { + name = "nixfmt-3-space"; + executable = true; + destination = "/bin/nixfmt"; + text = /* sh */ '' + #!${lib.getExe dash} + exec ${lib.getExe nixfmt-rfc-style} --indent=3 "$@" + ''; + checkPhase = '' + runHook preCheck + ${stdenvNoCC.shellDryRun} "$target" + runHook postCheck + ''; + meta.mainProgram = "nixfmt"; +} diff --git a/nix/package/nixtamal.nix b/nix/package/nixtamal.nix new file mode 100644 index 0000000..40806e2 --- /dev/null +++ b/nix/package/nixtamal.nix @@ -0,0 +1,95 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +{ + lib, + coreutils, + python3Packages, + nix-prefetch-darcs, + nix-prefetch-git, + nix-prefetch-pijul, + ocamlPackages, +}: + +ocamlPackages.buildDunePackage { + pname = "nixtamal"; + version = "0.0.1-alpha.1"; + + src = + let + fs = lib.fileset; + + ocaml_project = + file: + lib.lists.elem file.name [ + "dune" + "dune-project" + "dune-workspace" + ] + || file.hasExt "opam"; + + ocaml_src = + file: + lib.lists.any file.hasExt [ + "ml" + "mld" + "mli" + "mly" + ]; + in + fs.toSource { + root = ../..; + fileset = fs.unions [ + ../../LICENSE.txt + (fs.fileFilter (file: file.hasExt "txt") ../../license) + (fs.fileFilter ocaml_project ../..) + (fs.fileFilter ocaml_src ../../bin) + (fs.fileFilter ocaml_src ../../lib) + (fs.fileFilter ocaml_src ../../test) + ]; + }; + + nativeBuildInputs = [ + python3Packages.docutils + # NOTE: no KDL support + python3Packages.pygments + ]; + + buildInputs = [ + # required since the prefetcher scripts presently don’t specify all of + # their inputs + coreutils + nix-prefetch-darcs + nix-prefetch-git + nix-prefetch-pijul + ] + ++ (with ocamlPackages; [ + cmdliner + eio + eio_main + fmt + jingoo + (jsont.override { + withBrr = false; + withBytesrw = true; + }) + kdl + logs + ppx_deriving + saturn + uri + ]); + + doCheck = false; # TODO + + checkInputs = with ocamlPackages; [ + alcotest + ]; + + meta = { + license = with lib.licenses; [ gpl3Plus ]; + platforms = lib.platforms.unix; + mainProgram = "nixtamal"; + }; +} diff --git a/nix/package/ocamlformat-rpc-bin.nix b/nix/package/ocamlformat-rpc-bin.nix new file mode 100644 index 0000000..935c314 --- /dev/null +++ b/nix/package/ocamlformat-rpc-bin.nix @@ -0,0 +1,16 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +# I don’t like ocamlformat as it doesn’t have tab support despite OCaml fully +# supporting tabs — so I use Topiary. However, the OCaml LSP requires +{ + lib, + runCommand, + ocamlformat, +}: + +runCommand "extract-ocamlformat-rpc-bin" { } '' + mkdir -p $out/bin + cp ${lib.getBin ocamlformat}/bin/ocamlformat-rpc $out/bin/ +'' diff --git a/release.nix b/release.nix new file mode 100644 index 0000000..23e2c6c --- /dev/null +++ b/release.nix @@ -0,0 +1,24 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +let + pkgs_src = builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/bd88d6c13ab85cc842b93d53f68d6d40412e5a18.tar.gz"; + sha256 = "0nxk7d12y1zq7rbfjkspprbh2wac61cjsjaidc94gpv9bd0pbsja"; + }; + + pkgs = import pkgs_src { + overlays = [ + (import ./nix/overlay/default.nix) + (import ./nix/overlay/development.nix) + ]; + }; +in +{ + inherit (pkgs) nixtamal; + + inherit (pkgs.nixtamal) default; + + shell = pkgs.nixtamal-dev-shell; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..41ce045 --- /dev/null +++ b/shell.nix @@ -0,0 +1,5 @@ +#──────────────────────────────────────────────────────────────────────────────┐ +# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │ +# SPDX-License-Identifier: LGPL-2.1-or-later │ +#──────────────────────────────────────────────────────────────────────────────┘ +(import ./release.nix).shell |
