summaryrefslogtreecommitdiffhomepage
path: root/gleam/flake.nix
blob: 9c096a0a4b2818516f271a1aa1f8c76ee95b8a8d (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
{
  description = "ssp-reader: a reader for the .ssp document abstraction, in Gleam";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux"; # adjust for aarch64-linux / darwin
      pkgs = import nixpkgs { inherit system; };

      name = "ssp_reader";

      /* The builder, nix-gleam's, kept here in nix-gleam/ (see the README
         there). It fetches each Hex dependency on its own, with the
         checksum gleam has already written into manifest.toml, so there is
         no hash in this file to keep up to date, and nothing a run of gleam
         could make come out differently.
      */
      inherit (pkgs.callPackage ./nix-gleam { }) buildGleamApplication;
    in {
      packages.${system} = {
        default = self.packages.${system}.${name};

        /* The reader as an escript: precompiled Erlang in a single file,
           which needs only erlang to run, no gleam and no dependencies.
           Verified reproducible: a second export is byte identical.
           nix-gleam builds an erlang-shipment by default; the build phase
           is replaced, its configure phase having already put the
           dependencies in place.
        */
        ${name} = buildGleamApplication {
          pname = name;
          version = "2.1.0";
          src = ./.;
          nativeBuildInputs = [ pkgs.makeWrapper ];
          buildPhase = ''
            runHook preBuild
            export HOME=$TMPDIR
            gleam export escript
            runHook postBuild
          '';
          installPhase = ''
            runHook preInstall
            mkdir -p $out/bin
            install -m755 ${name} $out/bin/${name}
            wrapProgram $out/bin/${name} \
              --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.beamPackages.erlang pkgs.coreutils ]}
            runHook postInstall
          '';
          meta = {
            description = "reads a .ssp document abstraction and says what is in it";
            mainProgram = name;
          };
        };
      };

      devShells.${system}.default = pkgs.mkShell {
        packages = [ pkgs.gleam pkgs.beamPackages.erlang pkgs.rebar3 ];
      };
    };
}