Skip to content

Commit

Permalink
🎉 (haxe-nix/) Add new example
Browse files Browse the repository at this point in the history
  • Loading branch information
Comamoca committed Oct 14, 2024
1 parent 98e4808 commit 2436af1
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 0 deletions.
3 changes: 3 additions & 0 deletions haxe-nix/build.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--class-path src
-main hello.Main
--cpp out
48 changes: 48 additions & 0 deletions haxe-nix/deps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2003-2024 Eelco Dolstra and the Nixpkgs/NixOS contributors
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{ pkgs, haxe-support }:
let
lib = pkgs.lib;

withCommas = lib.replaceStrings [ "." ] [ "," ];
stdenv = pkgs.stdenv;

# local-lib = pkgs.callPackage ./lib.nix { inherit pkgs; };
# buildHaxeLib = local-lib.buildHaxeLib;
buildHaxeLib = haxe-support.buildHaxeLib;
in {
# inherit local-lib;

hxcpp = buildHaxeLib rec {
libname = "hxcpp";
version = "4.3.2";
sha256 = "sha256-mm0JObjNgi9JSLRv7IUAZeMUFV2f8+7OG8FhRWtNlqQ=";
postFixup = ''
for f in $out/lib/haxe/${withCommas libname}/${withCommas version}/{,project/libs/nekoapi/}bin/Linux{,64}/*; do
chmod +w "$f"
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) "$f" || true
patchelf --set-rpath ${ lib.makeLibraryPath [ stdenv.cc.cc ] } "$f" || true
done
'';
meta.description = "Runtime support library for the Haxe C++ backend";
};
}
226 changes: 226 additions & 0 deletions haxe-nix/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions haxe-nix/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
description = "A basic flake to with flake-parts";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
treefmt-nix.url = "github:numtide/treefmt-nix";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
haxe-support.url = "github:comamoca/nix-haxe-support";
};

outputs =
inputs@{
self,
systems,
nixpkgs,
treefmt-nix,
flake-parts,
haxe-support,
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ treefmt-nix.flakeModule ];
systems = import inputs.systems;

perSystem =
{
config,
pkgs,
system,
...
}:
let
stdenv = pkgs.stdenv;

deps = pkgs.callPackage ./deps.nix { inherit haxe-support; };

executable = stdenv.mkDerivation rec {
pname = "hello";
version = "0.1.0";
src = ./.;

nativeBuildInputs = with pkgs.haxePackages; [
deps.hxcpp
];

buildInputs = with pkgs; [
haxe
];

buildPhase = ''
haxe build.hxml
'';

installPhase = ''
install -D ./out/Main $out/bin/${pname}
'';
};
in
rec {
treefmt = {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
};

settings.formatter = { };
};

devShells.default = pkgs.mkShell {
packages = with pkgs; [
haxe
deps.hxcpp

nil
];
};

packages.default = executable;
};
};
}
Loading

0 comments on commit 2436af1

Please sign in to comment.