summaryrefslogtreecommitdiff
path: root/archpkgs.nix
diff options
context:
space:
mode:
authorIsabella Bastaja <isabella@sorre.xyz>2026-03-23 00:55:55 +0100
committerIsabella Bastaja <isabella@sorre.xyz>2026-03-23 18:46:41 +0100
commit3613c8d67802a9827e00bc9213e8ee79413e4f0e (patch)
treef795f49c9459fbaf33fbe1e9bf1dac91fd86bcb7 /archpkgs.nix
parent50e2588f76ef70c8ea14df13e313618c00d15dcb (diff)
WIP: packaging wrappers for arch
This change partially implements packaing wrapper scripts into Arch Linux packages. I managed to package the wrapper binary itself successfully, but the current implementation is not usable as it doesn't package the required config files with the wrapper. The issue is that I'd need to iterate the derivation's inputs and filter out the wrapped program, leaving only the config files. I need more time to figure out how to do this. In the meantime I'm leaving the broken version here as a scaffold. P.S. this could be implemented by directly building MTREE files too instead of pkgbuilds. I chose pkgbuilds for simplicity. References: - https://tonyfinn.com/blog/arch-packages-with-nix/
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)";
+ };
+}