This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
79 lines (79 loc) · 2.55 KB
/
flake.nix
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
{
# a 2023-07-03 mashup of https://johns.codes/blog/building-typescript-node-apps-with-nix and https://github.com/akirak/flake-templates/tree/master/node-typescript
description = "sbstr8";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/master";
kubenix.url = "github:hall/kubenix";
flake-utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, nixpkgs
, kubenix
, flake-utils
, gitignore
, ...
}:
flake-utils.lib.eachDefaultSystem
(system:
let
nodejs = pkgs.nodejs;
pkgs = import nixpkgs { inherit system; };
node2nixOutput = import ./nix { inherit pkgs nodejs system; };
nodeDeps = node2nixOutput.nodeDependencies;
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
node2nix
nodePackages.typescript
nodePackages.typescript-language-server
];
};
packages = {
k8s = (kubenix.evalModules.${system} {
module = { kubenix, ... }: {
imports = with kubenix.modules; [k8s];
kubernetes.resources.pods.example.spec.containers.nginx.image = "nginx";
};
}).config.kubernetes.result;
docker = pkgs.dockerTools.buildImage {
name = "sbstr8";
config = {
Cmd = [ "./node_modules/next/dist/bin/next" ];
WorkingDir = "${self.packages.${system}.default}";
};
};
default = with pkgs; stdenv.mkDerivation {
name = "sbstr8";
src = gitignore.lib.gitignoreSource ./.;
buildInputs = [ nodejs ];
buildPhase = ''
runHook preBuild
ln -sf ${nodeDeps}/lib/node_modules ./node_modules
npm run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -r ./.next $out/.next
cp -r ./public $out/public
cp -r ./src $out/src
cp -r ${nodeDeps}/lib/node_modules $out/node_modules;
ln -sf $out/node_modules/next/dist/bin/next $out/bin/sbstr8;
runHook postInstall
'';
};
};
apps.default = {
type = "app";
program = "${self.packages.${system}.default}/node_modules/next/dist/bin/next";
};
});
}