diff --git a/flake.nix b/flake.nix index 6333b2a6b..ff40626e9 100644 --- a/flake.nix +++ b/flake.nix @@ -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 diff --git a/package.nix b/package.nix index 7d22c4226..1ab3e6edf 100644 --- a/package.nix +++ b/package.nix @@ -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" @@ -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 diff --git a/src/modules/tasks.nix b/src/modules/tasks.nix index b350def17..79ff97db8 100644 --- a/src/modules/tasks.nix +++ b/src/modules/tasks.nix @@ -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