Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3cb6bc9
Experimental flake
NotExactlySiev Feb 11, 2025
ba4fa07
Fix flake.nix
NotExactlySiev Feb 11, 2025
4bc9fb6
Remove unneeded rmdir's
NotExactlySiev Feb 11, 2025
acadec0
Add CI for Nix flake
NotExactlySiev Feb 11, 2025
3e433c7
Limit Nix derivation to 2 cores
NotExactlySiev Feb 11, 2025
d580286
Nix: Add other systems to flake
NotExactlySiev Feb 11, 2025
530c914
Nix: syntax error
NotExactlySiev Feb 11, 2025
d7d6bfd
Fix flake
NotExactlySiev Feb 11, 2025
5c9930b
Nix: Limit Github actions to supported platforms
NotExactlySiev Feb 11, 2025
13b8953
Nix: flake typo
NotExactlySiev Feb 11, 2025
be7b9fc
Nix: remove duplicate systems from CI
NotExactlySiev Feb 11, 2025
81cd931
Nix: remove duplicate systems from CI
NotExactlySiev Feb 11, 2025
9281a15
Nix: fix github actions
NotExactlySiev Feb 11, 2025
cfb9ea5
Nix: Update package metadata
NotExactlySiev Feb 11, 2025
72ebd24
Nix: Remove aarch64 for now
NotExactlySiev Feb 11, 2025
ee6af1e
Nix: actually darwin is the problem
NotExactlySiev Feb 11, 2025
ace6745
Nix: actually it's both
NotExactlySiev Feb 11, 2025
1317919
Nix: Add vixl dep
NotExactlySiev Feb 11, 2025
6cbcb5f
Nix: Update flake
NotExactlySiev Feb 11, 2025
a44cbe6
Nix: Fix metadata, cleanup
NotExactlySiev Feb 11, 2025
914a939
Nix: Adjust patch
NotExactlySiev Feb 11, 2025
73679f8
Nix: Fix patch
NotExactlySiev Feb 11, 2025
6f12a24
Nix: Re-enable Lua
NotExactlySiev Feb 11, 2025
0dae74e
Nix: Remove the thirdparty directories that we replace
NotExactlySiev Feb 12, 2025
ccc4493
Removing patch.
nicolasnoble Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/cachix-install-nix-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Nix Flake actions

on:
pull_request:
push:

jobs:
nix-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
- id: set-matrix
name: Generate Nix Matrix
run: |
set -Eeu
matrix="$(nix eval --json '.#githubActions.matrix')"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"

nix-build:
name: ${{ matrix.name }} (${{ matrix.system }})
needs: nix-matrix
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
- uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: cachix/install-nix-action@v30
- run: nix build -L '.#${{ matrix.attr }}'
71 changes: 51 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ CROSS ?= none

UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
CC_IS_CLANG := $(shell $(CC) --version | grep -q clang && echo true || echo false)

PACKAGES := capstone freetype2 glfw3 libavcodec libavformat libavutil libswresample libuv zlib libcurl
PACKAGES := capstone freetype2 glfw3 libavcodec libavformat libavutil libswresample libcurl libuv zlib
OPTIONAL_PACKAGES := md4c fmt libllhttp libluv liburiparser
OPTIONAL_LIBRARIES := multipart ucl

LOCALES := el es_ES fr ja pt_BR uk zh_CN

Expand All @@ -19,29 +21,28 @@ HAS_SUBMODULES = true
endif

CXXFLAGS += -std=c++2b
CPPFLAGS += `pkg-config --cflags $(PACKAGES)`
CPPFLAGS += -I.
CPPFLAGS += -Isrc
CPPFLAGS += -Ithird_party
CPPFLAGS += -Ithird_party/ELFIO
CPPFLAGS += -Ithird_party/fmt/include/
CPPFLAGS_pkg_fmt += -Ithird_party/fmt/include/
CPPFLAGS += -Ithird_party/gl3w
CPPFLAGS += -Ithird_party/googletest/googletest/include
CPPFLAGS += -Ithird_party/imgui
CPPFLAGS += -Ithird_party/imgui/backends
CPPFLAGS += -Ithird_party/imgui/examples
CPPFLAGS += -Ithird_party/imgui/misc/cpp
CPPFLAGS += -Ithird_party/libelfin
CPPFLAGS += -Ithird_party/llhttp
CPPFLAGS_pkg_libllhttp += -Ithird_party/llhttp
CPPFLAGS += -Ithird_party/luajit/src
CPPFLAGS += -Ithird_party/luv/src
CPPFLAGS += -Ithird_party/luv/deps/lua-compat-5.3/c-api
CPPFLAGS_pkg_libluv += -Ithird_party/luv/src
CPPFLAGS_pkg_libluv += -Ithird_party/luv/deps/lua-compat-5.3/c-api
CPPFLAGS += -Ithird_party/magic_enum/include/magic_enum
CPPFLAGS += -Ithird_party/md4c/src
CPPFLAGS += -Ithird_party/multipart-parser-c
CPPFLAGS_pkg_md4c += -Ithird_party/md4c/src
CPPFLAGS_lib_multipart += -Ithird_party/multipart-parser-c
CPPFLAGS += -Ithird_party/tracy/public
CPPFLAGS += -Ithird_party/ucl -Ithird_party/ucl/include
CPPFLAGS += -Ithird_party/uriparser/include
CPPFLAGS_lib_ucl += -Ithird_party/ucl -Ithird_party/ucl/include
CPPFLAGS_pkg_liburiparser += -Ithird_party/uriparser/include
CPPFLAGS += -Ithird_party/zep/extensions
CPPFLAGS += -Ithird_party/zep/include
CPPFLAGS += -Ithird_party/xbyak/xbyak
Expand Down Expand Up @@ -75,7 +76,6 @@ ifeq ($(UNAME_S),Darwin)
endif

LUAJIT_LDFLAGS := $(LDFLAGS)
LDFLAGS += `pkg-config --libs $(PACKAGES)`

ifeq ($(UNAME_S),Darwin)
LDFLAGS += -lc++ -framework GLUT -framework OpenGL -framework CoreFoundation -framework Cocoa
Expand Down Expand Up @@ -108,8 +108,8 @@ endif

LD := $(CXX)

SRCS := $(call rwildcard,src/,*.cc)
SRCS += third_party/fmt/src/os.cc third_party/fmt/src/format.cc
SRCS += $(call rwildcard,src/,*.cc)
SRCS_pkg_fmt += third_party/fmt/src/os.cc third_party/fmt/src/format.cc
IMGUI_SRCS += $(wildcard third_party/imgui/*.cpp)
VIXL_SRCS := $(call rwildcard, third_party/vixl/src,*.cc)
SRCS += $(IMGUI_SRCS)
Expand All @@ -129,16 +129,16 @@ SRCS += third_party/imgui/misc/freetype/imgui_freetype.cpp
SRCS += third_party/imgui_lua_bindings/imgui_lua_bindings.cpp
SRCS += third_party/imgui_md/imgui_md.cpp
SRCS += third_party/imgui_memory_editor/imgui_memory_editor.cpp
SRCS += $(wildcard third_party/llhttp/*.c)
SRCS_pkg_libllhttp += $(wildcard third_party/llhttp/*.c)
SRCS += $(wildcard third_party/lpeg/*.c)
SRCS += third_party/lua-protobuf/pb.c
SRCS += third_party/luafilesystem/src/lfs.c
SRCS += third_party/luv/src/luv.c
SRCS += third_party/md4c/src/md4c.c
SRCS += third_party/multipart-parser-c/multipart_parser.c
SRCS_pkg_libluv += third_party/luv/src/luv.c
SRCS_pkg_md4c += third_party/md4c/src/md4c.c
SRCS_lib_multipart += third_party/multipart-parser-c/multipart_parser.c
SRCS += third_party/nanovg/src/nanovg.c
SRCS += third_party/tracy/public/TracyClient.cpp
SRCS += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c
SRCS_ReleaseWithTracy += third_party/tracy/public/TracyClient.cpp
SRCS_lib_ucl += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c
SRCS += $(wildcard third_party/uriparser/src/*.c)
SRCS += third_party/zep/extensions/repl/mode_repl.cpp
SRCS += $(wildcard third_party/zep/src/*.cpp)
Expand Down Expand Up @@ -176,6 +176,37 @@ TOOLS = exe2elf exe2iso modconv ps1-packer psyq-obj-parser

##############################################################################

SRCS += $(SRCS_$(BUILD))

define CHECK_PKG
ifeq ($(shell pkg-config --exists $(1) && echo true || echo false),true)
PACKAGES += $(1)
else
CPPFLAGS += $(CPPFLAGS_pkg_$(1))
LDFLAGS += $(LDFLAGS_pkg_$(1))
SRCS += $(SRCS_pkg_$(1))
endif
endef

define CHECK_LIB
ifeq ($(shell echo "int main(){}" | gcc -x c - -l$(1) -Wl,--no-as-needed -Wl,--unresolved-symbols=ignore-all -Wl,--no-undefined -o /dev/null >& /dev/null && echo true || echo false),true)
LDFLAGS += -l$(1)
else
CPPFLAGS += $(CPPFLAGS_lib_$(1))
LDFLAGS += $(LDFLAGS_lib_$(1))
SRCS += $(SRCS_lib_$(1))
endif
endef

$(foreach pkg,$(OPTIONAL_PACKAGES),$(eval $(call CHECK_PKG,$(pkg))))
$(foreach lib,$(OPTIONAL_LIBRARIES),$(eval $(call CHECK_LIB,$(lib))))

CPPFLAGS_PKGCONFIG := $(shell pkg-config --cflags $(PACKAGES))
LDFLAGS_PKGCONFIG := $(shell pkg-config --libs $(PACKAGES))

CPPFLAGS += $(CPPFLAGS_PKGCONFIG)
LDFLAGS += $(LDFLAGS_PKGCONFIG)

OBJECTS += $(patsubst %.c,%.o,$(filter %.c,$(SRCS)))
OBJECTS += $(patsubst %.cc,%.o,$(filter %.cc,$(SRCS)))
OBJECTS += $(patsubst %.cpp,%.o,$(filter %.cpp,$(SRCS)))
Expand Down
48 changes: 48 additions & 0 deletions flake.lock

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

41 changes: 41 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
description = "PlayStation 1 emulator and debugger";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = {
self,
nixpkgs,
nix-github-actions
}:
let
lib = nixpkgs.lib;
# githubSystems = builtins.attrNames nix-github-actions.lib.githubPlatforms;
# forAllSystems = lib.genAttrs lib.systems.flakeExposed;
# forGithubSystems = lib.genAttrs githubSystems;
# TODO: githubSystems should be supportedSystems intersects lib.githubPlatforms
# Some of the dependencies don't build on clang. Will fix later
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = lib.genAttrs supportedSystems;
forGithubSystems = lib.genAttrs supportedSystems;
in {
packages = forAllSystems (system:
let pkgs = import nixpkgs { inherit system; };
in {
pcsx-redux = pkgs.callPackage ./pcsx-redux.nix {
src = self;
platforms = lib.systems.flakeExposed;
};
# FIXME: default gets duplicated in githubActions
# default = self.packages.${system}.pcsx-redux;
});
Comment on lines +33 to +35
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Uncomment the default package declaration.

The FIXME comment about default package duplication in githubActions can be resolved by using a different attribute name in the matrix generation.

-      # FIXME: default gets duplicated in githubActions
-      # default = self.packages.${system}.pcsx-redux;
+      default = self.packages.${system}.pcsx-redux;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# FIXME: default gets duplicated in githubActions
# default = self.packages.${system}.pcsx-redux;
});
default = self.packages.${system}.pcsx-redux;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very much not how it works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

@NotExactlySiev I apologize for my incorrect suggestion. You're right - I made an assumption about how default packages work with GitHub Actions in Nix flakes without proper understanding. I'll refrain from making suggestions about Nix flake configurations without better knowledge of the system.


🌐 Web query:

How do default packages work in Nix flakes with GitHub Actions?

💡 Result:

Nix flakes handle default packages through specific output attributes that GitHub Actions can leverage for CI/CD workflows. Here's how they work together:

Default Package Configuration in Flakes

  1. Modern Approach (replaces deprecated defaultPackage):
outputs = { ... }: {
  packages = {
    x86_64-linux = {
      my-app = /* package definition */;
      default = self.packages.x86_64-linux.my-app; # Set primary package
    };
  };
}
  • Use packages.<system>.default as the canonical entry point[1][3]
  • Accessible via nix build without specifying package name[7][9]

GitHub Actions Integration

Key patterns for CI workflows:

- uses: cachix/install-nix-action@v25
- run: nix build          # Builds default package
- run: nix develop -c ... # Uses devShell or falls back to default package[2][5]

Common Workflow Patterns

Action Command Result
Build nix build Builds packages.<system>.default
Develop nix develop Uses devShells.<system>.default or falls back to default package[2]
Check nix flake check Verifies all defined outputs

Best Practices

  1. Always define explicit packages.<system>.default
  2. Use Cachix or Magic-Nix-Cache for binary caching[5]
  3. Combine with flake health checks:
- uses: DeterminateSystems/flake-checker-action@v4
  with:
    check-supported: true
    fail-mode: true[8]

The integration works by having GitHub Actions runners execute standard Nix commands against your flake repository structure. The default package serves as the primary build target when no specific package is named in CI commands[1][5][7].

Citations:


@NotExactlySiev I apologize for my previous incorrect suggestion. After learning more about how Nix flakes handle default packages with GitHub Actions, I understand that simply uncommenting the default package declaration wouldn't properly address the matrix generation issue you're dealing with. Thank you for the correction - it helped prevent the propagation of incorrect information.


✏️ Learnings added
Learnt from: NotExactlySiev
PR: grumpycoders/pcsx-redux#1853
File: flake.nix:33-35
Timestamp: 2025-02-11T16:23:24.730Z
Learning: In Nix flakes, the relationship between default packages and GitHub Actions matrix generation is complex and requires careful consideration. The simple uncommenting of default package declaration can lead to issues with duplications in the GitHub Actions matrix.

Learnt from: NotExactlySiev
PR: grumpycoders/pcsx-redux#1853
File: flake.nix:33-35
Timestamp: 2025-02-11T16:23:24.730Z
Learning: In Nix flakes, the relationship between `packages.<system>.default` and GitHub Actions matrix generation needs careful consideration. Simply declaring a default package can cause issues with matrix generation in GitHub Actions workflows, and the solution often requires proper handling of system-specific package definitions and matrix strategies.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = forGithubSystems (system: self.packages.${system});
};
};
}
Loading
Loading