summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Flynn <[email protected]>2025-03-05 15:27:26 -0500
committerSeth Flynn <[email protected]>2025-03-05 15:31:38 -0500
commit6fa4458f59160cdf9e82ad2138300b1041f510ad (patch)
tree88aeb808a13eadeacf0bc9b97d85c93f10de7a2d
parentb229a37e59b9720b7017e72a6d159b869ff36458 (diff)
treewide: use flake
Signed-off-by: Seth Flynn <[email protected]>
-rw-r--r--.github/workflows/ci.yaml58
-rw-r--r--.github/workflows/update-flake.yaml44
-rw-r--r--checks.nix51
-rw-r--r--default.nix63
-rw-r--r--dev-shells.nix16
-rw-r--r--flake.lock69
-rw-r--r--flake.nix39
-rw-r--r--lwjgl.nix25
-rw-r--r--module.nix131
-rw-r--r--pkgs/lwjgl/default.nix (renamed from pkgs/lwjgl.nix)41
-rw-r--r--pkgs/lwjgl/fix-library-paths.patch36
-rw-r--r--release.nix48
-rw-r--r--shell.nix17
13 files changed, 494 insertions, 144 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 054e4a3..e6012f8 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -5,34 +5,66 @@ on:
branches: [main]
paths:
- "**.nix"
+ - "flake.lock"
- ".github/workflows/ci.yaml"
pull_request:
paths:
- "**.nix"
+ - "flake.lock"
- ".github/workflows/ci.yaml"
+ workflow_call:
+ inputs:
+ ref:
+ type: string
+ description: "The branch, tag or SHA to checkout."
+ required: false
workflow_dispatch:
jobs:
- build:
- name: Build
+ eval:
+ name: Eval
- strategy:
- matrix:
- include:
- - os: ubuntu-latest
- system: x86_64-linux
-
- runs-on: ${{ matrix.os }}
+ runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
+ with:
+ ref: ${{ inputs.ref }}
- name: Install Nix
uses: cachix/install-nix-action@v30
- with:
- nix_path: nixpkgs=channel:nixos-unstable
- - name: Run build
+ - name: Evaluate Flake
run: |
- nix-build release.nix -A ${{ matrix.system }}
+ nix flake check \
+ --all-systems \
+ --no-build \
+ --show-trace
+
+ # build:
+ # name: Build (${{ matrix.system }})
+
+ # strategy:
+ # matrix:
+ # include:
+ # - os: ubuntu-latest
+ # system: x86_64-linux
+
+ # runs-on: ${{ matrix.os }}
+
+ # steps:
+ # - name: Checkout repository
+ # uses: actions/checkout@v4
+ # with:
+ # ref: ${{ inputs.ref }}
+
+ # - name: Install Nix
+ # uses: cachix/install-nix-action@v30
+
+ # - name: Run build
+ # run: |
+ # nix flake check \
+ # --fallback \
+ # --print-build-logs \
+ # --show-trace
diff --git a/.github/workflows/update-flake.yaml b/.github/workflows/update-flake.yaml
new file mode 100644
index 0000000..f7e0b12
--- /dev/null
+++ b/.github/workflows/update-flake.yaml
@@ -0,0 +1,44 @@
+name: Update flake.lock
+
+on:
+ schedule:
+ # Run every Saturday
+ - cron: "0 0 * * 6"
+ workflow_dispatch:
+
+jobs:
+ update:
+ name: Run update & create PR
+
+ runs-on: ubuntu-latest
+
+ permissions:
+ contents: write
+ pull-requests: write
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Install Nix
+ uses: cachix/install-nix-action@v30
+
+ - name: Run update
+ run: |
+ nix flake update \
+ --commit-lock-file \
+ --commit-lockfile-summary "flake: update inputs"
+
+ - name: Create pull request
+ id: create-pull-request
+ uses: peter-evans/create-pull-request@v7
+ with:
+ branch: update-flake-lock
+ title: "flake: update inputs"
+ token: ${{ github.token }}
+ sign-commits: true
+
+ - name: Run CI
+ uses: ./.github/workflows/ci.yaml
+ with:
+ ref: ${{ steps.create-pull-request.outputs.pull-request-head-sha }}
diff --git a/checks.nix b/checks.nix
new file mode 100644
index 0000000..a21986a
--- /dev/null
+++ b/checks.nix
@@ -0,0 +1,51 @@
+{
+ lib,
+ inputs,
+ self,
+ ...
+}:
+
+let
+ collectNestedDerivationsIn = lib.foldlAttrs (
+ acc: attrType: values:
+
+ acc // lib.mapAttrs' (attrName: lib.nameValuePair "${attrType}-${attrName}") values
+ ) { };
+in
+
+{
+ imports = [ inputs.getchpkgs.flakeModules.checks ];
+
+ perSystem =
+ {
+ pkgs,
+ system,
+ self',
+ ...
+ }:
+
+ lib.mkMerge [
+ {
+ checks = collectNestedDerivationsIn { inherit (self') devShells packages; };
+ }
+
+ (lib.mkIf (system == "x86_64-linux") {
+ quickChecks = {
+ deadnix = {
+ dependencies = [ pkgs.deadnix ];
+ script = "deadnix --fail ${self}";
+ };
+
+ nixfmt = {
+ dependencies = [ pkgs.nixfmt-rfc-style ];
+ script = "nixfmt --check ${self}";
+ };
+
+ statix = {
+ dependencies = [ pkgs.statix ];
+ script = "statix check ${self}";
+ };
+ };
+ })
+ ];
+}
diff --git a/default.nix b/default.nix
deleted file mode 100644
index fb95f92..0000000
--- a/default.nix
+++ /dev/null
@@ -1,63 +0,0 @@
-# nix-build
-# or to build a cross compiled package: nix-build -A <triple>.lwjgl
-# i.e., nix-build -A aarch64-unknown-linux-gnu.lwjgl
-{
- pkgs ? import <nixpkgs> {
- inherit system;
- config = { };
- overlays = [ ];
- },
- nixpkgs ? <nixpkgs>,
- system ? builtins.currentSystem,
-}:
-
-let
- inherit (pkgs) lib;
- inherit (pkgs.stdenv.hostPlatform) system;
- nativeTarget = pkgs.stdenv.hostPlatform.config;
-
- # Targets we want to build for
- targets = [
- "x86_64-unknown-linux-gnu"
- "i686-unknown-linux-gnu"
- "aarch64-unknown-linux-gnu"
- "armv7l-unknown-linux-gnueabihf"
- "riscv64-unknown-linux-gnu"
- ];
-
- # Loop over each target
- forAllTargets = lib.genAttrs targets;
-
- # Nixpkgs re-instantiated to cross compile from our current system to each target
- crossPkgsFor = forAllTargets (
- target:
-
- import nixpkgs {
- inherit system;
- inherit (pkgs) config overlays;
- crossSystem = {
- config = target;
- };
- }
- );
-
- # Our package set for each target
- ourPackagesFor = forAllTargets (
- target:
-
- let
- callPackage = lib.callPackageWith (ourPackagesFor.${target} // crossPkgsFor.${target});
- in
-
- {
- fetchAntDeps = callPackage ./pkgs/fetch-ant-deps.nix { };
- lwjgl = callPackage ./pkgs/lwjgl.nix { };
- }
- );
-
- nativeLwjgl =
- ourPackagesFor.${nativeTarget}.lwjgl
- or (lib.trace "${nativeTarget} is not a supported target" pkgs.emptyFile);
-in
-
-ourPackagesFor // { lwjgl = nativeLwjgl; }
diff --git a/dev-shells.nix b/dev-shells.nix
new file mode 100644
index 0000000..546c48b
--- /dev/null
+++ b/dev-shells.nix
@@ -0,0 +1,16 @@
+{
+ perSystem =
+ { pkgs, ... }:
+
+ {
+ devShells = {
+ default = pkgs.mkShellNoCC {
+ packages = [
+ pkgs.deadnix
+ pkgs.nixfmt-rfc-style
+ pkgs.statix
+ ];
+ };
+ };
+ };
+}
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..d4a59cb
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,69 @@
+{
+ "nodes": {
+ "flake-parts": {
+ "inputs": {
+ "nixpkgs-lib": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1740872218,
+ "narHash": "sha256-ZaMw0pdoUKigLpv9HiNDH2Pjnosg7NBYMJlHTIsHEUo=",
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "rev": "3876f6b87db82f33775b1ef5ea343986105db764",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "type": "github"
+ }
+ },
+ "getchpkgs": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1741162235,
+ "narHash": "sha256-ZqXa57XaT68NrcXTfltBHsglU+jInnW26lY25AVNB+c=",
+ "owner": "getchoo",
+ "repo": "getchpkgs",
+ "rev": "c294ae90127005d023bbe3f6a5da95c9a94c4e45",
+ "type": "github"
+ },
+ "original": {
+ "owner": "getchoo",
+ "repo": "getchpkgs",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1741010256,
+ "narHash": "sha256-WZNlK/KX7Sni0RyqLSqLPbK8k08Kq7H7RijPJbq9KHM=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "ba487dbc9d04e0634c64e3b1f0d25839a0a68246",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-parts": "flake-parts",
+ "getchpkgs": "getchpkgs",
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..4bea99c
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,39 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+
+ flake-parts = {
+ url = "github:hercules-ci/flake-parts";
+ inputs.nixpkgs-lib.follows = "nixpkgs";
+ };
+
+ getchpkgs = {
+ url = "github:getchoo/getchpkgs";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs =
+ inputs:
+
+ inputs.flake-parts.lib.mkFlake { inherit inputs; } {
+ imports = [
+ ./checks.nix
+ ./dev-shells.nix
+ ./lwjgl.nix
+ ./module.nix
+ ];
+
+ systems = [
+ "x86_64-linux"
+ "aarch64-linux"
+ ];
+
+ perSystem =
+ { pkgs, ... }:
+
+ {
+ formatter = pkgs.nixfmt-rfc-style;
+ };
+ };
+}
diff --git a/lwjgl.nix b/lwjgl.nix
new file mode 100644
index 0000000..f860abb
--- /dev/null
+++ b/lwjgl.nix
@@ -0,0 +1,25 @@
+{
+ lwjgl = {
+ # Targets we want to build for
+ targets = [
+ "x86_64-unknown-linux-gnu"
+ "i686-unknown-linux-gnu"
+ "aarch64-unknown-linux-gnu"
+ "armv7l-unknown-linux-gnueabihf"
+ "riscv64-unknown-linux-gnu"
+ ];
+
+ # Versions we're building
+ versions = {
+ "3.3.4" = {
+ hash = "sha256-U0pPeTqVoruqqhhMrBrczy0qt83a8atr8DyRcGgX/yI=";
+ antHash = "sha256-7jVlKBia8dJGuBjNwaljHBrXUep9KjOHHyZESayFnhs=";
+ };
+
+ "3.3.6" = {
+ hash = "sha256-iXwsTo394uoq8/jIlfNuQlXW1lnuge+5/+00O4UdvyA=";
+ antHash = "sha256-XNJpu6nS7gloQuKJadaUHeW0N9EpFKmJEib6/I2exVE=";
+ };
+ };
+ };
+}
diff --git a/module.nix b/module.nix
new file mode 100644
index 0000000..d828c97
--- /dev/null
+++ b/module.nix
@@ -0,0 +1,131 @@
+{
+ config,
+ lib,
+ inputs,
+ ...
+}:
+
+let
+ cfg = config.lwjgl;
+
+ lwjglVersionSubmodule =
+ { name, ... }:
+ {
+ freeformType = lib.types.attrsOf lib.types.anything;
+
+ options = {
+ version = lib.mkOption {
+ type = lib.types.str;
+ default = name;
+ defaultText = lib.literalExpression "config.name";
+ description = "Version of LWJGL3 these arguments are for.";
+ };
+
+ hash = lib.mkOption {
+ type = lib.types.str;
+ description = "Hash of the LWJGL3 source tarball.";
+ };
+
+ antHash = lib.mkOption {
+ type = lib.types.str;
+ description = "Hash of the LWJGL3 ant dependencies.";
+ };
+ };
+ };
+
+ lwjglSubmodule = {
+ options = {
+ targets = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ description = "A list of target triples to cross compile LWJGL3 for.";
+ };
+
+ versions = lib.mkOption {
+ type = lib.types.attrsOf (lib.types.submodule lwjglVersionSubmodule);
+ default = { };
+ description = "An attribute set of LWJGL3 versions and hashes.";
+ };
+ };
+ };
+in
+
+{
+ options.lwjgl = lib.mkOption {
+ type = lib.types.submodule lwjglSubmodule;
+ default = { };
+ description = "Configuration for the LWJGL3 project.";
+ };
+
+ config = {
+ perSystem =
+ {
+ pkgs,
+ system,
+ self',
+ ...
+ }:
+
+ let
+ nativeTarget = pkgs.stdenv.hostPlatform.config;
+
+ fetchAntDeps = pkgs.callPackage ./pkgs/fetch-ant-deps.nix { };
+
+ # Loop over each target
+ forAllTargets = lib.genAttrs cfg.targets;
+
+ # Nixpkgs re-instantiated to cross compile from our current system to each target
+ crossPkgsFor = forAllTargets (
+ target:
+
+ if target == nativeTarget then
+ pkgs
+ else
+ import inputs.nixpkgs {
+ inherit system;
+ inherit (pkgs) config overlays;
+ crossSystem = {
+ config = target;
+ };
+ }
+ );
+
+ # Our package set for each target
+ ourPackagesFor = forAllTargets (
+ target:
+
+ let
+ lwjgls = lib.mapAttrs' (
+ version: args:
+
+ lib.nameValuePair "${target}-lwjgl-${version}" (
+ crossPkgsFor.${target}.callPackage ./pkgs/lwjgl ({ inherit fetchAntDeps version; } // args)
+ )
+ ) cfg.versions;
+
+ versions = lib.naturalSort (lib.attrNames lwjgls);
+ in
+
+ {
+ # Use latest version by default
+ lwjgl = lwjgls.${lib.elemAt versions (lib.length versions - 1)};
+ }
+ // lwjgls
+ );
+ in
+
+ {
+ packages = lib.mergeAttrsList (
+ (lib.attrValues ourPackagesFor)
+ ++ [
+ {
+ lwjgl =
+ ourPackagesFor.${nativeTarget}.lwjgl
+ or (lib.trace "${nativeTarget} is not a supported target" pkgs.emptyFile);
+
+ default = self'.packages.lwjgl;
+ }
+ ]
+ );
+ };
+ };
+}
diff --git a/pkgs/lwjgl.nix b/pkgs/lwjgl/default.nix
index fac5eb5..546c45c 100644
--- a/pkgs/lwjgl.nix
+++ b/pkgs/lwjgl/default.nix
@@ -5,28 +5,55 @@
ant,
at-spi2-atk,
buildPackages,
+ cairo,
dbus,
fetchAntDeps,
fetchFromGitHub,
gdk-pixbuf,
+ glib,
gtk3,
+ harfbuzz,
kotlin,
libGLU,
+ libffi,
libglvnd,
+ pango,
+ replaceVars,
xorg,
+
+ version,
+ hash,
+ antHash,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "lwjgl";
- version = "3.3.4";
+ inherit version;
src = fetchFromGitHub {
owner = "LWJGL";
repo = "lwjgl3";
tag = finalAttrs.version;
- hash = "sha256-U0pPeTqVoruqqhhMrBrczy0qt83a8atr8DyRcGgX/yI=";
+ inherit hash;
};
+ patches = [
+ (replaceVars ./fix-library-paths.patch (
+ lib.mapAttrs (lib.const lib.getDev) {
+ inherit
+ at-spi2-atk
+ cairo
+ dbus
+ gdk-pixbuf
+ glib
+ gtk3
+ harfbuzz
+ pango
+ ;
+ }
+ ))
+ ];
+
antJdk = buildPackages.jdk_headless;
antDeps = fetchAntDeps {
inherit (finalAttrs)
@@ -35,7 +62,7 @@ stdenv.mkDerivation (finalAttrs: {
src
antJdk
;
- hash = "sha256-7jVlKBia8dJGuBjNwaljHBrXUep9KjOHHyZESayFnhs=";
+ hash = antHash;
};
strictDeps = true;
@@ -47,15 +74,23 @@ stdenv.mkDerivation (finalAttrs: {
buildInputs = [
at-spi2-atk
+ cairo
dbus
gdk-pixbuf
+ glib
gtk3
+ harfbuzz
libGLU
+ libffi
+ pango
xorg.libX11
xorg.libXt
];
env = {
+ NIX_CFLAGS = "-funroll-loops -I${lib.getDev gtk3}/include/gtk-3.0";
+ NIX_LDFLAGS = "-lffi";
+
JAVA_HOME = finalAttrs.antJdk.home;
JAVA8_HOME = buildPackages.jdk8_headless.home;
diff --git a/pkgs/lwjgl/fix-library-paths.patch b/pkgs/lwjgl/fix-library-paths.patch
new file mode 100644
index 0000000..0d6b332
--- /dev/null
+++ b/pkgs/lwjgl/fix-library-paths.patch
@@ -0,0 +1,36 @@
+diff --git a/config/linux/build.xml b/config/linux/build.xml
+index a1798b6aa..13a75815f 100644
+--- a/config/linux/build.xml
++++ b/config/linux/build.xml
+@@ -282,15 +282,13 @@
+ <build module="nfd" simple="true" linker="g++" if:true="${binding.nfd}">
+ <beforeCompile>
+ <compile lang="c++">
+- <arg value="-I/usr/include/gtk-3.0"/>
+- <arg value="-I/usr/include/glib-2.0"/>
+- <arg value="-I/usr/include/pango-1.0"/>
+- <arg value="-I/usr/include/harfbuzz"/>
+- <arg value="-I/usr/include/cairo"/>
+- <arg value="-I/usr/include/gdk-pixbuf-2.0"/>
+- <arg value="-I/usr/include/atk-1.0"/>
+- <arg value="-I/usr/lib64/glib-2.0/include"/>
+- <arg value="-I/usr/lib/${linux.triplet}/glib-2.0/include"/>
++ <arg value="-I@gtk3@"/>
++ <arg value="-I@glib@"/>
++ <arg value="-I@pango@"/>
++ <arg value="-I@harfbuzz@"/>
++ <arg value="-I@cairo@"/>
++ <arg value="-I@gdk-pixbuf@"/>
++ <arg value="-I@at-spi2-atk@"/>
+ <arg value="-I${src.main.rel}/include"/>
+ <fileset dir="." includes="${src.main}/nfd_gtk.cpp"/>
+ </compile>
+@@ -308,7 +306,7 @@
+ <build module="nfd" suffix="_portal" simple="true" linker="g++" if:true="${binding.nfd}">
+ <beforeCompile>
+ <compile lang="c++">
+- <arg line="-I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/lib/${linux.triplet}/dbus-1.0/include"/>
++ <arg line="-I@dbus@"/>
+ <arg value="-I${src.main.rel}/include"/>
+ <fileset dir="." includes="${src.main}/nfd_portal.cpp"/>
+ </compile>
diff --git a/release.nix b/release.nix
deleted file mode 100644
index 7b0524b..0000000
--- a/release.nix
+++ /dev/null
@@ -1,48 +0,0 @@
-# nix-build release.nix -A <system>
-# i.e., nix-build release.nix -A x86_64-linux
-{
- lib ? import <nixpkgs/lib>,
-}:
-
-let
- src = lib.fileset.toSource {
- root = ./.;
- fileset = lib.fileset.gitTracked ./.;
- };
-
- systems = [
- "x86_64-linux"
- "aarch64-linux"
- "x86_64-darwin"
- "aarch64-darwin"
- ];
-in
-
-lib.genAttrs systems (
- system:
-
- let
- pkgs = import <nixpkgs> {
- inherit system;
- config = { };
- overlays = [ ];
- };
-
- mkCheck =
- name: deps: script:
- pkgs.runCommand name { nativeBuildInputs = deps; } ''
- ${script}
- touch $out
- '';
-
- packages = lib.mapAttrs (lib.const lib.recurseIntoAttrs) (import ./default.nix { inherit pkgs; });
-
- checks = {
- deadnix = mkCheck "check-deadnix" [ pkgs.deadnix ] "deadnix --fail ${src}";
- nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${src}";
- statix = mkCheck "check-statix" [ pkgs.statix ] "statix check ${src}";
- };
- in
-
- checks // packages // { shell = import ./shell.nix { inherit pkgs; }; }
-)
diff --git a/shell.nix b/shell.nix
deleted file mode 100644
index 80e9e25..0000000
--- a/shell.nix
+++ /dev/null
@@ -1,17 +0,0 @@
-# nix-shell
-{
- pkgs ? import <nixpkgs> {
- inherit system;
- config = { };
- overlays = [ ];
- },
- system ? builtins.currentSystem,
-}:
-
-pkgs.mkShellNoCC {
- packages = [
- pkgs.deadnix
- pkgs.nixfmt-rfc-style
- pkgs.statix
- ];
-}