commit 39883879598746875b629db062a5597f1079fcd1 Author: KierĂ¡n Meinhardt Date: Sun Feb 15 11:26:50 2026 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b339ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +gf-book-examples +book.pdf +.direnv/ +.envrc diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5cbdc72 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1659446231, + "narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "eabc38219184cc3e04a974fe31857d8e0eac098d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..47dd8c8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,86 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-21.11"; + }; + + outputs = + { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + + gf-rgl = pkgs.callPackage ./gf-rgl.nix { }; + + vim-gf = pkgs.vimUtils.buildVimPlugin { + name = "vim-gf"; + src = pkgs.fetchFromGitHub { + owner = "gdetrez"; + repo = "vim-gf"; + rev = "60924ef93a0ec69dc716982646bc907dfb37de6d"; + hash = "sha256-Y1xDsefjusJFJCQu6fX6x/QEECjRuVBC4l6kASJwUgU="; + }; + }; + + gf-book-examples = pkgs.fetchzip { + url = "https://www.grammaticalframework.org/gf-book/gf-book-examples.tgz"; + hash = "sha256-tiOJ2Pep+1WkhD6rSbDfvPIZf1pty9h1lNvGGe3vAX8="; + }; + + gf-book = pkgs.fetchurl { + url = "https://listenmaa.fi/b/Aarne_Ranta-GF-book.pdf"; + hash = "sha256-GeoyJKYcC8MtPFXBdQhEOwAjwH+tWbG/T66KNZO67Og="; + }; + + neovim-for-gf = pkgs.neovim.override { + configure = { + packages.myPlugins = { + start = [ + vim-gf + pkgs.vimPlugins.vim-nix + ]; + }; + customRC = '' + set nocompatible + set expandtab shiftwidth=2 tabstop=2 + set number + + syntax on + filetype plugin indent on + + colorscheme delek + + set fileformat=unix + autocmd BufWritePre * if &ft != 'markdown' | %s/\s\+$//e | endif + set fixendofline + ''; + }; + }; + in + { + packages.${system} = { + gf = pkgs.haskellPackages.gf; + inherit gf-rgl gf-book gf-book-examples neovim-for-gf; + }; + + devShells.${system}.default = pkgs.mkShell { + buildInputs = [ + pkgs.haskellPackages.gf + gf-rgl + neovim-for-gf + (pkgs.writeShellScriptBin "gf-book" '' + ${pkgs.zathura}/bin/zathura ${gf-book} + '') + ]; + + shellHook = '' + alias vim='nvim' + + mkdir -p gf-book-examples + cp -rn ${gf-book-examples}/. gf-book-examples/ + chmod -R u+w gf-book-examples/ + ''; + }; + }; +} diff --git a/gf-rgl.nix b/gf-rgl.nix new file mode 100644 index 0000000..de97a89 --- /dev/null +++ b/gf-rgl.nix @@ -0,0 +1,130 @@ +{ + lib, + stdenv, + fetchFromGitHub, + haskellPackages, + ghc, + makeWrapper, + glibcLocales, + # Optional: build only specific languages (comma-separated, e.g., "Eng,Swe,Ger") + languages ? null, + # Optional: build mode - "present", "alltenses", or "both" + mode ? "both", +}: + +let + # Build the language flag if languages are specified + langFlag = if languages != null then "--langs=${languages}" else ""; + + # Build the mode flags + modeFlags = + if mode == "present" then + "present" + else if mode == "alltenses" then + "alltenses" + else + ""; # both is default +in + +stdenv.mkDerivation rec { + pname = "gf-rgl"; + version = "20250812"; + + src = fetchFromGitHub { + owner = "GrammaticalFramework"; + repo = "gf-rgl"; + rev = version; + hash = "sha256-rqN5MV/XxChXC+Vs4aLIhRtyPQZNk0LQZ2TCdbd6wUw="; + }; + + nativeBuildInputs = [ + haskellPackages.gf + ghc + makeWrapper + glibcLocales + ]; + + # Disable parallel building as the GF build process isn't parallel-safe + enableParallelBuilding = false; + + configurePhase = '' + runHook preConfigure + + export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive + export LANG=C.UTF-8 + export LC_ALL=C.UTF-8 + + # The RGL uses Setup.hs to build + # We need to point it to the gf executable + export GF=${haskellPackages.gf}/bin/gf + + # Make sure GF can find its own libraries + export GF_LIB_PATH=${haskellPackages.gf}/share/gf + + echo "Using GF: $GF" + echo "GF version: $($GF --version || echo 'unknown')" + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + # Build using the Haskell setup script + # This compiles all the GF grammar files + echo "Building GF-RGL with options: ${modeFlags} ${langFlag}" + + runghc Setup.hs build ${modeFlags} ${langFlag} --gf=${haskellPackages.gf}/bin/gf --verbose + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + # Install to the output directory + mkdir -p $out/share/gf + + # Copy the compiled files + echo "Installing to $out/share/gf" + runghc Setup.hs copy ${modeFlags} --dest=$out/share/gf + + # Create a setup hook so other derivations can find this + mkdir -p $out/nix-support + cat > $out/nix-support/setup-hook << EOF + export GF_LIB_PATH="\''${GF_LIB_PATH:+\''${GF_LIB_PATH}:}$out/share/gf" + EOF + + runHook postInstall + ''; + + # The RGL is architecture-independent (it's just compiled grammar files) + # but we keep it architecture-specific for now to be safe + # preferLocalBuild = true; + + meta = with lib; { + description = "Grammatical Framework's Resource Grammar Library (RGL)"; + longDescription = '' + The GF Resource Grammar Library is the standard library for Grammatical + Framework. It covers the morphology and basic syntax of over 30 languages. + + This package includes compiled grammar modules (.gfo files) that can be + imported and used in GF applications. + + Supported languages include: English, Swedish, German, French, Spanish, + Italian, Dutch, Finnish, Russian, Bulgarian, Catalan, Danish, Norwegian, + Polish, Romanian, Afrikaans, Amharic, Arabic, Basque, Chinese, Estonian, + Greek, Hebrew, Hindi, Japanese, Korean, Latvian, Maltese, Mongolian, + Nepali, Persian, Punjabi, Sindhi, Somali, Thai, Turkish, Urdu, and more. + ''; + homepage = "https://www.grammaticalframework.org/"; + license = with licenses; [ + lgpl3Plus + bsd3 + ]; + maintainers = with maintainers; [ ]; + platforms = platforms.unix; + # Note: This may take a while to build (30+ minutes for all languages) + # Consider using binary caches or building with specific languages only + }; +}