Skip to content

Commit

Permalink
Merge pull request #1648 from cachix/package-nix
Browse files Browse the repository at this point in the history
package: rework to make consistent with upstream nixpkgs version
  • Loading branch information
domenkozar authored Dec 23, 2024
2 parents f81cf7d + adff97d commit 9e1b29e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
let
systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = f: builtins.listToAttrs (map (name: { inherit name; value = f name; }) systems);
mkPackage = pkgs: import ./package.nix { inherit pkgs inputs; };
mkPackage = pkgs: pkgs.callPackage ./package.nix {
inherit (inputs.nix.packages.${pkgs.stdenv.system}) nix;
inherit (inputs.cachix.packages.${pkgs.stdenv.system}) cachix;
};
mkDevShellPackage = config: pkgs: import ./src/devenv-devShell.nix { inherit config pkgs; };
mkDocOptions = pkgs:
let
Expand Down
48 changes: 29 additions & 19 deletions package.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
{ pkgs, inputs, build_tasks ? false }:
{ lib
, stdenv
, makeBinaryWrapper
, installShellFiles
, rustPlatform
, nix
, cachix
, darwin
, sqlx-cli
, openssl
, pkg-config
, glibcLocalesUtf8
, build_tasks ? false
}:

pkgs.rustPlatform.buildRustPackage {
rustPlatform.buildRustPackage {
pname = "devenv";
version = "1.3.1";

# WARN: building this from src/modules/tasks.nix fails.
# There is something being prepended to the path, hence the .*.
src = pkgs.lib.sourceByRegex ./. [
src = lib.sourceByRegex ./. [
".*\.cargo(/.*)?$"
".*Cargo\.toml"
".*Cargo\.lock"
Expand All @@ -30,45 +43,42 @@ pkgs.rustPlatform.buildRustPackage {
};

nativeBuildInputs = [
pkgs.installShellFiles
pkgs.makeBinaryWrapper
pkgs.pkg-config
] ++ pkgs.lib.optional (!build_tasks) pkgs.sqlx-cli;
installShellFiles
makeBinaryWrapper
pkg-config
] ++ lib.optional (!build_tasks) sqlx-cli;

buildInputs = [ pkgs.openssl ]
++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.SystemConfiguration;
buildInputs = [ openssl ]
++ lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.SystemConfiguration;

# Force sqlx to use the prepared queries
SQLX_OFFLINE = true;
# A local database to use for preparing queries
DATABASE_URL = "sqlite:nix-eval-cache.db";

preBuild = pkgs.lib.optionalString (!build_tasks) ''
preBuild = lib.optionalString (!build_tasks) ''
cargo sqlx database setup --source devenv-eval-cache/migrations
cargo sqlx prepare --workspace
'';

postInstall =
let
inherit (inputs.nix.packages.${pkgs.stdenv.system}) nix;
inherit (inputs.cachix.packages.${pkgs.stdenv.system}) cachix;

localeArchiveFix =
pkgs.lib.optionalString (pkgs.stdenv.isLinux && (pkgs.glibcLocalesUtf8 != null)) ''
--set-default LOCALE_ARCHIVE ${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive
setDefaultLocaleArchive =
lib.optionalString (glibcLocalesUtf8 != null) ''
--set-default LOCALE_ARCHIVE ${glibcLocalesUtf8}/lib/locale/locale-archive
'';
in
pkgs.lib.optionalString (!build_tasks) ''
lib.optionalString (!build_tasks) ''
wrapProgram $out/bin/devenv \
--prefix PATH ":" "$out/bin:${cachix}/bin" \
--set DEVENV_NIX ${nix} \
${localeArchiveFix} \
${setDefaultLocaleArchive} \
# TODO: problematic for our library...
wrapProgram $out/bin/devenv-run-tests \
--prefix PATH ":" "$out/bin:${cachix}/bin" \
--set DEVENV_NIX ${nix} \
${localeArchiveFix} \
${setDefaultLocaleArchive} \
# Generate manpages
cargo xtask generate-manpages --out-dir man
Expand Down
6 changes: 5 additions & 1 deletion src/modules/tasks.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{ pkgs, lib, config, ... }@inputs:
let
types = lib.types;
devenv = import ./../../package.nix { inherit pkgs inputs; build_tasks = true; };
devenv = pkgs.callPackage ./../../package.nix {
build_tasks = true;
inherit (inputs.nix.packages.${pkgs.stdenv.system}) nix;
inherit (inputs.cachix.packages.${pkgs.stdenv.system}) cachix;
};
taskType = types.submodule
({ name, config, ... }:
let
Expand Down

0 comments on commit 9e1b29e

Please sign in to comment.