From e3fc0a1150241d1c6be48319f3f48f9f229b97ae Mon Sep 17 00:00:00 2001 From: Max Audron Date: Wed, 2 Aug 2023 14:07:52 +0200 Subject: setup new nix flake using crane --- flake.nix | 166 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 80 insertions(+), 86 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index de34969..f616506 100644 --- a/flake.nix +++ b/flake.nix @@ -1,116 +1,110 @@ { nixConfig = { substituters = - [ "https://cache.nixos.org/" "https://nix-community.cachix.org" "https://nix.cache.vapor.systems" ]; + [ "https://cache.nixos.org/" "https://nix-community.cachix.org" ]; trusted-public-keys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "nix.cache.vapor.systems-1:OjV+eZuOK+im1n8tuwHdT+9hkQVoJORdX96FvWcMABk=" ]; }; inputs = { - nixpkgs.url = "github:nixos/nixpkgs"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; + + fenix = { + url = "github:nix-community/fenix"; inputs.nixpkgs.follows = "nixpkgs"; }; - naersk = { - url = "github:nmattia/naersk"; + + crane = { + url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; }; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, rust-overlay, utils, naersk }: + outputs = { self, nixpkgs, utils, fenix, crane, advisory-db }: with nixpkgs.lib; - recursiveUpdate (utils.lib.eachDefaultSystem (system: + utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - rust = rust-overlay.packages."${system}".rust; - - naersk-lib = naersk.lib."${system}".override { - cargo = rust; - rustc = rust; - }; - in rec { - packages.default = packages.gtree; - - packages.gtree = naersk-lib.buildPackage { - pname = "gtree"; - root = ./.; - - nativeBuildInputs = [ pkgs.perl ]; - - cargoBuildOptions = prev: - prev ++ [ "--features=vendored-libgit2,vendored-openssl" ]; - }; - - apps.default = utils.lib.mkApp { drv = packages.default; }; - - devShell = pkgs.mkShell { nativeBuildInputs = [ rust pkgs.perl ]; }; - })) (utils.lib.eachSystem [ - utils.lib.system.x86_64-linux - utils.lib.system.aarch64-linux - ] (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - - staticInputs = with pkgs; [ - pkgsStatic.stdenv.cc - pkgsStatic.openssl.dev - rust - perl + rustToolchain = with fenix.packages.${system}; + combine ([ latest.toolchain ] ++ (if system == "x86_64-linux" then + [ targets.x86_64-unknown-linux-musl.latest.rust-std ] + else + [ ])); + + nativeBuildInputs = with pkgs; + [ + rustToolchain + pkg-config + + pkgsStatic.openssl + ] ++ lib.optional stdenv.isDarwin [ + pkgs.libiconv + pkgs.darwin.apple_sdk.frameworks.Security ]; - target = - "${elemAt (strings.splitString "-" system) 0}-unknown-linux-musl"; - - rust = rust-overlay.packages."${system}".rust.override { - extensions = [ "rust-src" ]; - targets = [ target ]; - }; + OPENSSL_DIR = "${pkgs.pkgsStatic.openssl}"; + OPENSSL_LIB_DIR = "${pkgs.pkgsStatic.openssl.out}/lib"; + OPENSSL_CRYPTO_LIBRARY = "${pkgs.pkgsStatic.openssl.out}/lib"; + OPENSSL_INCLUDE_DIR = "${pkgs.pkgsStatic.openssl.dev}/include"; + CARGO_BUILD_TARGET = if system == "x86_64-linux" then + "x86_64-unknown-linux-musl" + else + null; + CARGO_BUILD_RUSTFLAGS = if system == "x86_64-linux" then + "-C target-feature=+crt-static" + else + null; + + graphqlFilter = path: _type: builtins.match ".*graphql$" path != null; + markdownFilter = path: _type: builtins.match ".*md$" path != null; + markdownOrCargo = path: type: + (graphqlFilter path type) || (markdownFilter path type) + || (craneLib.filterCargoSources path type); + + # crane setup + craneLib = crane.lib.${system}.overrideToolchain rustToolchain; + src = nixpkgs.lib.cleanSourceWith { + src = craneLib.path ./.; # The original, unfiltered source + filter = markdownOrCargo; + }; - naersk-lib = naersk.lib."${system}".override { - cargo = rust; - rustc = rust; + cargoArtifacts = self.packages.${system}.cargoArtifacts; + in { + packages = { + cargoArtifacts = craneLib.buildDepsOnly { + inherit src; + inherit nativeBuildInputs OPENSSL_DIR OPENSSL_LIB_DIR + OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR CARGO_BUILD_TARGET + CARGO_BUILD_RUSTFLAGS; }; - gitlab-upload = makeBinScript "gitlab-upload" '' - ${pkgs.curl} -f --header "PRIVATE-TOKEN: $GITLAB_API_TOKEN" --upload-file result/bin/gtree https://gitlab.com/api/v4/projects/${project_id}/packages/generic/${name}/${version}/$1 - ''; - in rec { - # `nix build` - packages.gtreeStatic = naersk-lib.buildPackage { - pname = "gtree"; - root = ./.; - - nativeBuildInputs = staticInputs; - - CARGO_BUILD_TARGET = target; - CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS = - "-C target-feature=+crt-static"; - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS = - "-C target-feature=+crt-static"; - - OPENSSL_STATIC = true; - OPENSSL_DIR = "${pkgs.pkgsStatic.openssl}"; - OPENSSL_LIB_DIR = "${pkgs.pkgsStatic.openssl.out}/lib"; - OPENSSL_INCLUDE_DIR = "${pkgs.pkgsStatic.openssl.dev}/include"; + ##################################### + # Build Binaries + gtree = craneLib.buildPackage { + inherit cargoArtifacts src; + inherit nativeBuildInputs OPENSSL_DIR OPENSSL_LIB_DIR + OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR CARGO_BUILD_TARGET + CARGO_BUILD_RUSTFLAGS; }; - devShell = pkgs.mkShell { - nativeBuildInputs = staticInputs; + default = self.packages.${system}.gtree; + }; - shellHook = '' - export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-C target-feature=+crt-static" - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-C target-feature=+crt-static" + devShells.default = pkgs.mkShell { + inherit nativeBuildInputs OPENSSL_DIR OPENSSL_LIB_DIR + OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR CARGO_BUILD_TARGET + CARGO_BUILD_RUSTFLAGS; + }; - export OPENSSL_STATIC=1 - export OPENSSL_DIR="${pkgs.pkgsStatic.openssl}" - export OPENSSL_LIB_DIR="${pkgs.pkgsStatic.openssl.out}/lib" - export OPENSSL_INCLUDE_DIR="${pkgs.pkgsStatic.openssl.dev}/include" - ''; - }; - })); + formatter = pkgs.nixfmt; + }); } -- cgit v1.2.3 assword 2025-12-14add server passwordMax Audron-1/+6 2025-12-14update cargo dependenciesMax Audron-670/+505 2025-12-14update flake inputs to nixpkgs 25.11Max Audron-36/+41 2025-05-06fix rustls missing cryptoproviderMax Audron-1/+6 2025-05-06remove too commonly used used for shifty_eyesMax Audron-1/+1 2025-05-06fix truncate on unicodeMax Audron-10/+20 fuck unicode all my homies stan ascii 2025-05-06update dependenciesMax Audron-691/+1659 2024-08-12add nix build and moduleMax Audron-5/+427 2022-02-19remove jsonnet lock fileMax Audron-36/+0 2022-02-19fix deploy to work with gitlab agentMax Audron-4/+4 2021-10-22write tons of documentation and reorganize some modulesMax Audron-65/+300 2021-10-22remove wolfram alpha url shorteningMax Audron-1/+2 2021-10-20remove failing wolfram alpha test casesMax Audron-105/+55 this is due to the url shorterner dying randomly and also just generally bad idea to call external services during unit tests. 2021-10-20bump version to 1.6.2Max Audron-3/+2 2021-10-20prepare for release on crates.ioMax Audron-39/+65 2021-10-20add async docs to macro crate and bump versionMax Audron-9/+10 2021-10-20change hook errors to be logged as warningsMax Audron-3/+3 they in nearly all cases aren't critical enough to warrant an actual error messages 2021-10-20fix configuration not loading correctly on release buildsMax Audron-8/+23 2021-10-19replace sedregex crate8-rework-sedMax Audron-20/+358 This replaces the sedregex crate with our own implementation for multiple reasons: 1. We required to access the parsed regex, this required a patch to the sedregex crate which did not get merged due to an inactive dev, blocking us from publishing on crates.Io 2. We wanted to highlight the changes done in bold 3. We want to add execution of multiple chained sed commands in the future which would require more modification 2021-10-19add formatting trait for irc codesMax Audron-0/+129 add an impl off the formatting trait on String to format Strings with the typical irc formatting codes for bold, italic etc 2021-10-17fix links in readmeMax Audron-2/+2