-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix.test
172 lines (138 loc) · 4.17 KB
/
flake.nix.test
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
description = "Das kleine Bitcoin-Lexikon";
inputs = {
# use release 23.05 branch of the GitHub repository as input, this is the most common input format
# nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, nixpkgs
, flake-utils
, systems
, gitignore
,
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
# pkgs = import <nixpkgs> { };
# The path to the npm project
src = ./.;
# Read the package-lock.json as a Nix attrset
packageLock = builtins.fromJSON (builtins.readFile (src + "/package-lock.json"));
# Create an array of all (meaningful) dependencies
deps = builtins.attrValues (removeAttrs packageLock.packages [ "" ])
# ++ builtins.attrValues (removeAttrs packageLock.dependencies [ "" ])
;
# Turn each dependency into a fetchurl call
tarballs = map (p: pkgs.fetchurl { url = p.resolved; hash = p.integrity; }) deps;
# Write a file with the list of tarballs
tarballsFile = pkgs.writeTextFile {
name = "tarballs";
text = builtins.concatStringsSep "\n" tarballs;
};
in
{
# this shell can be instantiated with `nix develop`
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.nodejs-18_x
];
shellHook = ''
echo 'yoyoyo, nix is a go-go!'
# npm install
'';
};
packages.default = pkgs.mkShell {
buildInputs = [
pkgs.nodejs-18_x
];
shellHook = ''
echo 'yoyoyo, imma build dis lets go!'
npm install
npm build
'';
};
packages.testpkg = pkgs.mkShell {
buildInputs = [
pkgs.nodejs-18_x
];
shellHook = ''
echo 'yoyoyo, imma build dis lets go!'
npm install
npm build
'';
};
packages.deploy = pkgs.mkShell {
buildInputs = [
pkgs.nodejs-18_x
];
shellHook = ''
echo 'yoyoyo, imma deploy dis lets gooo!'
npm install
npm build
npm run deploy
'';
};
packages.lockTest = pkgs.stdenv.mkDerivation {
inherit (packageLock) name version;
inherit src;
buildInputs = [ pkgs.nodejs ];
buildPhase = ''
# export HOME=$PWD/.home
# export npm_config_cache=$PWD/.npm
# mkdir -p $out/js
# cd $out/js
# cp -r $src/. .
# while read package
# do
# echo "caching $package"
# npm cache add "$package"
# done <${tarballsFile}
echo "YOYOYOYOYOYOYOYOY BUUUUUUUUUUUUUUILD"
# npm ci
# npm run build
'';
installPhase = ''
ln -s $out/js/node_modules/.bin $out/bin
'';
};
packages.appBuild = pkgs.stdenv.mkDerivation {
name = "example-ts-node";
version = "0.1.0";
src = ./.;
# src = gitignore.lib.gitignoreSource ./.; # uses the gitignore in the repo to only copy files git would see
buildInputs = [
pkgs.nodejs-18_x
];
# https://nixos.org/manual/nixpkgs/stable/#sec-stdenv-phases
# configurePhase = ''
# echo "executing configurePhase"
# npm ci
# '';
buildPhase = ''
echo "executing buildPhase"
# each phase has pre/postHooks. When you make your own phase be sure to still call the hooks
runHook preBuild
# npm ci
npm run build
runHook postBuild
echo "output test" > $out
'';
installPhase = ''
echo "executing installPhase"
runHook preInstall
# cp -r node_modules $out/node_modules
# cp package.json $out/package.json
# cp -r dist $out/dist
runHook postInstall
'';
};
});
}