summaryrefslogtreecommitdiff
path: root/openwrt/packages.nix
blob: bf7b3a7ec0558121e58b4cf04cf0f88e1ad272af (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
{ pkgs, lib, config, ... }:

let
  deps = config.build.depsPackage;
in

{
  options.packages = lib.mkOption {
    type = lib.types.listOf lib.types.str;
    default = [];
    description = ''
      Extra packages to install. These are merely names of packages available
      to opkg through the package source lists configured on the device, it is
      not currently possible to provide packages for installation without
      configuring an opkg source first.
    '';
  };

  config = {
    deploySteps.packages = {
      priority = 9999;
      copy = ''
        scp ${deps} device:/tmp/deps-${deps.version}.ipk
      '';
      apply = ''
        if [ ${deps.version} != "$(opkg info ${deps.package_name} | grep Version | cut -d' ' -f2)" ]; then
          opkg update
          opkg install --autoremove --force-downgrade /tmp/deps-${deps.version}.ipk
        fi
      '';
    };

    build.depsPackage = pkgs.runCommand "deps.ipk" rec {
      package_name = ".extra-system-deps.";
      version = builtins.hashString "sha256" (toString config.packages);
      control = ''
        Package: ${package_name}
        Version: ${version}
        Architecture: all
        Description: extra system dependencies
        ${lib.optionalString
          (config.packages != [])
          "Depends: ${lib.concatStringsSep ", " config.packages}"
        }
      '';
      passAsFile = [ "control" ];
    } ''
      mkdir -p deps/control deps/data
      cp $controlPath deps/control/control
      echo 2.0 > deps/debian-binary

      alias tar='command tar --numeric-owner --group=0 --owner=0'
      (cd deps/control && tar -czf ../control.tar.gz ./*)
      (cd deps/data && tar -czf ../data.tar.gz .)
      (cd deps && tar -zcf $out ./debian-binary ./data.tar.gz ./control.tar.gz)
    '';
  };
}