iced icon indicating copy to clipboard operation
iced copied to clipboard

Flake.nix example has example code to allow easy building with nix

Open makuru-org opened this issue 7 months ago • 2 comments

I have added some example code to allow the easy building with Nix and packaging for NixOS.

makuru-org avatar May 10 '25 16:05 makuru-org

Still need to test x11 compatibility.

makuru-org avatar May 10 '25 16:05 makuru-org

I actually wanted to make a pr to update this as well but it feels like you've over complicated it. Here's my flake, regardless I'd like the packaging info for comet and cargo hot to make it in. I know there's some disagree about using cachex's software but overall it makes the process easier and you get mold as your default linker which is nice.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    devenv.url = "github:cachix/devenv";

    comet = {
      url = "github:iced-rs/comet";
      flake = false;
    };

    cargo-hot = {
      url = "github:hecrj/cargo-hot";
      flake = false;
    };
  };

  outputs =
    inputs@{ flake-parts, nixpkgs, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [ inputs.devenv.flakeModule ];
      systems = nixpkgs.lib.systems.flakeExposed;

      perSystem =
        {
          lib,
          pkgs,
          ...
        }:
        let
          iced_comet = pkgs.rustPlatform.buildRustPackage {
            pname = "iced_comet";
            version = "0.14.0-dev"; # Update this to match your package version
            src = inputs.comet;
            cargoLock = {
              lockFile = "${inputs.comet}/Cargo.lock";
              outputHashes = {
                "cryoglyph-0.1.0" = "sha256-X7S9jq8wU6g1DDNEzOtP3lKWugDnpopPDBK49iWvD4o=";
                "dpi-0.1.1" = "sha256-hlVhlQ8MmIbNFNr6BM4edKdZbe+ixnPpKm819zauFLQ=";
                "iced-0.14.0-dev" = "sha256-Thoqj1WY+48VqRkPEJVOkHs3g/pt6MEzg1J7pdogKzA=";
                "iced_palace-0.14.0-dev" = "sha256-OcFPDxp8GBUvQaX0SU1I/b2enIIqKgaLdGvmHHrKrp4=";
              };
            };
            nativeBuildInputs = with pkgs; [ pkg-config ];
            buildInputs = with pkgs; [ openssl ];
          };

          cargo-hot = pkgs.rustPlatform.buildRustPackage {
            pname = "cargo-hot";
            version = "0.1.0"; # Update this to match your package version
            src = inputs.cargo-hot;
            cargoLock = {
              lockFile = "${inputs.cargo-hot}/Cargo.lock";
              outputHashes = { };
            };
            nativeBuildInputs = with pkgs; [ pkg-config ];
            buildInputs = with pkgs; [ openssl ];
          };
        in
        {
          # Per-system attributes can be defined here. The self' and inputs'
          # module parameters provide easy access to attributes of the same
          # system.
          devenv.shells.default = {
            # https://devenv.sh/reference/options/
            dotenv.disableHint = true;

            languages.rust.enable = true;
            packages = with pkgs; [
              cargo-hot
              iced_comet
              openssl
              pkg-config
              tokio-console
            ];

            env = {
              LD_LIBRARY_PATH = lib.makeLibraryPath (
                with pkgs;
                [
                  libGL
                  libxkbcommon
                  vulkan-loader
                  wayland
                  xorg.libXcursor
                  xorg.libXrandr
                  xorg.libXi
                  xorg.libX11
                ]
              );
              ICED_BACKEND = "wgpu"; # wgpu or tiny-skia
              RUST_LOG = "info";
            };
          };
        };
    };
}

This file will automatically enter the shell once you ssh into the directory.

if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
  source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

watch_file devenv.nix
watch_file devenv.lock
watch_file devenv.yaml
if ! use flake . --impure
then
  echo "devenv could not be build. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi

Redhawk18 avatar Jun 15 '25 16:06 Redhawk18