From 1b159318a9174e1fa5eb5027044f25d71a369933 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sat, 23 Nov 2024 13:45:55 +0100 Subject: [PATCH] Use flake --- .envrc | 1 + flake.lock | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 62 ++++++++++++++++++++++++++++++++++++++++ shell.nix | 27 ------------------ 4 files changed, 146 insertions(+), 27 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..3550a30f2d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..77581733ec --- /dev/null +++ b/flake.lock @@ -0,0 +1,83 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1730504689, + "narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "506278e768c2a08bec68eb62932193e341f55c90", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1732014248, + "narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "23e89b7da85c3640bbc2173fe04f4bd114342367", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1732328983, + "narHash": "sha256-RHt12f/slrzDpSL7SSkydh8wUE4Nr4r23HlpWywed9E=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ed8aa5b64f7d36d9338eb1d0a3bb60cf52069a72", + "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 0000000000..9597821caa --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = + inputs@{ self, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + _module.args.pkgs = import self.inputs.nixpkgs { + inherit system; + overlays = [ + (import inputs.rust-overlay) + ]; + }; + devShells.default = + let + libPath = + with pkgs; + lib.makeLibraryPath [ + pkg-config + openssl + ]; + in + pkgs.mkShell { + inputsFrom = builtins.attrValues self'.packages; + packages = with pkgs; [ + # (rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)) + pkg-config + openssl + cargo + cargo-watch + rustc + rust-analyzer + clippy + ]; + LD_LIBRARY_PATH = libPath; + RUST_BACKTRACE = 1; + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + }; + }; + }; +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index fa7b78072a..0000000000 --- a/shell.nix +++ /dev/null @@ -1,27 +0,0 @@ -/* -based on -https://discourse.nixos.org/t/how-can-i-set-up-my-rust-programming-environment/4501/9 -*/ -let - rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"); - pkgs = import { overlays = [ rust_overlay ]; }; - rustVersion = "latest"; # using a specific version: "1.62.0" - rust = pkgs.rust-bin.stable.${rustVersion}.default.override { - extensions = [ - "rust-src" # for rust-analyzer - "rust-analyzer" # usable by IDEs like zed-editor - ]; - }; -in -pkgs.mkShell { - buildInputs = [ - rust - ] ++ (with pkgs; [ - pkg-config - openssl - # other dependencies - #gtk3 - #wrapGAppsHook - ]); - RUST_BACKTRACE = 1; -}