Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all functions overridable #374

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions crate2nix/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
# See https://github.com/kolloch/crate2nix for more info.

{ nixpkgs ? ../nix/nixpkgs.nix
, pkgs ? import nixpkgs { config = {}; }
, pkgs ? import nixpkgs { }
, fetchurl ? pkgs.fetchurl
, fetchgit ? pkgs.fetchgit
, callPackage ? pkgs.callPackage
, lib ? pkgs.lib
, buildPackages ? pkgs.buildPackages
, stdenv ? pkgs.stdenv
, stdenvNoCC ? pkgs.stdenvNoCC
, symlinkJoin ? pkgs.symlinkJoin
, runCommand ? pkgs.runCommand
, buildRustCrateForPkgs ? pkgs: pkgs.buildRustCrate
# This is used as the `crateOverrides` argument for `buildRustCrate`.
, defaultCrateOverrides ? pkgs.defaultCrateOverrides
Expand All @@ -24,7 +30,7 @@
# Additional crate2nix configuration if it exists.
, crateConfig
? if builtins.pathExists ./crate-config.nix
then pkgs.callPackage ./crate-config.nix {}
then callPackage ./crate-config.nix {}
else {}
}:

Expand Down Expand Up @@ -65,7 +71,7 @@ rec {


# A derivation that joins the outputs of all workspace members together.
allWorkspaceMembers = pkgs.symlinkJoin {
allWorkspaceMembers = symlinkJoin {
name = "all-workspace-members";
paths =
let members = builtins.attrValues workspaceMembers;
Expand Down Expand Up @@ -3286,15 +3292,15 @@ rec {
# If the user hasn't set any pre/post commands, we don't want to
# insert empty lines. This means that any existing users of crate2nix
# don't get a spurious rebuild unless they set these explicitly.
testCommand = pkgs.lib.concatStringsSep "\n" (
pkgs.lib.filter (s: s != "") [
testCommand = lib.concatStringsSep "\n" (
lib.filter (s: s != "") [
testPreRun
"$f $testCrateFlags 2>&1 | tee -a $out"
testPostRun
]
);
in
pkgs.stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation {
name = "run-tests-${testCrate.name}";

inherit (crate) src;
Expand Down Expand Up @@ -3330,7 +3336,7 @@ rec {
'';
};
in
pkgs.runCommand "${crate.name}-linked"
runCommand "${crate.name}-linked"
{
inherit (crate) outputs crateName;
passthru = (crate.passthru or { }) // {
Expand Down Expand Up @@ -3469,7 +3475,7 @@ rec {
)
crateConfigs;
target = makeTarget stdenv.hostPlatform;
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
build = mkBuiltByPackageIdByPkgs buildPackages;
};
in
self;
Expand Down Expand Up @@ -3544,7 +3550,7 @@ rec {
crateConfig
// {
src =
crateConfig.src or (pkgs.fetchurl rec {
crateConfig.src or (fetchurl rec {
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";
# https://www.pietroalbini.org/blog/downloading-crates-io/
# Not rate-limited, CDN URL.
Expand Down
20 changes: 13 additions & 7 deletions crate2nix/templates/Cargo.nix.tera
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
# See https://github.com/kolloch/crate2nix for more info.

{ nixpkgs ? {{config.nixpkgs_path | safe}}
, pkgs ? import nixpkgs { config = {}; }
, pkgs ? import nixpkgs { }
, fetchurl ? pkgs.fetchurl
, fetchgit ? pkgs.fetchgit
, callPackage ? pkgs.callPackage
, lib ? pkgs.lib
, buildPackages ? pkgs.buildPackages
, stdenv ? pkgs.stdenv
, stdenvNoCC ? pkgs.stdenvNoCC
, symlinkJoin ? pkgs.symlinkJoin
, runCommand ? pkgs.runCommand
, buildRustCrateForPkgs ? pkgs: pkgs.buildRustCrate
# This is used as the `crateOverrides` argument for `buildRustCrate`.
, defaultCrateOverrides ? pkgs.defaultCrateOverrides
Expand All @@ -26,7 +32,7 @@
# Additional crate2nix configuration if it exists.
, crateConfig
? if builtins.pathExists ./crate-config.nix
then pkgs.callPackage ./crate-config.nix {}
then callPackage ./crate-config.nix {}
else {}
}:

Expand Down Expand Up @@ -74,15 +80,15 @@ rec {
registries = {
{%- for name, hash in registries %}
{{name}} = builtins.fromJSON (builtins.readFile (fetchurl {
url = "{{name | safe}}/config.json";
url = "{{name | trim_end_matches(pat="/") | safe}}/config.json";
sha256 = {{hash}};
}));
{%- endfor %}
};
{%- endif %}

# A derivation that joins the outputs of all workspace members together.
allWorkspaceMembers = pkgs.symlinkJoin {
allWorkspaceMembers = symlinkJoin {
name = "all-workspace-members";
paths =
let members = builtins.attrValues workspaceMembers;
Expand Down Expand Up @@ -147,16 +153,16 @@ rec {
{%- elif crate.source.Nix.file.import and crate.source.Nix.attr %}
src = (import {{crate.source.Nix.file.import | safe}}).{{crate.source.Nix.attr | safe}};
{%- elif crate.source.Nix.file.package and crate.source.Nix.attr %}
src = (pkgs.callPackage {{crate.source.Nix.file.package | safe}} {}).{{crate.source.Nix.attr | safe}};
src = (callPackage {{crate.source.Nix.file.package | safe}} {}).{{crate.source.Nix.attr | safe}};
{%- elif crate.source.Nix.file.import %}
src = import {{crate.source.Nix.file.import | safe}};
{%- elif crate.source.Nix.file.package %}
src = pkgs.callPackage {{crate.source.Nix.file.package | safe}} {};
src = callPackage {{crate.source.Nix.file.package | safe}} {};
{%- elif crate.source.LocalDirectory.path %}
src = lib.cleanSourceWith { filter = sourceFilter; src = {{crate.source.LocalDirectory.path | safe}}; };
{%- elif crate.source.Git %}
workspace_member = null;
src = pkgs.fetchgit {
src = fetchgit {
url = {{crate.source.Git.url}};
rev = {{crate.source.Git.rev}};
{%- if crate.source.Git.sha256 %}
Expand Down
20 changes: 12 additions & 8 deletions crate2nix/templates/nix/crate2nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#
# crate2nix/default.nix (excerpt start)
#{#
{ pkgs
, lib
{ lib
, pkgs
, stdenv
, stdenvNoCC
, buildRustCrate
, buildRustCrateForPkgs ? if buildRustCrate != null then
lib.warn "`buildRustCrate` is deprecated, use `buildRustCrateForPkgs` instead" (_: buildRustCrate)
else
pkgs: pkgs.buildRustCrate
, buildPackages
, defaultCrateOverrides
, fetchurl
, runCommand
, strictDeprecation ? true
, crates ? { }
, rootFeatures ? [ ]
Expand Down Expand Up @@ -157,15 +161,15 @@ rec {
# If the user hasn't set any pre/post commands, we don't want to
# insert empty lines. This means that any existing users of crate2nix
# don't get a spurious rebuild unless they set these explicitly.
testCommand = pkgs.lib.concatStringsSep "\n" (
pkgs.lib.filter (s: s != "") [
testCommand = lib.concatStringsSep "\n" (
lib.filter (s: s != "") [
testPreRun
"$f $testCrateFlags 2>&1 | tee -a $out"
testPostRun
]
);
in
pkgs.stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation {
name = "run-tests-${testCrate.name}";

inherit (crate) src;
Expand Down Expand Up @@ -201,7 +205,7 @@ rec {
'';
};
in
pkgs.runCommand "${crate.name}-linked"
runCommand "${crate.name}-linked"
{
inherit (crate) outputs crateName;
passthru = (crate.passthru or { }) // {
Expand Down Expand Up @@ -340,7 +344,7 @@ rec {
)
crateConfigs;
target = makeTarget stdenv.hostPlatform;
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
build = mkBuiltByPackageIdByPkgs buildPackages;
};
in
self;
Expand Down Expand Up @@ -415,7 +419,7 @@ rec {
crateConfig
// {
src =
crateConfig.src or (pkgs.fetchurl rec {
crateConfig.src or (fetchurl rec {
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";
# https://www.pietroalbini.org/blog/downloading-crates-io/
# Not rate-limited, CDN URL.
Expand Down
28 changes: 17 additions & 11 deletions sample_projects/bin_with_git_submodule_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
# See https://github.com/kolloch/crate2nix for more info.

{ nixpkgs ? <nixpkgs>
, pkgs ? import nixpkgs { config = {}; }
, pkgs ? import nixpkgs { }
, fetchurl ? pkgs.fetchurl
, fetchgit ? pkgs.fetchgit
, callPackage ? pkgs.callPackage
, lib ? pkgs.lib
, buildPackages ? pkgs.buildPackages
, stdenv ? pkgs.stdenv
, stdenvNoCC ? pkgs.stdenvNoCC
, symlinkJoin ? pkgs.symlinkJoin
, runCommand ? pkgs.runCommand
, buildRustCrateForPkgs ? pkgs: pkgs.buildRustCrate
# This is used as the `crateOverrides` argument for `buildRustCrate`.
, defaultCrateOverrides ? pkgs.defaultCrateOverrides
Expand All @@ -24,7 +30,7 @@
# Additional crate2nix configuration if it exists.
, crateConfig
? if builtins.pathExists ./crate-config.nix
then pkgs.callPackage ./crate-config.nix {}
then callPackage ./crate-config.nix {}
else {}
}:

Expand Down Expand Up @@ -65,7 +71,7 @@ rec {


# A derivation that joins the outputs of all workspace members together.
allWorkspaceMembers = pkgs.symlinkJoin {
allWorkspaceMembers = symlinkJoin {
name = "all-workspace-members";
paths =
let members = builtins.attrValues workspaceMembers;
Expand Down Expand Up @@ -485,7 +491,7 @@ rec {
edition = "2018";
links = "rocksdb";
workspace_member = null;
src = pkgs.fetchgit {
src = fetchgit {
url = "https://github.com/rust-rocksdb/rust-rocksdb";
rev = "66f04df013b6e6bd42b5a8c353406e09a7c7da2a";
sha256 = "1rchvjrjamdaznx26gy4bmjj10rrf00mgc1wvkc489r9z1nh4h1h";
Expand Down Expand Up @@ -837,7 +843,7 @@ rec {
version = "0.21.0";
edition = "2018";
workspace_member = null;
src = pkgs.fetchgit {
src = fetchgit {
url = "https://github.com/rust-rocksdb/rust-rocksdb";
rev = "66f04df013b6e6bd42b5a8c353406e09a7c7da2a";
sha256 = "1rchvjrjamdaznx26gy4bmjj10rrf00mgc1wvkc489r9z1nh4h1h";
Expand Down Expand Up @@ -1504,15 +1510,15 @@ rec {
# If the user hasn't set any pre/post commands, we don't want to
# insert empty lines. This means that any existing users of crate2nix
# don't get a spurious rebuild unless they set these explicitly.
testCommand = pkgs.lib.concatStringsSep "\n" (
pkgs.lib.filter (s: s != "") [
testCommand = lib.concatStringsSep "\n" (
lib.filter (s: s != "") [
testPreRun
"$f $testCrateFlags 2>&1 | tee -a $out"
testPostRun
]
);
in
pkgs.stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation {
name = "run-tests-${testCrate.name}";

inherit (crate) src;
Expand Down Expand Up @@ -1548,7 +1554,7 @@ rec {
'';
};
in
pkgs.runCommand "${crate.name}-linked"
runCommand "${crate.name}-linked"
{
inherit (crate) outputs crateName;
passthru = (crate.passthru or { }) // {
Expand Down Expand Up @@ -1687,7 +1693,7 @@ rec {
)
crateConfigs;
target = makeTarget stdenv.hostPlatform;
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
build = mkBuiltByPackageIdByPkgs buildPackages;
};
in
self;
Expand Down Expand Up @@ -1762,7 +1768,7 @@ rec {
crateConfig
// {
src =
crateConfig.src or (pkgs.fetchurl rec {
crateConfig.src or (fetchurl rec {
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";
# https://www.pietroalbini.org/blog/downloading-crates-io/
# Not rate-limited, CDN URL.
Expand Down
Loading
Loading