commit 5f14fab320af6f49c3afd126f4541dd0e42e360b Author: Nettika Date: Sat Feb 14 01:42:45 2026 -0800 Create a from-source Nix package for oils-for-nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2f5dd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2a4c37 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# oils-for-unix from source + +```bash +NIXPKGS_ALLOW_INSECURE=1 nix-build . +``` + +The build uses Python 2 for legacy build scripts. Python 2, marked insecure in nixpkgs, is not present in the final binaries. + +## Files + +- `oils-for-unix-0.37.0.nix` - from-source Oils +- `mypy-0.780.nix` - mypy 0.780 (last version to support --py2) built without mypyc diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..c3a78eb --- /dev/null +++ b/default.nix @@ -0,0 +1,5 @@ +{ + pkgs ? import { }, +}: + +pkgs.callPackage ./oils-for-unix-0.37.0.nix { } diff --git a/mypy-0.780.nix b/mypy-0.780.nix new file mode 100644 index 0000000..ab8978e --- /dev/null +++ b/mypy-0.780.nix @@ -0,0 +1,40 @@ +{ + lib, + fetchFromGitHub, + python3, +}: + +python3.pkgs.buildPythonPackage rec { + pname = "mypy"; + # This is the version oils-for-unix uses for mycpp Python-to-C++ translation + version = "0.780"; + + src = fetchFromGitHub { + owner = "python"; + repo = "mypy"; + rev = "v${version}"; + # Fetch submodules to include typeshed (required for type stubs) + fetchSubmodules = true; + hash = "sha256-czwCx6ZjCu3CrVmbI6NbstzWM0GvuPTWJiiUhXSznu4="; + }; + + # Do not use mypyc to compile. + # Rather, build interpreted so mycpp can extend its classes. + preBuild = '' + export MYPY_USE_MYPYC=0 + ''; + + # Skip tests to speed up build + doCheck = false; + + dependencies = with python3.pkgs; [ + mypy-extensions + typing-extensions + typed-ast + ]; + + # Ensure we're not pulling in a compiled version + pythonImportsCheck = [ "mypy" ]; + + meta.license = lib.licenses.mit; +} diff --git a/oils-for-unix-0.37.0.nix b/oils-for-unix-0.37.0.nix new file mode 100644 index 0000000..36e3dea --- /dev/null +++ b/oils-for-unix-0.37.0.nix @@ -0,0 +1,136 @@ +{ + lib, + stdenv, + fetchFromGitHub, + symlinkJoin, + callPackage, + # Build tools + python2, # Legacy build scripts. Marked insecure but not in final binary + python310, # Newest version that supports mypy 0.780's typeshed + re2c, + ninja, + git, + cmark, + which, + time, + readline, +}: + +let + # mypy 0.780 is the last version with --py2 support + # built without mypyc so mycpp can extend its classes + mypy-for-mycpp = callPackage ./mypy-0.780.nix { python3 = python310; }; + + python = python310.withPackages (ps: [ + mypy-for-mycpp + ps.typing-extensions + ]); + + # Configure script expects readline lib and headers at the same prefix + readline-all = symlinkJoin { + name = "readline-all"; + paths = [ + readline + readline.dev + ]; + }; + +in +stdenv.mkDerivation (finalAttrs: { + pname = "oils-for-unix"; + version = "0.37.0"; + + src = fetchFromGitHub { + owner = "oils-for-unix"; + repo = "oils"; + # Reference by release branch + rev = "release/${finalAttrs.version}"; + hash = "sha256-d2i2P8ZiGb+FYzZIzs0pY2gIRQGGuenLbxrGhafVxVc="; + }; + + nativeBuildInputs = [ + python2 + python + re2c + ninja + git + cmark + which + time + ]; + + buildInputs = [ readline ]; + + postPatch = '' + patchShebangs . + + substituteInPlace build/dynamic-deps.sh \ + --replace-quiet '/usr/bin/env' "$(command -v env)" + + # _PyVerify_fd is Windows-only + substituteInPlace pyext/posixmodule.c \ + --replace-quiet '_PyVerify_fd(fd)' '1' + + substituteInPlace doctools/cmark.py \ + --replace-quiet "raise AssertionError('bin/cmark not found')" \ + "cmark_path = '${cmark}/bin/cmark'" + ''; + + configurePhase = '' + runHook preConfigure + ./configure \ + --datarootdir=$out \ + --with-readline \ + --readline=${readline-all} + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + . build/dev-shell.sh + build/py.sh configure-for-dev + build/stamp.sh write-git-commit + build/py.sh py-source + build/py.sh py-extensions + build/doc.sh all-ref + ./NINJA-config.sh + ninja _bin/cxx-opt/oils-for-unix + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin + install -m755 _bin/cxx-opt/oils-for-unix $out/bin/oils-for-unix + ln -s oils-for-unix $out/bin/osh + ln -s oils-for-unix $out/bin/ysh + runHook postInstall + ''; + + # Suppress warnings from older C code in vendor dependencies + env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=incompatible-function-pointer-types"; + + meta = { + license = lib.licenses.asl20; + platforms = lib.platforms.all; + mainProgram = "osh"; + }; + + passthru = + let + mkShell = + shellName: + symlinkJoin { + name = "oils-for-unix-${shellName}-${finalAttrs.version}"; + paths = [ finalAttrs.finalPackage ]; + passthru.shellPath = "/bin/${shellName}"; + meta = finalAttrs.meta // { + mainProgram = shellName; + }; + }; + in + { + osh = mkShell "osh"; + ysh = mkShell "ysh"; + }; +})