aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: 60a501d7e413bbdc93041e6d34c891b69eb0ce5e (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  };

  outputs = {
    self,
    nixpkgs,
  }: let
    supportedSystems = ["x86_64-linux"];
    forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
    nixpkgsFor = forAllSystems (system:
      import nixpkgs {
        inherit system;
        overlays = [self.overlays.default];
      });
  in {
    overlays.default = final: prev: {
      node_modules = with final;
        stdenv.mkDerivation {
          pname = "readit-node-modules";
          version = "0.0.1";
          impureEnvVars =
            lib.fetchers.proxyImpureEnvVars
            ++ ["GIT_PROXY_COMMAND" "SOCKS_SERVER"];
          src = ./.;
          nativeBuildInputs = [bun];
          buildInputs = [nodejs-slim_latest];
          dontConfigure = true;
          dontFixup = true;
          buildPhase = ''
            bun install --no-progress --frozen-lockfile
          '';
          installPhase = ''
            mkdir -p $out/node_modules
            cp -R ./node_modules/* $out/node_modules
            ls -la $out/node_modules
          '';
          outputHash = "sha256-qFYgRIarDChHQu0ZrUKd/Y61gxaagMWpf2h9xizwGv4=";
          outputHashAlgo = "sha256";
          outputHashMode = "recursive";
        };
      readit = with final;
        stdenv.mkDerivation {
          pname = "readit";
          version = "0.0.1";
          src = ./.;
          nativeBuildInputs = [makeBinaryWrapper];
          buildInputs = [bun];

          buildPhase = ''
            runHook preBuild


            runHook postBuild
          '';

          dontFixup = true;

          installPhase = ''
            runHook preInstall

            mkdir -p $out/bin

            ln -s ${node_modules}/node_modules $out
            cp -R ./* $out

            # bun is referenced naked in the package.json generated script
            # makeBinaryWrapper ${bun}/bin/bun $out/bin/$pname \
            #   --add-flags "run --prefer-offline --no-install $out/app.js"

            makeBinaryWrapper ${bun}/bin/bun $out/bin/$pname \
            --prefix PATH : ${lib.makeBinPath [bun]} \
            --add-flags "run --prefer-offline --no-install $out/src/index.js"

          '';
        };
    };

    devShell = forAllSystems (system: let
      pkgs = nixpkgsFor."${system}";
    in
      pkgs.mkShell {
        nativeBuildInputs = [
          pkgs.bun
        ];
        RUST_BACKTRACE = 1;
      });

    packages = forAllSystems (system: {
      inherit (nixpkgsFor."${system}") readit node_modules;
    });

    defaultPackage = forAllSystems (system: nixpkgsFor."${system}".readit);

    apps = forAllSystems (system: let
      pkgs = nixpkgsFor.${system};
    in {
      default = {
        type = "app";
        program = "${pkgs.readit}/bin/readit";
      };
    });

    formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
  };
}