Add Nix build infrastructure

This commit is contained in:
Félix Baylac Jacqué 2022-11-22 10:23:20 +01:00 committed by Félix Baylac-Jacqué
parent 91d1d09d89
commit 834d7d56c9
Signed by: picnoir
GPG Key ID: EFD315F31848DBA4
5 changed files with 151 additions and 0 deletions

30
default.nix Normal file
View File

@ -0,0 +1,30 @@
{ pkgs ? import <nixpkgs> { }, lib ? pkgs.lib }:
pkgs.stdenvNoCC.mkDerivation {
pname = "nix-gl-host";
version = "0.1";
# TODO: filter that out
src = lib.cleanSource ./.;
nativeBuildInputs = [
pkgs.nixpkgs-fmt
pkgs.python3
pkgs.python3Packages.black
pkgs.nixpkgs-fmt
];
postFixup = ''
substituteInPlace $out/bin/nixglhost \
--replace "@patchelf-bin@" "${pkgs.patchelf}/bin/patchelf" \
--replace "IN_NIX_STORE = False" "IN_NIX_STORE = True"
patchShebangs $out/bin/nixglhost
'';
postCheck = ''
black --check $out/bin/nixglhost
nixpkgs-fmt --check *.nix
'';
installPhase = ''
install -D -m0755 nixglhost-wrapper.py $out/bin/nixglhost
'';
}

27
flake.lock Normal file
View File

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1669045945,
"narHash": "sha256-BQxzijvZpLQ7R+KuQzCPcFgIS6OK0Onb29pYFe2pzJo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6b5019a48f876f3288efc626fa8b70ad0c64eb46",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

28
flake.nix Normal file
View File

@ -0,0 +1,28 @@
{
description = "Gluing native OpenGL drivers";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs =
{ self
, nixpkgs
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
in
{
defaultPackage = forAllSystems (system:
import ./default.nix {
pkgs = import nixpkgs { inherit system; };
});
devShell = forAllSystems (system:
nixpkgs.legacyPackages.${system}.callPackage ./shell.nix { }
);
formatter = forAllSystems (system:
nixpkgs.legacyPackages.${system}.nixpkgs-fmt
);
};
}

57
nixglhost-wrapper.py Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/env python3
import argparse
import os
import sys
IN_NIX_STORE = False
if IN_NIX_STORE:
# The following paths are meant to be substituted by Nix at build
# time.
PATCHELF_PATH = "@patchelf-bin@"
else:
PATCHELF_PATH = "patchelf"
def info_debug(string):
"""Prints STR to STDERR if the DEBUG environment variable is set"""
if "DEBUG" in os.environ:
print(f"[+] {string}", file=sys.stderr)
def patch_dso(dsoPath, ):
raise "TODO patch_dso"
def find_vendor_dso():
raise "TODO find_vendor_dso"
def exec_binary(args):
raise "TODO exec_binary"
def main(args):
home = os.path.expanduser("~")
xdg_cache_home = os.environ.get("XDG_CACHE_HOME", os.path.join(HOME, ".cache"))
os.exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="nixglhost-wrapper",
description="Wrapper used to massage the host GL drivers to work with your nix-built binary.",
)
parser.add_argument(
"GL_VENDOR_PATH",
type=str,
help="a path pointing to the directory containing your GL driver shared libraries",
)
parser.add_argument(
"NIX_BINARY_AND_ARGS",
type=str,
nargs="+",
help="Nix-built binary you'd like to wrap and its args. For instance: nixglhost-wrapper /usr/lib/nvidia opengl-exe --with --some --args",
)
args = parser.parse_args()
main()

9
shell.nix Normal file
View File

@ -0,0 +1,9 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
nativeBuildInputs = [
pkgs.nixpkgs-fmt
pkgs.python3Packages.black
pkgs.python3Packages.mypy
];
}