From ca14ff1fefdd5d9228466a932048fed711d0b5eb Mon Sep 17 00:00:00 2001 From: j4ger Date: Mon, 23 Dec 2024 16:01:47 +0800 Subject: [PATCH 1/2] Add a devShell for webapp development --- flake.lock | 80 ++++++++++++++++++++++++++++++++++++++---------------- flake.nix | 40 ++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 25 deletions(-) diff --git a/flake.lock b/flake.lock index 2b411256e5..4da110ab30 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1722555600, - "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", "type": "github" }, "original": { @@ -18,41 +18,72 @@ "type": "github" } }, - "nixpkgs": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, "locked": { - "lastModified": 1724395761, - "narHash": "sha256-zRkDV/nbrnp3Y8oCADf5ETl1sDrdmAW6/bBVJ8EbIdQ=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "ae815cee91b417be55d43781eb4b73ae1ecc396c", + "lastModified": 1733346208, + "narHash": "sha256-a4WZp1xQkrnA4BbnKrzJNr+dYoQr5Xneh2syJoddFyE=", + "owner": "nix-community", + "repo": "naersk", + "rev": "378614f37a6bee5a3f2ef4f825a73d948d3ae921", "type": "github" }, "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", + "owner": "nix-community", + "repo": "naersk", "type": "github" } }, + "nixpkgs": { + "locked": { + "lastModified": 1733759999, + "narHash": "sha256-463SNPWmz46iLzJKRzO3Q2b0Aurff3U1n0nYItxq7jU=", + "path": "/nix/store/yw6kg4rb9v8s3ypjbpspig5r81m4lr5s-source", + "rev": "a73246e2eef4c6ed172979932bc80e1404ba2d56", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, "nixpkgs-lib": { "locked": { - "lastModified": 1722555339, - "narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=", + "lastModified": 1733096140, + "narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" } }, "nixpkgs_2": { "locked": { - "lastModified": 1718428119, - "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", + "lastModified": 1734435836, + "narHash": "sha256-kMBQ5PRiFLagltK0sH+08aiNt3zGERC2297iB6vrvlU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4989a246d7a390a859852baddb1013f825435cee", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", "type": "github" }, "original": { @@ -65,21 +96,22 @@ "root": { "inputs": { "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", "rust-overlay": "rust-overlay", "systems": "systems" } }, "rust-overlay": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1724638882, - "narHash": "sha256-ap2jIQi/FuUHR6HCht6ASWhoz8EiB99XmI8Esot38VE=", + "lastModified": 1734834660, + "narHash": "sha256-bm8V+Cu8rWJA+vKQnc94mXTpSDgvedyoDKxTVi/uJfw=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "19b70f147b9c67a759e35824b241f1ed92e46694", + "rev": "b070e6030118680977bc2388868c4b3963872134", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index f903e8635c..53ba19bcdd 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,7 @@ nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; systems.url = "github:nix-systems/default"; + naersk.url = "github:nix-community/naersk"; rust-overlay.url = "github:oxalica/rust-overlay"; # crane.url = "github:ipetkov/crane"; @@ -43,7 +44,7 @@ # This is useful when building crates as packages # Note that it does require a `Cargo.lock` which this repo does not have # craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain; - in + in rec { _module.args.pkgs = import inputs.nixpkgs { inherit system; @@ -52,6 +53,14 @@ ]; }; + packages.dx = let + naersk' = pkgs.callPackage inputs.naersk {}; + in naersk'.buildPackage { + name = "dioxus-cli"; + src = ./.; + cargoBuildOptions = prev: prev ++ [ "-p" "dioxus-cli" ]; + }; + devShells.default = pkgs.mkShell { name = "dioxus-dev"; buildInputs = rustBuildInputs; @@ -64,6 +73,35 @@ export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library"; ''; }; + + devShells.web = pkgs.mkShell { + name = "dioxus-web-devShell"; + buildInputs = with pkgs; [ + openssl + pkg-config + cacert + + (rust-bin.stable.latest.default.override { + extensions = [ "rust-src" "rust-analyzer" "rust-std" ]; + targets = [ "wasm32-unknown-unknown" ]; + }) + (pkgs.writeShellApplication { + name = "rustup"; + text = '' + #!/bin/sh + echo "installed targets for active toolchain" + echo "--------------------------------------" + echo "wasm32-unknown-unknown" + echo "x86_64-unknown-linux-gnu" + ''; + }) # mock rustup to pass dx toolchain verification + packages.dx + ]; + shellHook = '' + + ''; + }; + }; }; } From a70fc8ec36ac0e29caa6afb64e204c83091151ad Mon Sep 17 00:00:00 2001 From: j4ger Date: Sat, 28 Dec 2024 17:53:55 +0800 Subject: [PATCH 2/2] Fix `nix run` related meta issue --- flake.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake.nix b/flake.nix index 53ba19bcdd..bb9fc586f7 100644 --- a/flake.nix +++ b/flake.nix @@ -59,6 +59,10 @@ name = "dioxus-cli"; src = ./.; cargoBuildOptions = prev: prev ++ [ "-p" "dioxus-cli" ]; + + meta = { + mainProgram = "dx"; + }; }; devShells.default = pkgs.mkShell {