Add support for sourcehut links (#517)

* Add support for SourceHut flakes

* Update flake-info/README.md

Co-authored-by: Naïm Favier <n@monade.li>

Co-authored-by: Naïm Favier <n@monade.li>
This commit is contained in:
Philip Munksgaard 2022-08-23 14:42:06 +02:00 committed by GitHub
parent 087925bbb2
commit 9e5f095369
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 5 deletions

View file

@ -63,7 +63,7 @@ application.
To add your own flakes to the search index edit [./flakes/manual.toml](./flakes/manual.toml).
Possible types are `github`, `gitlab`, and `git` (which is the fallback for any kind of git repository but requires to set a revision key manually as of now).
Possible types are `github`, `gitlab`, `sourcehut`, and `git` (which is the fallback for any kind of git repository but requires to set a revision key manually as of now).
To test whether your flake is compatible with nix flake-info you can try running `flake-info` against it

View file

@ -68,7 +68,8 @@ The `<flake>` argument should contain a valid reference to a flake. It accepts a
> use git+<url> to checkout a git repository at <url>
> use /local/absolute/path or ./relative/path to load a local source
> use gitlab:<user>/<repo>/github:<user>/<repo> to shortcut gitlab or github repositories
> use gitlab:<user>/<repo>/github:<user>/<repo>/sourcehut:<user>/<repo> to
> shortcut gitlab, github or sourcehut repositories
Optionally, analyzing can be done in a temporary store enabled by the `--temp-store` option.
@ -97,7 +98,7 @@ $ flake-info nixpkgs nixos-21.05
to perform a bulk import grouping multiple inputs under the same name/index use the group command.
It expects a json file as input that contains references to flakes or nixpkgs. If those resources are on github or gitlab they can be extended with more meta information including pinning the commit hash/ref.
It expects a JSON file as input that contains references to flakes or nixpkgs. If those resources are on GitHub, GitLab or SourceHut they can be extended with more meta information including pinning the commit hash/ref.
The second argument is the group name that is used to provide the index name.

View file

@ -33,19 +33,21 @@ impl Flake {
Repo::Git { .. } => Default::default(),
Repo::GitHub { repo, .. } => repo.clone(),
Repo::Gitlab { repo, .. } => repo.clone(),
Repo::SourceHut { repo, .. } => repo.clone(),
};
self
}
}
/// Information about the flake origin
/// Supports (local/raw) Git, GitHub and Gitlab repos
/// Supports (local/raw) Git, GitHub, SourceHut and Gitlab repos
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum Repo {
Git { url: PathBuf },
GitHub { owner: String, repo: String },
Gitlab { owner: String, repo: String },
SourceHut { owner: String, repo: String },
}
#[cfg(test)]

View file

@ -11,7 +11,7 @@ pub type Hash = String;
pub type FlakeRef = String;
/// Information about the flake origin
/// Supports (local/raw) Git, GitHub and Gitlab repos
/// Supports (local/raw) Git, GitHub, SourceHut and Gitlab repos
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum Source {
@ -27,6 +27,11 @@ pub enum Source {
repo: String,
git_ref: Option<Hash>,
},
SourceHut {
owner: String,
repo: String,
git_ref: Option<Hash>,
},
Git {
url: String,
},
@ -66,6 +71,18 @@ impl Source {
.as_ref()
.map_or("".to_string(), |f| format!("?ref={}", f))
),
Source::SourceHut {
owner,
repo,
git_ref,
} => format!(
"sourcehut:{}/{}{}",
owner,
repo,
git_ref
.as_ref()
.map_or("".to_string(), |f| format!("?ref={}", f))
),
Source::Git { url } => url.to_string(),
Source::Nixpkgs(Nixpkgs { git_ref, .. }) => format!(
"https://api.github.com/repos/NixOS/nixpkgs/tarball/{}",

View file

@ -1001,6 +1001,9 @@ decodeResolvedFlake =
"gitlab" ->
Maybe.map (\repoPath_ -> ( "gitlab:" ++ repoPath_, "https://gitlab.com/" ++ repoPath_ )) repoPath
"sourcehut" ->
Maybe.map (\repoPath_ -> ( "sourcehut:" ++ repoPath_, "https://sr.ht/" ++ repoPath_ )) repoPath
"git" ->
Maybe.map (\url_ -> ( url_, url_ )) url

View file

@ -270,6 +270,9 @@ decodeResolvedFlake =
"gitlab" ->
Maybe.map (\repoPath_ -> "https://gitlab.com/" ++ repoPath_) repoPath
"sourcehut" ->
Maybe.map (\repoPath_ -> "https://sr.ht/" ++ repoPath_) repoPath
"git" ->
url