From 26b0e3b21dd4a793e6c7f70b357814a9d1041649 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Tue, 20 Jun 2023 01:12:02 +0200 Subject: [PATCH] Allow customizing features --- flake.nix | 22 +++------------------- package.nix | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 package.nix diff --git a/flake.nix b/flake.nix index 446ee3b..9c1a76a 100644 --- a/flake.nix +++ b/flake.nix @@ -10,30 +10,14 @@ extra-substituters = [ "https://natsukagami.cachix.org" ]; trusted-public-keys = [ "natsukagami.cachix.org-1:3U6GV8i8gWEaXRUuXd2S4ASfYgdl2QFPWg4BKPbmYiQ=" ]; }; - outputs = { self, nixpkgs, naersk, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: + outputs = { self, nixpkgs, flake-utils, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; - naersk' = pkgs.callPackage naersk { }; + naersk = pkgs.callPackage inputs.naersk { }; in rec { - packages.youmubot = naersk'.buildPackage { - name = "youmubot"; - version = "0.1.0"; - - root = ./.; - cargoBuildOptions = opts: opts ++ [ "--package youmubot" ]; - - buildInputs = with pkgs; [ - openssl - ]; - - nativeBuildInputs = nixpkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs; [ - pkg-config - ]); - - SQLX_OFFLINE = "true"; - }; + packages.youmubot = pkgs.callPackage ./package.nix { inherit naersk; }; defaultPackage = packages.youmubot; diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..7547b0d --- /dev/null +++ b/package.nix @@ -0,0 +1,36 @@ +{ naersk +, lib +, stdenv +, pkg-config +, openssl + +, enableCodeforces ? true +, enableOsu ? true +, ... +}: +let + customizeFeatures = !(enableCodeforces && enableOsu); + featureFlags = lib.optionals customizeFeatures ( + [ "--no-default-features" "--features=core" ] + ++ lib.optional enableCodeforces "--features=codeforces" + ++ lib.optional enableOsu "--features=osu" + ); +in +naersk.buildPackage { + name = "youmubot"; + version = "0.1.0"; + + root = ./.; + cargoBuildOptions = opts: opts ++ [ "--package youmubot" ] ++ featureFlags; + + buildInputs = [ + openssl + ]; + + nativeBuildInputs = lib.optionals stdenv.isLinux [ + pkg-config + ]; + + SQLX_OFFLINE = "true"; +} +