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

WIP: add support for veloren in tools.nix #166

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions crate2nix/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub enum Source {
/// The revision hash.
rev: String,
/// The sha256 of the fetched result.
sha256: String,
sha256: Option<String>,
},
/// Get the source from a nix expression.
Nix {
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Display for Source {
version,
sha256,
} => write!(f, "{} {} from crates.io: {}", name, version, sha256),
Source::Git { url, rev, sha256 } => write!(f, "{}#{} via git: {}", url, rev, sha256),
Source::Git { url, rev, sha256 } => write!(f, "{}#{} via git: {:?}", url, rev, sha256),
Source::Nix { file, attr: None } => write!(f, "{}", file),
Source::Nix {
file,
Expand Down
2 changes: 1 addition & 1 deletion crate2nix/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl From<crate::config::Source> for ResolvedSource {
url,
rev,
r#ref: None,
sha256: Some(sha256),
sha256: sha256,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sha256: sha256,
sha256,

}),
crate::config::Source::CratesIo {
name,
Expand Down
2 changes: 1 addition & 1 deletion crate2nix/src/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn git_io_source(url: Url, rev: String) -> Result<config::Source, Error> {
let sha256 = prefetchable.prefetch()?;
eprintln!("done.");

Ok(config::Source::Git { url, rev, sha256 })
Ok(config::Source::Git { url, rev, sha256: Some(sha256) })
}

/// Operations on assmebling out-of-tree sources via nix.
Expand Down
32 changes: 27 additions & 5 deletions tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,16 @@ rec {
withoutGitPlus = lib.removePrefix "git+" source;
splitHash = lib.splitString "#" withoutGitPlus;
splitQuestion = lib.concatMap (lib.splitString "?") splitHash;
maybeBranchSplited = lib.splitString "branch=" withoutGitPlus;
in
{
url = builtins.head splitQuestion;
rev = lib.last splitQuestion;
branch = if (lib.length maybeBranchSplited) == 1 then
"master"
else (
lib.head (lib.splitString "#" (lib.last maybeBranchSplited))
);
};

vendorSupport = { crateDir ? ./., ... }:
Expand Down Expand Up @@ -234,7 +240,7 @@ rec {
src = builtins.fetchGit {
submodules = true;
inherit (parsed) url rev;
ref = attrs.branch or "master";
ref = parsed.branch or null;
};
hash = pkgs.runCommand "hash-of-${attrs.name}" { nativeBuildInputs = [ pkgs.nix ]; } ''
echo -n "$(nix-hash --type sha256 ${src})" > $out
Expand Down Expand Up @@ -296,13 +302,13 @@ rec {
[source."${parsed.url}"]
git = "${parsed.url}"
rev = "${parsed.rev}"
${lib.optionalString (isNull (builtins.match ".*\\?rev=[0-9a-z]{40}.*" source)) ''branch = "${attrs.branch or "master"}"''}
${lib.optionalString (isNull (builtins.match ".*\\?rev=[0-9a-z]{40}.*" source)) ''branch = "${attrs.branch or parsed.branch or "master"}"''}
replace-with = "vendored-sources"
'';
gitSources = packagesByType."git" or [ ];
gitSourcesUnique = lib.unique gitSources;
gitSourceConfigs = builtins.map gitSourceConfig gitSourcesUnique;
gitSourceConfigsString = lib.concatStrings gitSourceConfigs;
gitSourceConfigsString = lib.concatStrings (lib.unique gitSourceConfigs);
in
pkgs.writeText
"vendor-config"
Expand Down Expand Up @@ -351,14 +357,30 @@ rec {
inherit sha256;
inherit (parsed) url rev;
};

rootCargo = builtins.fromTOML (builtins.readFile "${src}/Cargo.toml");
isWorkspace = rootCargo ? "workspace";
isPackage = rootCargo ? "package";
containedCrates = rootCargo.workspace.members ++ (if isPackage then ["."] else []);

getCrateNameFromPath = path: let
cargoTomlCrate = builtins.fromTOML (builtins.readFile "${src}/${path}/Cargo.toml");
in
cargoTomlCrate.package.name;

pathToExtract = if isWorkspace then
builtins.head (builtins.filter (to_filter:
(getCrateNameFromPath to_filter) == name
) containedCrates)
else
".";
in
pkgs.runCommand (lib.removeSuffix ".tar.gz" src.name) { }
''
mkdir -p $out
cp -apR ${src}/* $out
cp -apR ${src}/${pathToExtract}/* $out
echo '{"package":null,"files":{}}' > $out/.cargo-checksum.json
'';

};
};
};
Expand Down