diff --git a/.github/workflows/nix-github-actions.yml b/.github/workflows/nix-github-actions.yml new file mode 100644 index 0000000..3dc0069 --- /dev/null +++ b/.github/workflows/nix-github-actions.yml @@ -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 }}" diff --git a/flake.lock b/flake.lock index c6af7fc..49c7d3b 100644 --- a/flake.lock +++ b/flake.lock @@ -38,6 +38,27 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716823556, + "narHash": "sha256-xe91WnzDwGrnY2O992hK1Frq9bpj+NMvl43BtjX/UJs=", + "owner": "IGI-111", + "repo": "nix-github-actions", + "rev": "878fcd535257a2fd22d5d1e95cd4b447bb94ca94", + "type": "github" + }, + "original": { + "owner": "IGI-111", + "ref": "IGI-111/add-aarch64-darwin", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1716715802, @@ -58,6 +79,7 @@ "inputs": { "crane": "crane", "flake-utils": "flake-utils", + "nix-github-actions": "nix-github-actions", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index e7ef7d7..2abe210 100644 --- a/flake.nix +++ b/flake.nix @@ -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 @@ -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}"); }