8000 use finalAttrs instead of rec by figsoda · Pull Request #666 · nix-community/nix-init · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
8000
2 changes: 1 addition & 1 deletion src/fetcher/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub async fn get_package_info(
pname: repo.into(),
description,
file_url_prefix: Some(format!(
"https://{github_base}/{owner}/{repo}/blob/${{src.rev}}/",
"https://{github_base}/{owner}/{repo}/blob/${{finalAttrs.src.rev}}/",
)),
license: Vec::new(),
python_dependencies: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/fetcher/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub async fn get_package_info(
pname: repo.into(),
description,
file_url_prefix: Some(format!(
"https://{domain}/{owner}/{repo}/-/blob/${{src.rev}}/",
"https://{domain}/{owner}/{repo}/-/blob/${{finalAttrs.src.rev}}/",
)),
license: Vec::new(),
python_dependencies: Default::default(),
Expand Down
18 changes: 9 additions & 9 deletions src/lang/go/goreleaser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ fn regex() -> Option<Regex> {
fn parse_ldflags<'a>(re: &Regex, ldflags: &'a str) -> Cow<'a, str> {
re.replace_all(ldflags, |caps: &Captures| match &caps[1] {
// https://goreleaser.com/customization/templates
".ProjectName" => "${pname}".into(),
".Version" | ".RawVersion" => "${version}".into(),
".ProjectName" => "${finalAttrs.pname}".into(),
".Version" | ".RawVersion" => "${finalAttrs.version}".into(),
".Branch" | ".PrefixedTag" | ".Tag" | ".ShortCommit" | ".FullCommit" | ".Commit" => {
"${src.rev}".into()
"${finalAttrs.src.rev}".into()
}
".IsGitDirty" => "false".into(),
".Major" => "${lib.versions.major version}".into(),
".Minor" => "${lib.versions.minor version}".into(),
".Patch" => "${lib.versions.patch version}".into(),
".Major" => "${lib.versions.major finalAttrs.version}".into(),
".Minor" => "${lib.versions.minor finalAttrs.version}".into(),
".Patch" => "${lib.versions.patch finalAttrs.version}".into(),
".Date" | ".CommitDate" => "1970-01-01T00:00:00Z".into(),
".Timestamp" | ".CommitTimestamp" => "0".into(),
".Summary" | ".PrefixedSummary" => "${src.rev}".into(),
".Summary" | ".PrefixedSummary" => "${finalAttrs.src.rev}".into(),
x => format!("${{{}}}", x.to_lower_camel_case()),
})
}
Expand All @@ -118,14 +118,14 @@ mod tests {
assert_eq!(parse_ldflags(&re, "-s -w"), "-s -w");
assert_eq!(
parse_ldflags(&re, "-X=main.Version={{ .Version }}"),
"-X=main.Version=${version}",
"-X=main.Version=${finalAttrs.version}",
);
assert_eq!(
parse_ldflags(
&re,
"-s -w -X main.Version={{ .Version }} -X main.Tag={{ .Tag }}",
),
"-s -w -X main.Version=${version} -X main.Tag=${src.rev}",
"-s -w -X main.Version=${finalAttrs.version} -X main.Tag=${finalAttrs.src.rev}",
);

assert_eq!(
Expand Down
34 changes: 17 additions & 17 deletions src/main.rs
9C88
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ async fn run() -> Result<()> {
if &pname == name {
formatdoc! {r#"
fetchCrate {{
inherit pname version;
inherit (finalAttrs) pname version;
hash = "{hash}";
}}"#,
}
} else {
formatdoc! {r#"
fetchCrate {{
pname = {name:?};
inherit version;
inherit (finalAttrs) version;
hash = "{hash}";
}}"#,
}
Expand All @@ -263,7 +263,7 @@ async fn run() -> Result<()> {
.context("failed to parse nurl output")?;
formatdoc! {r#"
fetchPypi {{
inherit pname version;
inherit (finalAttrs) pname version;
hash = "{hash}";{ext}
}}"#,
}
Expand All @@ -278,7 +278,7 @@ async fn run() -> Result<()> {
formatdoc! {r#"
fetchPypi {{
pname = {name:?};
inherit version;
inherit (finalAttrs) version;
hash = "{hash}";{ext}
}}"#,
}
Expand All @@ -287,11 +287,11 @@ async fn run() -> Result<()> {

_ => {
if rev == version {
cmd.arg("-o").arg("rev").arg("version");
cmd.arg("-o").arg("rev").arg("finalAttrs.version");
} else if rev.contains(&version) {
cmd.arg("-O")
.arg("rev")
.arg(rev.replacen(&version, "${version}", 1));
.arg(rev.replacen(&version, "${finalAttrs.version}", 1));
}

String::from_utf8(
Expand All @@ -315,7 +315,7 @@ async fn run() -> Result<()> {
.arg("--json")
.arg("--expr")
.arg(format!(
"let pname={pname:?};version={version:?};in(import({nixpkgs}){{}}).{src_expr}",
"let finalAttrs={{pname={pname:?};version={version:?};}};in(import({nixpkgs}){{}}).{src_expr}",
))
.get_stdout()
.await?;
Expand Down Expand Up @@ -560,7 +560,7 @@ async fn run() -> Result<()> {
writedoc! {out, r#"
}}:

buildGoModule rec {{
buildGoModule (finalAttrs: {{
pname = {pname:?};
version = {version:?};

Expand Down Expand Up @@ -647,7 +647,7 @@ async fn run() -> Result<()> {
writedoc! {out, r#"
}}:

{} rec {{
{} (finalAttrs: {{
pname = {pname:?};
version = {version:?};
pyproject = true;
Expand All @@ -667,7 +667,7 @@ async fn run() -> Result<()> {
write!(out, " ")?;
writedoc! {out, r#"
cargoDeps = rustPlatform.fetchCargoVendor {{
inherit pname version src;
inherit (finalAttrs) pname version src;
hash = "{hash}";
}};

Expand Down Expand Up @@ -701,7 +701,7 @@ async fn run() -> Result<()> {
writedoc! {out, r#"
}}:

rustPlatform.buildRustPackage rec {{
rustPlatform.buildRustPackage (finalAttrs: {{
pname = {pname:?};
version = {version:?};

Expand Down Expand Up @@ -734,7 +734,7 @@ async fn run() -> Result<()> {
writedoc! {out, r#"
}}:

rustPlatform.buildRustPackage rec {{
rustPlatform.buildRustPackage (finalAttrs: {{
pname = "{pname}";
version = "{version}";

Expand All @@ -751,7 +751,7 @@ async fn run() -> Result<()> {
writedoc! { out, r#"
}}:

stdenv.mkDerivation rec {{
stdenv.mkDerivation (finalAttrs: {{
pname = {pname:?};
version = {version:?};

Expand All @@ -778,14 +778,14 @@ async fn run() -> Result<()> {
writedoc! {out, r#"
}}:

stdenv.mkDerivation rec {{
stdenv.mkDerivation (finalAttrs: {{
pname = {pname:?};
version = {version:?};

src = {src_expr};

cargoDeps = rustPlatform.fetchCargoVendor {{
inherit pname version src;
inherit (finalAttrs) pname version src;
hash = "{hash}";
}};

Expand Down Expand Up @@ -813,7 +813,7 @@ async fn run() -> Result<()> {
writedoc! {out, r#"
}}:

stdenv.mkDerivation rec {{
stdenv.mkDerivation (finalAttrs: {{
pname = "{pname}";
version = "{version}";

Expand Down Expand Up @@ -1027,7 +1027,7 @@ async fn run() -> Result<()> {
}
}

writeln!(out, " }};\n}}")?;
writeln!(out, " }};\n}})")?;

let mut out_file = File::create(&out_path).context("failed to create output file")?;
write!(out_file, "{out}")?;
Expand Down
0