Skip to content

Commit

Permalink
nixpkgs' npins source generation using nixpkgs fetchers doesn't suppo…
Browse files Browse the repository at this point in the history
…rt git correctly
  • Loading branch information
Gerg-L committed Aug 1, 2024
1 parent 2842897 commit 4911001
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update_deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
git reset --soft HEAD^
fi
if NPINS=$(nix run nixpkgs#npins -- -d ./pkgs update -f | grep -E '[^\(no changes\)]*url.*'); then
if NPINS=$(nix run nixpkgs#npins -- -d ./pkgs/npins update -f | grep -E '[^\(no changes\)]*url.*'); then
MESSAGE="$MESSAGE
npins url updates:
Expand Down
3 changes: 3 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let
spicePkgs = self.legacyPackages.${pkgs.stdenv.hostPlatform.system};
extensionType = lib.types.either lib.types.pathInStore (
lib.types.submodule {
freeformType = lib.types.attrs;
options = {
src = lib.mkOption {
type = lib.types.pathInStore;
Expand Down Expand Up @@ -48,6 +49,7 @@ in
inherit (spicePkgs.themes) default;

type = lib.types.submodule {
freeformType = lib.types.attrs;
options = {
name = lib.mkOption {
type = lib.types.str;
Expand Down Expand Up @@ -171,6 +173,7 @@ in
enabledCustomApps = lib.mkOption {
type = lib.types.listOf (
lib.types.submodule {
freeformType = lib.types.attrs;
options = {
src = lib.mkOption {
type = lib.types.pathInStore;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let
spicePkgs = self.legacyPackages.${pkgs.stdenv.system};
in
{
sources = lib.mapAttrs (_: pkgs.npins.mkSource) (lib.importJSON "${self}/pkgs/sources.json").pins;
sources = pkgs.callPackages "${self}/pkgs/npins/sources.nix" { };
spicetify = pkgs.callPackage "${self}/pkgs/spicetify.nix" { };

/*
Expand Down
File renamed without changes.
72 changes: 72 additions & 0 deletions pkgs/npins/sources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Based off of:
# https://github.com/NixOS/nixpkgs/blob/776c3bee4769c616479393aeefceefeda16b6fcb/pkgs/tools/nix/npins/source.nix
{
lib,
fetchurl,
fetchgit,
fetchzip,
}:
builtins.mapAttrs (
_:
let
getZip =
{ url, hash, ... }:
fetchzip {
inherit url;
sha256 = hash;
extension = "tar";

};
mkGitSource =
{
repository,
revision,
url ? null,
hash,
...
}@attrs:
assert repository ? type;
if url != null then
getZip attrs
else
assert repository.type == "Git";
let
urlToName =
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url;
short = builtins.substring 0 7 rev;
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
in
"${if matched == null then "source" else builtins.head matched}${appendShort}";
name = urlToName repository.url revision;
in
fetchgit {
inherit name;
inherit (repository) url;
rev = revision;
sha256 = hash;
};

mkPyPiSource =
{ url, hash, ... }:
fetchurl {
inherit url;
sha256 = hash;
};
in
spec:
assert spec ? type;
let
func =
{
Git = mkGitSource;
GitRelease = mkGitSource;
PyPi = mkPyPiSource;
Channel = getZip;
}
.${spec.type} or (builtins.throw "Unknown source type ${spec.type}");
in
spec // { outPath = func spec; }

) (lib.importJSON ./sources.json).pins

0 comments on commit 4911001

Please sign in to comment.