From 45c3e91560e2b17c857461d229663c6e8b6a0a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Du=C3=9Fin?= Date: Thu, 22 Aug 2024 12:48:30 +0200 Subject: [PATCH] chore: Add nix build files --- derivation.nix | 17 +++++++++++++++ flake.lock | 48 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 53 +++++++++++++++++++++++++++++++++++++++++++++ rust_toolchain.toml | 3 +++ 4 files changed, 121 insertions(+) create mode 100644 derivation.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust_toolchain.toml diff --git a/derivation.nix b/derivation.nix new file mode 100644 index 0000000..d6de351 --- /dev/null +++ b/derivation.nix @@ -0,0 +1,17 @@ +{ + lib, + pkgs, + rustPlatform, + name, +}: +(rustPlatform.buildRustPackage { + inherit name; + + nativeBuildInputs = with pkgs; [ + ]; + + src = lib.cleanSource ./.; + cargoLock = { + lockFile = ./Cargo.lock; + }; +}) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9590a3a --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1724322575, + "narHash": "sha256-kRYwAdYsaICNb2WYcWtBFG6caSuT0v/vTAyR8ap0IR0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2a02822b466ffb9f1c02d07c5dd6b96d08b56c6b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1724293269, + "narHash": "sha256-x/XhOAszT/ejditCHUtGOjQcVg2AQhrC/QVew3i7kTI=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "6dc6d34a3a217457d7044dcce32b6d537480a6a1", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..87a0757 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "Light control over the network"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/release-24.05"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, rust-overlay }: + let + inherit (nixpkgs) lib; + systems = ["x86_64-linux"]; + systemClosure = attrs: + builtins.foldl' (acc: system: + lib.recursiveUpdate acc (attrs system)) {} + systems; + in + systemClosure (system: + let + inherit ((builtins.fromTOML (builtins.readFile ./Cargo.toml)).package) name; + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + toolchain = ( + pkgs.rust-bin.fromRustupToolchainFile ./rust_toolchain.toml + ); + rustPlatform = pkgs.makeRustPlatform + { + rustc = toolchain; + cargo = toolchain; + }; + libPath = with pkgs; lib.makeLibraryPath [ + ]; + in + { + packages.${system}.default = pkgs.callPackage ./derivation.nix { + inherit name rustPlatform; + }; + + devShells.${system}.default = pkgs.mkShell { + buildInputs = with pkgs; [ + toolchain + clang + llvmPackages.bintools + ]; + + LD_LIBRARY_PATH = libPath; + }; + }); +} diff --git a/rust_toolchain.toml b/rust_toolchain.toml new file mode 100644 index 0000000..b5ae49d --- /dev/null +++ b/rust_toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly-2024-06-15" +components = ["rust-src", "rust-analyzer"]