From e25a5635558ab6323104bd0b639d8442f3658be8 Mon Sep 17 00:00:00 2001 From: 71rd Date: Mon, 20 May 2024 01:21:10 +0000 Subject: [PATCH] nix: init flake with release and shell and default --- build.nix | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ default.nix | 1 + flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 48 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 build.nix create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/build.nix b/build.nix new file mode 100644 index 0000000..62e067c --- /dev/null +++ b/build.nix @@ -0,0 +1,64 @@ +{ lib +, self ? null +, buildType ? "release" +, platform ? "linux" +, enableWayland ? true +, enableXorg ? true +, enableOpenGL ? true +, enableVulkan ? true +, rustPlatform +, makeDesktopItem +, pkg-config +, libxkbcommon +, alsa-lib +, libGL +, vulkan-loader +, wayland +, libXrandr +, libXcursor +, libX11 +, libXi +, ... +}: + +assert (platform == "linux" ) -> (enableWayland || enableXorg); +assert (platform == "linux" ) -> (enableVulkan || enableOpenGL); + +rustPlatform.buildRustPackage rec { + name = "outfly"; + inherit buildType; + src = ./.; + version = if (self ? rev) then self.rev else "dirty"; + + buildNoDefaultFeatures = true; + buildFeatures = [ "embed_assets" ] ++ lib.optionals enableXorg [ "x11" ] + ++ lib.optionals enableWayland [ "wayland" ]; + + runtimeInputs = [ libxkbcommon ] + ++ lib.optionals enableOpenGL [ libGL ] + ++ lib.optionals enableXorg [ libXrandr libX11 ] + ++ lib.optionals enableVulkan [ vulkan-loader ]; + + buildInputs = [ alsa-lib.dev libXcursor libXi ] + ++ lib.optionals enableWayland [ wayland ]; + + nativeBuildInputs = [ pkg-config ]; + doCheck = false; + + postFixup = '' + patchelf $out/bin/outfly \ + --add-rpath ${lib.makeLibraryPath runtimeInputs} + ''; + + cargoLock = { lockFile = ./Cargo.lock; }; + + desktopItems = [ + (makeDesktopItem { + name = "outfly"; + exec = "outfly"; + desktopName = "OutFly"; + categories = [ "Game" ]; + }) + ]; +} + diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..3eb8439 --- /dev/null +++ b/default.nix @@ -0,0 +1 @@ +with import { }; callPackage ./build.nix { version = "0.7.1"; } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f3856ec --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1713248628, + "narHash": "sha256-NLznXB5AOnniUtZsyy/aPWOk8ussTuePp2acb9U+ISA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5672bc9dbf9d88246ddab5ac454e82318d094bb8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..00bfec2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,48 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ ]; + pkgs = import nixpkgs { inherit system overlays; }; + in { + packages.outfly = pkgs.callPackage ./build.nix { version = "0.7.0"; }; + packages.default = self.packages.${system}.outfly; + + apps.outfly = { + type = "app"; + program = "${self.packages.${system}.outfly}/bin/outfly"; + }; + apps.default = self.apps.${system}.outfly; + + devShells.default = let + buildInputs = [ + pkgs.alsa-lib.dev + + #opengl + pkgs.libGL + + pkgs.libxkbcommon + + pkgs.xorg.libXcursor + pkgs.xorg.libXi + pkgs.xorg.libXrandr + pkgs.xorg.libX11 + + pkgs.vulkan-loader + ]; + nativeBuildInputs = [ + pkgs.cargo + pkgs.pkg-config + + ]; + + in pkgs.mkShell { + inherit buildInputs nativeBuildInputs; + LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}"; + }; + }); +}