diff options
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..917e2e0 --- /dev/null +++ b/flake.nix | |||
@@ -0,0 +1,99 @@ | |||
1 | { | ||
2 | inputs = { | ||
3 | |||
4 | nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||
5 | |||
6 | }; | ||
7 | |||
8 | outputs = | ||
9 | { self | ||
10 | , nixpkgs | ||
11 | }: | ||
12 | let | ||
13 | supportedSystems = [ "x86_64-linux" ]; | ||
14 | forAllSystems = nixpkgs.lib.genAttrs supportedSystems; | ||
15 | nixpkgsFor = forAllSystems (system: | ||
16 | import nixpkgs { | ||
17 | inherit system; | ||
18 | overlays = [ self.overlays.default ]; | ||
19 | }); | ||
20 | |||
21 | in | ||
22 | { | ||
23 | overlays.default = final: prev: { | ||
24 | node_modules = with final; stdenv.mkDerivation { | ||
25 | pname = "readit-node-modules"; | ||
26 | version = "0.0.1"; | ||
27 | impureEnvVars = lib.fetchers.proxyImpureEnvVars | ||
28 | ++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ]; | ||
29 | src = ./.; | ||
30 | nativeBuildInputs = [ bun ]; | ||
31 | buildInputs = [ nodejs-slim_latest ]; | ||
32 | dontConfigure = true; | ||
33 | dontFixup = true; | ||
34 | buildPhase = '' | ||
35 | bun install --no-progress --frozen-lockfile | ||
36 | ''; | ||
37 | installPhase = '' | ||
38 | mkdir -p $out/node_modules | ||
39 | cp -R ./node_modules/* $out/node_modules | ||
40 | ls -la $out/node_modules | ||
41 | ''; | ||
42 | outputHash = "sha256-qFYgRIarDChHQu0ZrUKd/Y61gxaagMWpf2h9xizwGv4="; | ||
43 | outputHashAlgo = "sha256"; | ||
44 | outputHashMode = "recursive"; | ||
45 | }; | ||
46 | readit = with final; stdenv.mkDerivation { | ||
47 | pname = "readit"; | ||
48 | version = "0.0.1"; | ||
49 | src = ./.; | ||
50 | nativeBuildInputs = [ makeBinaryWrapper ]; | ||
51 | buildInputs = [ bun ]; | ||
52 | |||
53 | buildPhase = '' | ||
54 | runHook preBuild | ||
55 | |||
56 | |||
57 | runHook postBuild | ||
58 | ''; | ||
59 | |||
60 | dontFixup = true; | ||
61 | |||
62 | installPhase = '' | ||
63 | runHook preInstall | ||
64 | |||
65 | mkdir -p $out/bin | ||
66 | |||
67 | # cp app.js $out/app.js | ||
68 | cp -R ./* $out | ||
69 | |||
70 | # bun is referenced naked in the package.json generated script | ||
71 | # makeBinaryWrapper ${bun}/bin/bun $out/bin/$pname \ | ||
72 | # --add-flags "run --prefer-offline --no-install $out/app.js" | ||
73 | |||
74 | makeBinaryWrapper ${bun}/bin/bun $out/bin/$pname \ | ||
75 | --prefix PATH : ${lib.makeBinPath [ bun ]} \ | ||
76 | --add-flags "run --prefer-offline --no-install $out/src/index.js" | ||
77 | |||
78 | ''; | ||
79 | }; | ||
80 | }; | ||
81 | |||
82 | devShell = forAllSystems (system: | ||
83 | let | ||
84 | pkgs = nixpkgsFor."${system}"; | ||
85 | in | ||
86 | pkgs.mkShell { | ||
87 | nativeBuildInputs = [ | ||
88 | pkgs.bun | ||
89 | ]; | ||
90 | RUST_BACKTRACE = 1; | ||
91 | }); | ||
92 | |||
93 | packages = forAllSystems(system: { | ||
94 | inherit (nixpkgsFor."${system}") readit node_modules; | ||
95 | }); | ||
96 | }; | ||
97 | } | ||
98 | |||
99 | |||