summaryrefslogtreecommitdiff
path: root/archpkgs.nix
diff options
context:
space:
mode:
Diffstat (limited to 'archpkgs.nix')
-rw-r--r--archpkgs.nix82
1 files changed, 82 insertions, 0 deletions
diff --git a/archpkgs.nix b/archpkgs.nix
new file mode 100644
index 0000000..37f8236
--- /dev/null
+++ b/archpkgs.nix
@@ -0,0 +1,82 @@
+{ self, pkgs, wrappers, system }:
+let
+ lib = pkgs.lib;
+ make-tzst = name: value: pkgs.stdenv.mkDerivation {
+ pname = "${name}-tzst";
+ version = value.version;
+ # src = bundlers.bundlers.${system}.toArx value;
+ # dontUnpack = true;
+ src = value;
+ nativeBuildInputs = [ pkgs.zstd ];
+ buildPhase = ''
+ mtime=$(date -d '@${toString self.lastModified}' '+%Y%m%d %H:%M')
+ cp $src/bin/${name} "sorre-${name}"
+ tar -cf '${name}.tar.zst' --zstd "--mtime=$mtime" --mode=a+rX,u+w --dereference "sorre-${name}"
+ '';
+ installPhase = ''
+ mkdir -p $out
+ cp '${name}.tar.zst' $out/
+ '';
+ };
+
+ arch = builtins.head (lib.strings.splitString "-" system);
+
+ make-pkgbuild = name: version: archdeps:
+ pkgs.writeText "${name}-pkgbuild" ''
+ pkgname=sorre-${name}
+ pkgver=${version}
+ pkgrel=1
+ depends=${archdeps}
+ arch=('${arch}') # FIXME?
+ source=('${name}.tar.zst')
+ md5sums=('SKIP')
+
+ package() {
+ mkdir -p $pkgdir/usr/bin
+ tar -xf ${name}.tar.zst -C $pkgdir/usr/bin
+ }
+ '';
+
+ # make an Arch Linux compatible wrapper package
+ #
+ # This function only packages the **wrapper**, it does not include the package
+ # itself. Make sure the archeps are set correctly. The wrapper binary will be
+ # prefixed with `sorre-`.
+ #
+ # See:
+ # - https://man.archlinux.org/man/PKGBUILD.5
+ # - https://tonyfinn.com/blog/arch-packages-with-nix/
+ make-archpkg = { name, value, archdeps }:
+ let
+ tzst = make-tzst name value;
+ pkgbuild = make-pkgbuild name value.version archdeps;
+ in pkgs.stdenv.mkDerivation {
+ pname = "${name}-arch";
+ version = value.version;
+ src = tzst;
+ dontUnpack = true;
+ nativeBuildInputs = [ pkgs.zstd pkgs.pacman pkgs.fakeroot pkgs.libarchive ];
+ buildPhase = ''
+ cp $src/${name}.tar.zst .
+ cp ${pkgbuild} ./PKGBUILD
+
+ # FIXME: remove nodeps, build mtree myself :(
+ # having nodeps here means that pacman can't actaully resolve **any**
+ # dependecy, only warn you if they're missing.
+ PKGEXT=".pkg.tar.zst" makepkg --nodeps --config ${pkgs.pacman}/etc/makepkg.conf
+ '';
+
+ installPhase = ''
+ mkdir -p $out
+ cp *.pkg.tar.zst $out/
+ touch -m -d '@${toString self.lastModified}' $out/*.pkg.tar.zst
+ '';
+ };
+in
+{
+ gallery-dl = make-archpkg {
+ name = "gallery-dl";
+ value = wrappers.gallery-dl;
+ archdeps = "(gallery-dl)";
+ };
+}