summaryrefslogtreecommitdiff
path: root/archpkgs.nix
blob: 37f8236f6c64b034c2d9dd48dded5d257179c732 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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)";
  };
}