From c23f69ae144de9b294034170173da9405320f5fb Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Thu, 7 Nov 2024 23:24:41 +0100 Subject: [PATCH] wip nix flake --- README.md | 4 ++- flake.nix | 87 ++++++++++++++++++++++++++++++++++++++----------------- shell.nix | 40 ------------------------- 3 files changed, 64 insertions(+), 67 deletions(-) delete mode 100644 shell.nix diff --git a/README.md b/README.md index 2485bf3..ce48083 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ The screenshot above shows the output of two example projects running in paralle ## Running -Check out this repository and run `cargo run --release`. +With nix flakes: `nix run github:kaesaecracker/servicepoint-simulator` + +Without nix: check out this repository and use `cargo run --release`. ## Command line arguments diff --git a/flake.nix b/flake.nix index ced5161..08c3c0b 100644 --- a/flake.nix +++ b/flake.nix @@ -8,37 +8,72 @@ outputs = inputs@{ self, nixpkgs }: let - servicepoint-simulator = nixpkgs.legacyPackages.x86_64-linux.rustPlatform.buildRustPackage rec { - pname = "servicepoint-simulator"; - version = "0.0.1"; - - src = ./.; # TODO: src, Cargo.toml etc - - buildInputs = [ - - ]; - nativeBuildInputs = with nixpkgs.legacyPackages.x86_64-linux; [ pkg-config ]; - #cargoSha256 = "sha256-0hfmV4mbr3l86m0X7EMYTOu/b+BjueVEbbyQz0KgOFY="; - cargoLock.lockFile = ./Cargo.lock; - - meta = with nixpkgs.stdenv.lib; { - homepage = ""; - description = ""; - #license = licenses.gplv3; - }; - - }; + lib = nixpkgs.lib; + forAllSystems = lib.genAttrs lib.systems.flakeExposed; in rec { - packages.x86_64-linux.default = servicepoint-simulator; + packages = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages."${system}"; + in + { + default = pkgs.rustPlatform.buildRustPackage { + pname = "servicepoint-simulator"; + version = "0.0.1"; + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; + + src = ./.; + + nativeBuildInputs = with pkgs; [ pkg-config ]; + + buildInputs = + with pkgs; + [ + xe + lzma + ] + ++ (lib.optionals pkgs.stdenv.isLinux ( + with pkgs; + [ + xorg.libxkbfile + wayland + libxkbcommon + ] + )); + + meta = with lib; { + homepage = ""; + description = ""; + license = licenses.gpl3; + }; + }; + } + ); legacyPackages = packages; - devShells.x86_64-linux.default = import ./shell.nix { pkgs = nixpkgs.legacyPackages.x86_64-linux; }; + devShells = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages."${system}"; + in + { + default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + packages = with pkgs; [ + rustfmt + cargo-expand + ]; + #LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath buildInputs}"; + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + }; + } + ); - formatter = { - x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style; - aarch64-linux = nixpkgs.legacyPackages.aarch64-linux.nixfmt-rfc-style; - }; + formatter = forAllSystems (system: nixpkgs.legacyPackages."${system}".nixfmt-rfc-style); }; } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index ceff669..0000000 --- a/shell.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ - pkgs ? import { }, -}: -let - rust-toolchain = pkgs.symlinkJoin { - name = "rust-toolchain"; - paths = with pkgs; [ - rustc - cargo - rustPlatform.rustcSrc - rustfmt - clippy - cargo-expand - ]; - }; -in -pkgs.mkShell { - nativeBuildInputs = with pkgs.buildPackages; [ - rust-toolchain - - pkg-config - xe - lzma - - # linux x11 / wayland - libxkbcommon - #xorg.libxkbfile - wayland - ]; - - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; - - LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath ( - with pkgs; - [ - wayland - libxkbcommon - ] - ); -}