From e25a5635558ab6323104bd0b639d8442f3658be8 Mon Sep 17 00:00:00 2001 From: 71rd Date: Mon, 20 May 2024 01:21:10 +0000 Subject: [PATCH 1/5] 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}"; + }; + }); +} From c98931959f10449081a6bc7edb7b854f439a10ce Mon Sep 17 00:00:00 2001 From: 71rd Date: Thu, 6 Jun 2024 15:26:38 +0000 Subject: [PATCH 2/5] nix: move build support to dir, add .envrc for using nix dev env --- .envrc | 1 + build/nix/README.md | 1 - build.nix => build/nix/build.nix | 9 +++-- build/nix/default.nix | 48 +------------------------ build/nix/flake.lock | 48 +++++++++++++++++++++---- build/nix/flake.nix | 49 ++++++++++++++++++++----- default.nix | 1 - flake.lock | 61 -------------------------------- flake.nix | 48 ------------------------- 9 files changed, 90 insertions(+), 176 deletions(-) create mode 100644 .envrc delete mode 100644 build/nix/README.md rename build.nix => build/nix/build.nix (88%) delete mode 100644 default.nix delete mode 100644 flake.lock delete mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1972867 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake ./build/nix diff --git a/build/nix/README.md b/build/nix/README.md deleted file mode 100644 index e424bd6..0000000 --- a/build/nix/README.md +++ /dev/null @@ -1 +0,0 @@ -This is a work-in-progress nix package. It successfully worked on one NixOS system, but failed on another due to obscure errors. It also failed using "nix build" on ArchLinux. diff --git a/build.nix b/build/nix/build.nix similarity index 88% rename from build.nix rename to build/nix/build.nix index 62e067c..f4cd23e 100644 --- a/build.nix +++ b/build/nix/build.nix @@ -27,7 +27,7 @@ assert (platform == "linux" ) -> (enableVulkan || enableOpenGL); rustPlatform.buildRustPackage rec { name = "outfly"; inherit buildType; - src = ./.; + src = ./../..; version = if (self ? rev) then self.rev else "dirty"; buildNoDefaultFeatures = true; @@ -50,12 +50,17 @@ rustPlatform.buildRustPackage rec { --add-rpath ${lib.makeLibraryPath runtimeInputs} ''; - cargoLock = { lockFile = ./Cargo.lock; }; + postPatch = '' + find ../cargo-vendor-dir -name Cargo.toml -exec sed -i 's/^workspace = true//' {} + + ''; + + cargoLock = { lockFile = ./../../Cargo.lock; }; desktopItems = [ (makeDesktopItem { name = "outfly"; exec = "outfly"; + desktopName = "OutFly"; categories = [ "Game" ]; }) diff --git a/build/nix/default.nix b/build/nix/default.nix index af58bda..3eb8439 100644 --- a/build/nix/default.nix +++ b/build/nix/default.nix @@ -1,47 +1 @@ -{ - rustPlatform, - pkg-config, - alsa-lib, - libcap, - libxkbcommon, - wayland, - udev, - vulkan-loader, - xorg, - lib, -}: -rustPlatform.buildRustPackage rec { - src = ../../..; - pname = "outfly"; - version = "0.8.1"; - cargoLock = { - lockFile = "${src}/Cargo.lock"; - }; - nativeBuildInputs = [ pkg-config ]; - - buildNoDefaultFeatures = true; - buildFeatures = [ - "release_linux" - ]; - buildInputs = [ - alsa-lib - libcap - wayland - ]; - postFixup = - let - runtimeDeps = [ - vulkan-loader - libxkbcommon - xorg.libX11 - xorg.libXrandr - xorg.libXi - xorg.libXcursor - ]; - libPath = lib.makeLibraryPath runtimeDeps; - in - '' - patchelf $out/bin/outfly \ - --add-rpath ${libPath} - ''; -} +with import { }; callPackage ./build.nix { version = "0.7.1"; } diff --git a/build/nix/flake.lock b/build/nix/flake.lock index a8dd10e..f3856ec 100644 --- a/build/nix/flake.lock +++ b/build/nix/flake.lock @@ -1,16 +1,34 @@ { "nodes": { - "nixpkgs": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1714076141, - "narHash": "sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { - "owner": "nixos", + "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" @@ -18,8 +36,24 @@ }, "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", diff --git a/build/nix/flake.nix b/build/nix/flake.nix index 09f2afd..00bfec2 100644 --- a/build/nix/flake.nix +++ b/build/nix/flake.nix @@ -1,17 +1,48 @@ { - description = "A breathtaking 3D space game in the rings of Jupiter"; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + 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; - outputs = { self, nixpkgs }: { + apps.outfly = { + type = "app"; + program = "${self.packages.${system}.outfly}/bin/outfly"; + }; + apps.default = self.apps.${system}.outfly; - packages.x86_64-linux.outfly = let - pkgs = import nixpkgs { system = "x86_64-linux"; }; - in pkgs.callPackage ./default.nix {}; + devShells.default = let + buildInputs = [ + pkgs.alsa-lib.dev - packages.x86_64-linux.default = self.packages.x86_64-linux.outfly; + #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}"; + }; + }); } diff --git a/default.nix b/default.nix deleted file mode 100644 index 3eb8439..0000000 --- a/default.nix +++ /dev/null @@ -1 +0,0 @@ -with import { }; callPackage ./build.nix { version = "0.7.1"; } diff --git a/flake.lock b/flake.lock deleted file mode 100644 index f3856ec..0000000 --- a/flake.lock +++ /dev/null @@ -1,61 +0,0 @@ -{ - "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 deleted file mode 100644 index 00bfec2..0000000 --- a/flake.nix +++ /dev/null @@ -1,48 +0,0 @@ -{ - 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}"; - }; - }); -} From df85f4bd08f1cf87fd4a4cd0d0e2b62282966058 Mon Sep 17 00:00:00 2001 From: 71rd Date: Fri, 7 Jun 2024 23:23:49 +0000 Subject: [PATCH 3/5] nix: default remove hardcoded version --- build/nix/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/nix/default.nix b/build/nix/default.nix index 3eb8439..87c1095 100644 --- a/build/nix/default.nix +++ b/build/nix/default.nix @@ -1 +1 @@ -with import { }; callPackage ./build.nix { version = "0.7.1"; } +with import { }; callPackage ./build.nix { } From d51fd52a24d3d8671c523dfc1d4a45bc6a2052f7 Mon Sep 17 00:00:00 2001 From: 71rd Date: Thu, 27 Jun 2024 13:38:23 +0000 Subject: [PATCH 4/5] nix: remove hardcoded version from flake --- build/nix/flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/nix/flake.nix b/build/nix/flake.nix index 00bfec2..3a2a3af 100644 --- a/build/nix/flake.nix +++ b/build/nix/flake.nix @@ -9,7 +9,7 @@ overlays = [ ]; pkgs = import nixpkgs { inherit system overlays; }; in { - packages.outfly = pkgs.callPackage ./build.nix { version = "0.7.0"; }; + packages.outfly = pkgs.callPackage ./build.nix {}; packages.default = self.packages.${system}.outfly; apps.outfly = { From 0c8a626e73679b2ff3bba1e48d5e74932e6774d7 Mon Sep 17 00:00:00 2001 From: 71rd Date: Tue, 30 Jul 2024 17:01:11 +0000 Subject: [PATCH 5/5] nix: update inputs for rust 1.79 --- build/nix/flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/nix/flake.lock b/build/nix/flake.lock index f3856ec..fac9dc7 100644 --- a/build/nix/flake.lock +++ b/build/nix/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1713248628, - "narHash": "sha256-NLznXB5AOnniUtZsyy/aPWOk8ussTuePp2acb9U+ISA=", + "lastModified": 1722185531, + "narHash": "sha256-veKR07psFoJjINLC8RK4DiLniGGMgF3QMlS4tb74S6k=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5672bc9dbf9d88246ddab5ac454e82318d094bb8", + "rev": "52ec9ac3b12395ad677e8b62106f0b98c1f8569d", "type": "github" }, "original": {