diff options
| author | Isabella Bastaja <isabella@sorre.xyz> | 2026-03-23 00:55:55 +0100 |
|---|---|---|
| committer | Isabella Bastaja <isabella@sorre.xyz> | 2026-03-23 18:46:41 +0100 |
| commit | 3613c8d67802a9827e00bc9213e8ee79413e4f0e (patch) | |
| tree | f795f49c9459fbaf33fbe1e9bf1dac91fd86bcb7 | |
| parent | 50e2588f76ef70c8ea14df13e313618c00d15dcb (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/
| -rw-r--r-- | archpkgs.nix | 82 | ||||
| -rw-r--r-- | default.nix | 8 | ||||
| -rw-r--r-- | flake.nix | 4 |
3 files changed, 91 insertions, 3 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)"; + }; +} diff --git a/default.nix b/default.nix index 3a871d5..a2dc56f 100644 --- a/default.nix +++ b/default.nix @@ -1,9 +1,10 @@ { + self, pkgs ? import <nixpkgs> { }, wrapper-manager, + system, }: let - recursiveMerge = with pkgs.lib; attrList: @@ -44,11 +45,14 @@ let ./wrappers/gallery-dl ]; }; + wrappers = wm-eval.config.build.packages; + + archpkgs = import ./archpkgs.nix { inherit self pkgs wrappers system; }; in { + inherit wrappers archpkgs; lib = import ./lib { inherit pkgs; }; modules = import ./modules; overlays = import ./overlays; - wrappers = wm-eval.config.build.packages; } // packages @@ -28,7 +28,9 @@ }; in { - legacyPackages = import ./default.nix { inherit pkgs wrapper-manager; }; + legacyPackages = import ./default.nix { + inherit self pkgs wrapper-manager system; + }; packages = nixpkgs.lib.filterAttrs (_: v: nixpkgs.lib.isDerivation v) self.legacyPackages.${system}; } ); |
