This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
81 lines (69 loc) · 2.39 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
80
81
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = import nixpkgs { inherit system; };
node = pkgs.nodejs_22;
src = pkgs.lib.cleanSource ./.;
packageJson = pkgs.lib.sourceByRegex ./. [
"^package.json$"
"^package-lock.json$"
];
npm-install = pkgs.writeShellApplication {
name = "npm-install";
runtimeInputs = [ node pkgs.coreutils pkgs.bash ];
text = ''
export HOME=$PWD # npm will modify $HOME
cp ${packageJson}/* .
chmod 0644 package*.json
npm clean-install
mv node_modules "''${out:?}"
'';
};
nodeModules = pkgs.stdenv.mkDerivation {
name = "hackerinnen-list-node-modules";
builder = "${npm-install}/bin/npm-install";
outputHashMode = "recursive";
outputHash = "sha256-mYCj67nmXruHZdUL7fd/IxWI4wCf9JDpHms56M2vXWk=";
};
in {
# Building the website requires network access not available in a Nix
# build sandbox. Therefore the package is not the static website
# itself, but a script building the website. We still try to minimize
# side effects outside our build directory.
packages.build = pkgs.writeShellApplication {
name = "build-hackerinnen-website";
runtimeInputs = [ node ];
text = ''
export PATH=${nodeModules}/.bin:$PATH
export ASTRO_TELEMETRY_DISABLED=1
dest_dir=$(realpath "$1")
if [[ ! -d "$dest_dir" ]]; then
echo "$dest_dir does not exist, aborting."
exit 1
fi
cd "$(mktemp -d)"
cp -r "${src}" src/
chmod u+w src/
# Running Astro changes the node_modules/ directory, so we have to
# copy it instead of merely creating a symlink.
cp -r "${nodeModules}" src/node_modules
chmod -R u+w src/
cd src/
npm run build
mv dist/* "$dest_dir"
'';
};
devShells.default = pkgs.mkShell {
buildInputs = [
node
pkgs.just
];
};
}
);
}