Skip to content

Commit

Permalink
chore(nix): Switch to rust-flake
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Apr 19, 2024
1 parent 83b5646 commit a4b8d5c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 58 deletions.
66 changes: 43 additions & 23 deletions flake.lock

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

17 changes: 3 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";

rust-overlay.url = "github:oxalica/rust-overlay";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
rust-flake.url = "github:juspay/rust-flake";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
cargo-doc-live.url = "github:srid/cargo-doc-live";

dioxus-desktop-template.url = "github:srid/dioxus-desktop-template";
dioxus-desktop-template.flake = false;
};

outputs = inputs:
Expand All @@ -30,7 +25,8 @@
inputs.treefmt-nix.flakeModule
inputs.process-compose-flake.flakeModule
inputs.cargo-doc-live.flakeModule
(inputs.dioxus-desktop-template + /nix/flake-module.nix)
inputs.rust-flake.flakeModules.default
inputs.rust-flake.flakeModules.nixpkgs
./rust.nix
];

Expand All @@ -48,13 +44,6 @@
};

perSystem = { config, self', pkgs, lib, system, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.rust-overlay.overlays.default
];
};

# Add your auto-formatters here.
# cf. https://numtide.github.io/treefmt/
treefmt.config = {
Expand Down
77 changes: 56 additions & 21 deletions rust.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
# Nix module for the Rust part of the project
#
# This uses https://github.com/srid/dioxus-desktop-template/blob/master/nix/flake-module.nix
# This uses Crane, via https://github.com/juspay/rust-flake
{
perSystem = { config, self', pkgs, lib, system, ... }: {
dioxus-desktop = {
overrideCraneArgs = oa: {
nativeBuildInputs = (oa.nativeBuildInputs or [ ]) ++ [
rust-project = {
crane.args = {
buildInputs = lib.optionals pkgs.stdenv.isLinux
(with pkgs; [
webkitgtk_4_1
xdotool
pkg-config
]) ++ lib.optionals pkgs.stdenv.isDarwin (
with pkgs.darwin.apple_sdk.frameworks; [
IOKit
Carbon
WebKit
Security
Cocoa
# Use newer SDK because some crates require it
# cf. https://github.com/NixOS/nixpkgs/pull/261683#issuecomment-1772935802
pkgs.darwin.apple_sdk_11_0.frameworks.CoreFoundation
]
);
nativeBuildInputs = with pkgs;[
pkg-config
makeWrapper
tailwindcss
dioxus-cli
pkgs.nix # cargo tests need nix
];
meta.description = "WIP: nix-browser";
};
rustBuildInputs = lib.optionals pkgs.stdenv.isLinux
(with pkgs; [
webkitgtk_4_1
pkg-config
]) ++ lib.optionals pkgs.stdenv.isDarwin (
with pkgs.darwin.apple_sdk.frameworks; [
IOKit
Carbon
WebKit
Security
Cocoa
# Use newer SDK because some crates require it
# cf. https://github.com/NixOS/nixpkgs/pull/261683#issuecomment-1772935802
pkgs.darwin.apple_sdk_11_0.frameworks.CoreFoundation
]
);

src = lib.cleanSourceWith {
src = inputs.self; # The original, unfiltered source
filter = path: type:
(lib.hasSuffix "\.html" path) ||
(lib.hasSuffix "tailwind.config.js" path) ||
# Example of a folder for images, icons, etc
(lib.hasInfix "/assets/" path) ||
(lib.hasInfix "/css/" path) ||
# Default filter from crane (allow .rs files)
(config.rust-project.crane.lib.filterCargoSources path type)
;
};
};

packages.default = self'.packages.nix-browser;
packages.default = self'.packages.nix-browser.overrideAttrs (oa: {
# Copy over assets for the desktop app to access
installPhase =
(oa.installPhase or "") + ''
cp -r ./assets/* $out/bin/
'';
postFixup =
(oa.postFixup or "") + ''
# HACK: The Linux desktop app is unable to locate the assets
# directory, but it does look into the current directory.
# So, `cd` to the directory containing assets (which is
# `bin/`, per the installPhase above) before launching the
# app.
wrapProgram $out/bin/${config.rust-project.cargoToml.package.name} \
--chdir $out/bin
'';
});
;

devShells.rust = pkgs.mkShell {
inputsFrom = [
Expand Down

0 comments on commit a4b8d5c

Please sign in to comment.