Skip to content

Commit

Permalink
Enable nix based build actions (#31)
Browse files Browse the repository at this point in the history
* Enable nix based build actions

* Add clippy and fmt in multi-stage build

* Rework flake

* Enable darwin target
  • Loading branch information
IGI-111 authored May 27, 2024
1 parent 053e15f commit adbad49
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 45 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/nix-github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Nix Flake actions

on:
pull_request:
push:
branches:
- master
- main

jobs:
nix-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- id: set-matrix
name: Generate Nix Matrix
run: |
set -Eeu
matrix="$(nix eval --json '.#githubActions.matrix')"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
nix-build:
needs: nix-matrix
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- run: nix build -L ".#${{ matrix.attr }}"
22 changes: 22 additions & 0 deletions flake.lock

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

167 changes: 122 additions & 45 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,28 @@
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
nix-github-actions.url = "github:IGI-111/nix-github-actions?ref=IGI-111/add-aarch64-darwin";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
};

outputs =
{
self,
nixpkgs,
crane,
flake-utils,
nix-github-actions,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
craneLib = crane.mkLib pkgs;
buildInputs = with pkgs; [
xorg.libXi
xorg.libX11
xorg.libXcursor
libxkbcommon
fontconfig
libGL
wayland
openssl
];
nativeBuildInputs = with pkgs; [
rustc
cargo
rustfmt
rustPackages.clippy
rust-analyzer
slint-lsp

pkg-config
# kdialog
];
libPath = pkgs.lib.makeLibraryPath buildInputs;
in
{
packages.default = craneLib.buildPackage {
let
buildPackageForSystem =
{
pkgs,
buildInputs,
nativeBuildInputs,
}:
let
craneLib = crane.mkLib pkgs;
libPath = pkgs.lib.makeLibraryPath buildInputs;
src =
let
# Only keeps slint files
Expand All @@ -57,19 +39,114 @@
src = craneLib.path ./.;
filter = sourceFilter;
};

# Add extra inputs here or any other derivation settings
# doCheck = true;
buildInputs = buildInputs;
nativeBuildInputs = nativeBuildInputs;
LD_LIBRARY_PATH = libPath;
};
# `nix develop`
devShell = pkgs.mkShell {
buildInputs = buildInputs;
nativeBuildInputs = nativeBuildInputs;
LD_LIBRARY_PATH = libPath;
cargoArtifacts = craneLib.buildDepsOnly {
inherit src buildInputs nativeBuildInputs;
LD_LIBRARY_PATH = libPath;
};
kira = craneLib.buildPackage {
inherit
src
buildInputs
nativeBuildInputs
cargoArtifacts
;
doNotSign = true; # FIXME: disable apple binary signature
LD_LIBRARY_PATH = libPath;
};
in
{
defaultPackage = kira;
checks = {
inherit kira;
kira-clippy = craneLib.cargoClippy {
inherit
src
buildInputs
nativeBuildInputs
cargoArtifacts
;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};
kira-fmt = craneLib.cargoFmt { inherit src; };
};
devShell = pkgs.mkShell {
inherit buildInputs nativeBuildInputs;
LD_LIBRARY_PATH = libPath;
};
};
}
);

buildPackageDeps = {
"x86_64-linux" =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
{
inherit pkgs;
buildInputs = with pkgs; [
xorg.libXi
xorg.libX11
xorg.libXcursor
libxkbcommon
fontconfig
libGL
wayland
openssl
];
nativeBuildInputs = with pkgs; [
rustc
cargo
rustfmt
rustPackages.clippy
rust-analyzer
slint-lsp

pkg-config
# kdialog
];
};

"aarch64-darwin" =
let
pkgs = nixpkgs.legacyPackages.aarch64-darwin;
in
{
inherit pkgs;
buildInputs = with pkgs; [
openssl
darwin.signingUtils
darwin.libiconv
darwin.libobjc
# darwin.xcode
# darwin.apple_sdk.sdk
darwin.apple_sdk.Libsystem
# darwin.apple_sdk.frameworks
darwin.apple_sdk.frameworks.SystemConfiguration
darwin.apple_sdk.frameworks.AppKit
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Cocoa
darwin.apple_sdk.frameworks.Security
];
nativeBuildInputs = with pkgs; [
rustc
cargo
rustfmt
rustPackages.clippy
rust-analyzer
slint-lsp

pkg-config
uutils-coreutils
findutils
];
};
};
in
{
githubActions = nix-github-actions.lib.mkGithubMatrix { inherit (self) checks; };
}
// flake-utils.lib.eachSystem [
"x86_64-linux"
# "x86_64-darwin"
"aarch64-darwin"
] (system: buildPackageForSystem buildPackageDeps."${system}");
}

0 comments on commit adbad49

Please sign in to comment.