aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: b8892fa80b98ebda1e2cddf35b26a9581740b902 (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
{
  inputs = {
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils, ... }:
  utils.lib.eachDefaultSystem (system: 
  let
    pkgs = nixpkgs.legacyPackages."${system}";
    nativeBuildInputs = with pkgs; [
      flex
      bison
    ];

    buildScript = pkgs.writeScriptBin "build-script"
    ''
      set -e
      prog_name="$1"
      outdir="outputs/$prog_name"
      mkdir -p "$outdir"

      ${pkgs.flex}/bin/flex -o "$outdir"/lex.yy.cc "$prog_name"/main.l
      ${pkgs.gcc}/bin/gcc "$outdir"/lex.yy.cc -o "$outdir"/exec

      ./"$outdir"/exec < "$prog_name"/input
      rm -r "outputs"/*
      '';

  in rec {
    devShell = pkgs.mkShell {
      nativeBuildInputs = nativeBuildInputs ++ (with pkgs; [
        gcc
      ]);
    };
    defaultApp = {
      type = "app";
      program = "${buildScript}/bin/build-script";
    };
  });
}