aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: 6e86ab9e447ea223c3c8f2703e73a76b215265e5 (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
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    beaker-src = {
      url = "git+https://git.bwaaa.monster/beaker";
      flake = false;
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      beaker-src,
    }:
    let
      supportedSystems = [
        "x86_64-linux"
        "aarch64-linux"
      ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
    in
    {
      formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt);
      packages = forAllSystems (
        system:
        let
          pkgs = import nixpkgs { inherit system; };

          beaker = pkgs.stdenv.mkDerivation {
            pname = "beaker";
            version = "git";
            src = beaker-src;
            makeFlags = [
              "INSTALL_PREFIX=$(out)/"
              "LDCONFIG=true"
            ];
          };
        in
        {
          default = pkgs.stdenv.mkDerivation {
            pname = "omnisearch";
            version = "git";
            src = ./.;

            buildInputs = [
              pkgs.libxml2.dev
              pkgs.curl.dev
              pkgs.openssl
              beaker
            ];

            preBuild = ''
              makeFlagsArray+=(
                "PREFIX=$out"
                "CFLAGS=-Wall -Wextra -O2 -Isrc -I${pkgs.libxml2.dev}/include/libxml2"
                "LIBS=-lbeaker -lcurl -lxml2 -lpthread -lm -lssl -lcrypto"
              )
            '';

            installPhase = ''
              mkdir -p $out/bin $out/share/omnisearch
              install -Dm755 bin/omnisearch $out/bin/omnisearch
              cp -r templates static -t $out/share/omnisearch/
            '';

            meta = {
              description = "Lightweight metasearch engine in C";
              platforms = pkgs.lib.platforms.linux;
            };
          };
        }
      );
      nixosModules.default = import ./module.nix self;
    };
}