summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 76cda01407872f5d516073b2c3e607a992e561a5 (plain) (blame)
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
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/release-22.05";
    flake-utils.url = "github:numtide/flake-utils/master";
    gomod2nix.url = "github:tweag/gomod2nix/master";
    toaq-dictionary = { url = "github:toaq/dictionary/master"; flake = false; };
    zugai = { url = "github:toaq/zugai/main"; flake = false; };
  };

  outputs = { self, nixpkgs, gomod2nix, flake-utils, zugai, toaq-dictionary, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = (import nixpkgs {
          inherit system;
          overlays =
            [ gomod2nix.overlays.default (_: super: { go = super.go_1_17; }) ];
        }).pkgs;
      in with pkgs;
      let
        toaqScript = runCommand "toaq-script" { } ''
          mkdir -p $out/share/fonts
          cp ${./ToaqScript.ttf} $out/share/fonts/ToaqScript.ttf
        '';
        imagemagickWithPango = imagemagick.overrideAttrs
          (a: { buildInputs = a.buildInputs ++ [ pango ]; });
        expand-serial = runCommand "expand-serial" { } ''
          mkdir -p $out/bin
          tee >$out/bin/expand-serial <<EOF
          #!/bin/sh
          ${pkgs.python3}/bin/python ${zugai}/src/expand_serial.py \
            -d ${toaq-dictionary}/dictionary.json \
            -d ${zugai}/data/supplement.json \
            -- "\$@"
          EOF
          chmod +x $out/bin/expand-serial
        '';
        nuogai = buildGoApplication {
          vendorSha256 = null;
          runVend = true;
          name = "nuogai";
          src = ./.;
          modules = ./gomod2nix.toml;
          nativeBuildInputs = [ makeWrapper ];
          postFixup = ''
            wrapProgram $out/bin/nuogai --prefix PATH : ${
              lib.makeBinPath [ imagemagickWithPango expand-serial ]
            }
          '';
        };
      in {
        nixosModule = { config, pkgs, lib, ... }@args:
          import ./module.nix (args // { inherit self system; });
        devShells.${system} = gomod2nix.devShells.${system};
        defaultPackage = nuogai;
        packages = { inherit nuogai expand-serial toaqScript; };
      });
}