nix: init flake with release and shell and default

This commit is contained in:
71rd 2024-05-20 01:21:10 +00:00
parent 0af4b7dab9
commit e25a563555
4 changed files with 174 additions and 0 deletions

64
build.nix Normal file
View file

@ -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" ];
})
];
}

1
default.nix Normal file
View file

@ -0,0 +1 @@
with import <nixpkgs> { }; callPackage ./build.nix { version = "0.7.1"; }

61
flake.lock Normal file
View file

@ -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
}

48
flake.nix Normal file
View file

@ -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}";
};
});
}