Skip to content
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
110 changes: 62 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions npins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ let
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null then
(builtins.fetchTarball {
(builtins.fetchTarball ({
inherit url;
sha256 = hash; # FIXME: check nix version & use SRI hashes
})
} // (if repository ? filename then {
name = repository.filename;
} else { })))
else assert repository.type == "Git"; builtins.fetchGit {
url = repository.url;
rev = revision;
Expand All @@ -35,13 +37,14 @@ let
sha256 = hash;
};

mkChannelSource = { url, hash, ... }:
mkChannelSource = { url, hash, filename, ... }:
builtins.fetchTarball {
name = filename;
inherit url;
sha256 = hash;
};
in
if version == 3 then
if version == 4 then
builtins.mapAttrs (_: mkSource) data.pins
else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
10 changes: 6 additions & 4 deletions npins/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"branch": "nixpkgs-unstable",
"revision": "a529f0c125a78343b145a8eb2b915b0295e4f459",
"url": "https://github.com/nixos/nixpkgs/archive/a529f0c125a78343b145a8eb2b915b0295e4f459.tar.gz",
"hash": "0d945bdpsxaqz4d9hvsmzhcbriqwga3i0bf1ppj6lrrbqhr4pj7v"
"hash": "0d945bdpsxaqz4d9hvsmzhcbriqwga3i0bf1ppj6lrrbqhr4pj7v",
"filename": "npins-github-nixpkgs.tar.gz"
},
"pre-commit-hooks.nix": {
"type": "Git",
Expand All @@ -22,8 +23,9 @@
"branch": "master",
"revision": "ff9c0b459ddc4b79c06e19d44251daa8e9cd1746",
"url": "https://github.com/cachix/pre-commit-hooks.nix/archive/ff9c0b459ddc4b79c06e19d44251daa8e9cd1746.tar.gz",
"hash": "0z09ndxvbk6w4j28lzgj0b9qqcbwrvr58c0xsm0rf0xsdipi0nwf"
"hash": "0z09ndxvbk6w4j28lzgj0b9qqcbwrvr58c0xsm0rf0xsdipi0nwf",
"filename": "npins-github-pre-commit-hooks.nix.tar.gz"
}
},
"version": 3
}
"version": 4
}
26 changes: 24 additions & 2 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Pin {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct ChannelVersion {
pub url: url::Url,
pub filename: String,
}

impl diff::Diff for ChannelVersion {
Expand Down Expand Up @@ -62,15 +63,36 @@ impl Updatable for Pin {
.url()
.clone();

Ok(ChannelVersion { url })
Ok(ChannelVersion {
url: url.clone(),
filename: Self::calc_filename(&url)?,
})
}

async fn fetch(&self, version: &ChannelVersion) -> Result<ChannelHash> {
/* Prefetch an URL that looks like
* https://releases.nixos.org/nixos/21.11/nixos-21.11.335807.df4f1f7cc3f
*/
let hash = nix::nix_prefetch_tarball(&version.url).await?;
let hash =
nix::nix_prefetch_tarball(&version.url, Some(Self::calc_filename(&version.url)?))
.await?;

Ok(ChannelHash { hash })
}
}

impl Pin {
pub fn calc_filename(url: &url::Url) -> Result<String> {
Copy link
Owner

Choose a reason for hiding this comment

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

Tests please.

let name_parts = url.path_segments().unwrap().collect::<Vec<&str>>();
Copy link
Owner

Choose a reason for hiding this comment

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

What makes us think it is safe to unwrap here?

let basename = name_parts
.get(1)
.ok_or_else(|| anyhow::format_err!("Unsupported channel URL {}", url))?;
let ending = name_parts
.last()
.ok_or_else(|| anyhow::format_err!("Unsupported channel URL {}", url))?
.split('.')
.skip(1)
.collect::<Vec<&str>>();
Ok(format!("npins-channel-{}.{}", basename, ending.join(".")))
}
}
Loading