Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding flake.nix #363

Merged
merged 6 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
29 changes: 29 additions & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: nix build

on:
pull_request:
branches:
- 0.0.x
paths:
- '**/*.rs'
- '.github/workflows/nix-build.yml'
- 'nix/**'
push:
branches:
- 0.0.x
paths:
- '**/*.rs'
- '.github/workflows/nix-build.yml'
- 'nix/**'

jobs:
lints:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: DeterminateSystems/flake-checker-action@main
- name: Run `nix build`
run: nix build
27 changes: 27 additions & 0 deletions .github/workflows/update-flake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: update-flake-lock
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'

jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Enable magic Nix cache
uses: DeterminateSystems/magic-nix-cache-action@main
- name: Check flake
uses: DeterminateSystems/flake-checker-action@main
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@main
with:
pr-title: 'Update flake.lock' # Title of PR to be created
pr-labels: | # Labels to be set on the PR
dependencies
automated
pr-assignees: TornaxO7 RaySlash

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
release
.jekyll-cache
.jekyll-metadata
NOTES
NOTES

.direnv/
# produced by `nix build`
result/
112 changes: 112 additions & 0 deletions flake.lock

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

113 changes: 113 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = inputs@{ self, nixpkgs, systems, rust-overlay, ... }:
let
# Using nix-systems to identify architecture
eachSystem = nixpkgs.lib.genAttrs (import systems);
pkgsFor = eachSystem (system:
import nixpkgs {
localSystem = system;
overlays = [
rust-overlay.overlays.default
];
});

mkRio = ({ rustPlatform, lib, pkgs, ... }:
let
rlinkLibs = with pkgs; if stdenv.isDarwin then [
darwin.libobjc
darwin.apple_sdk_11_0.frameworks.AppKit
darwin.apple_sdk_11_0.frameworks.AVFoundation
darwin.apple_sdk_11_0.frameworks.Vision
] else [
fontconfig
libGL
libxkbcommon
vulkan-loader
] ++ (with pkgs; [
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
xorg.libxcb
wayland
]);
in
rustPlatform.buildRustPackage {
pname = "rio";
name = "rio"; # attribute name for packages
src = ./.;
nativeBuildInputs = with pkgs; [
ncurses
cmake
pkg-config
autoPatchelfHook
];

runtimeDependencies = rlinkLibs;
buildInputs = rlinkLibs;
cargoLock.lockFile = ./Cargo.lock;

meta = {
description = "A hardware-accelerated GPU terminal emulator powered by WebGPU";
homepage = "https://raphamorim.io/rio";
license = lib.licenses.mit;
platforms = lib.platforms.unix;
changelog = "https://github.com/raphamorim/rio/blob/master/CHANGELOG.md";
mainProgram = "rio";
};
});
in
{
overlays.default = final: prev: {
rio = prev.callPackage mkRio { };
};

# `nix build` works
packages = eachSystem (system: {
default = pkgsFor.${system}.callPackage mkRio { };
});

# `nix develop` works
devShells = eachSystem (system:
let
rust-toolchain = (pkgsFor.${system}.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = [ "rust-src" "rust-analyzer" ];
};
in
{
default = pkgsFor.${system}.mkShell rec {
packages = with pkgsFor.${system}; if stdenv.isDarwin then [
darwin.libobjc
darwin.apple_sdk_11_0.frameworks.AppKit
darwin.apple_sdk_11_0.frameworks.AVFoundation
darwin.apple_sdk_11_0.frameworks.Vision
] else [
fontconfig
libGL
libxkbcommon
vulkan-loader
ncurses
cmake
pkg-config
autoPatchelfHook
rust-toolchain
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
xorg.libxcb
wayland
];

LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${builtins.toString (pkgsFor.${system}.lib.makeLibraryPath packages)}";
};
}
);
};
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
[toolchain]
channel = "1.73.0"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]
targets = ["wasm32-unknown-unknown"]