Repository navigation
add support for buildNimPackage #862
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
Open
lnk3
wants to merge
1
commit into
nix-community:main
Choose a base branch
from
lnk3:build-nim-package
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode cha
8000
racters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| use std::{ | ||
| fmt::Write as _, | ||
| path::{Path, PathBuf}, | ||
| }; | ||
|
|
||
| use anyhow::Result; | ||
| use parse_display::Display; | ||
|
|
||
| use crate::codegen::{Builder, Codegen}; | ||
|
|
||
| #[derive(Clone, Copy, Display)] | ||
| #[display("buildNimPackage")] | ||
| pub struct BuildNimPackage; | ||
|
|
||
| impl Builder for BuildNimPackage { | ||
| fn function(&self) -> &'static str { | ||
| "buildNimPackage" | ||
| } | ||
|
|
||
| fn explicit_strict_deps(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| async fn after_src(&self, cg: &mut Codegen<'_>) -> Result<String> { | ||
| let mut out = String::new(); | ||
|
|
||
| let lock_path = get_lock_path(cg.out_dir); | ||
|
|
||
| writeln!( | ||
| out, | ||
| " # Generate lockfile with: nix run -f . nim_lk ./result | jq --sort-keys > {lock_path}" | ||
| )?; | ||
| writeln!(out, " lockFile = ./lock.json;\n")?; | ||
|
|
||
| if let Some(file) = find_nimble_file(cg.src_dir) { | ||
| writeln!(out, " nimbleFile = \"{file}\";\n")?; | ||
| } | ||
|
|
||
| writeln!(out, " nimFlags = [ ];\n")?; | ||
|
|
||
| Ok(out) | ||
| } | ||
| } | ||
|
|
||
| fn get_lock_path(out_dir: Option<&Path>) -> String { | ||
| out_dir | ||
| .map(|d| d.join("lock.json")) | ||
| .unwrap_or_else(|| PathBuf::from("lock.json")) | ||
| .display() | ||
| .to_string() | ||
| } | ||
|
|
||
| fn find_nimble_file(src_dir: &Path) -> Option<String> { | ||
| std::fs::read_dir(src_dir) | ||
| .ok()? | ||
| .filter_map(Result::ok) | ||
| .find(|entry| entry.path().extension().is_some_and(|ext| ext == "nimble")) | ||
| .map(|entry| entry.file_name().to_string_lossy().into_owned()) | ||
| } | ||
|
Comment on lines
+53
to
+59
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to find detect the nimble file since it doesn't have a predefined name like There is a nimbleFile parameter for the nixpkgs builder function which is not mandatory but nice to have and trivial to precompute for the maintainer. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| lib, | ||
| buildNimPackage, | ||
| fetchFromGitHub, | ||
| nix-update-script, | ||
| }: | ||
|
|
||
| buildNimPackage (finalAttrs: { | ||
| pname = "choosenim"; | ||
| version = "0.8.16"; | ||
| __structuredAttrs = true; | ||
| strictDeps = true; | ||
|
|
||
| src = fetchFromGitHub { | ||
| owner = "nim-lang"; | ||
| repo = "choosenim"; | ||
| tag = "v${finalAttrs.version}"; | ||
| hash = "sha256-Sa1T7uZDIZHsakyI7QeJEWrHW7rSarFDniY9FaTBL7Q="; | ||
| }; | ||
|
|
||
| # Generate lockfile with: nix run -f . nim_lk ./result | jq --sort-keys > ./lock.json | ||
| lockFile = ./lock.json; | ||
|
|
||
| nimbleFile = "choosenim.nimble"; | ||
|
|
||
| nimFlags = [ ]; | ||
|
|
||
| passthru.updateScript = nix-update-script { }; | ||
|
|
||
| meta = { | ||
| description = "Official tool for easily installing and managing multiple versions of the Nim programming language"; | ||
| homepage = "https://github.com/nim-lang/choosenim"; | ||
| changelog = "https://github.com/nim-lang/choosenim/blob/${finalAttrs.src.rev}/changelog.markdown"; | ||
| license = lib.licenses.bsd3; | ||
| maintainers = with lib.maintainers; [ alice ]; | ||
| mainProgram = "choosenim"; | ||
| }; | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| args = [ | ||
| "--headless", | ||
| "--url=https://github.com/nim-lang/choosenim", | ||
| "--rev=v0.8.16", | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use
nix-initin a nixpkgs checkout it precomputed theout_dirto something likepkgs/by-name/xx/xxxxxxxx/, so I wanted to use it to help the maintainer generate the lockfile in the correct place.The comment will result in a simple command the nix-init user can just copy and run