Skip to content

Commit cd6b532

Browse files
committed
feat: add Nix and NixOS assets
1 parent 8131f3f commit cd6b532

File tree

15 files changed

+3237
-0
lines changed

15 files changed

+3237
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
node_modules
22
db/*
33
*.log
4+
5+
# VM disk images
6+
*.qcow2
7+
8+
# Nix build results
9+
result
10+
result-*
11+
repl-result-*
12+
13+
# NixOS test driver REPL history
14+
.nixos-test-history

app.nix

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
lib,
3+
config,
4+
dream2nix,
5+
pkgs,
6+
...
7+
} @ args: let
8+
packageJSON = lib.importJSON ./package.json;
9+
in {
10+
imports = [
11+
dream2nix.modules.dream2nix.nodejs-package-json-v3
12+
dream2nix.modules.dream2nix.nodejs-granular-v3
13+
];
14+
15+
inherit (packageJSON) name version;
16+
17+
# Take advantage of a shell injection vector in dream2nix in order to apply a
18+
# workaround for an issue with `npm i` converting dependencies specified with
19+
# `git+https://` or `github:` to `git+ssh://`.
20+
# See:
21+
# - https://github.com/npm/cli/issues/2610
22+
# - https://github.com/npm/cli/issues/2631
23+
nodejs-package-json.npmArgs = lib.mkAfter [
24+
"--package-lock-only' ; ${lib.getExe pkgs.gnused} -i -e 's|git+ssh://|git+https://|g' ./package-lock.json #"
25+
];
26+
27+
mkDerivation = {
28+
src = lib.cleanSource ./.;
29+
doCheck = false;
30+
meta = {
31+
# XXX broken somehow? `lib.licenses.gpl3` works...
32+
#license = lib.licenses.cc-by-nc-40;
33+
homepage = "https://github.com/LowPowerLab/RaspberryPi-Gateway";
34+
};
35+
};
36+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Modification of nixpkgs deviceTree.applyOverlays to resolve https://github.com/NixOS/nixpkgs/issues/125354.
2+
#
3+
# Derived from https://github.com/NixOS/nixpkgs/blob/916ca8f2b0c208def051f8ea9760c534a40309db/pkgs/os-specific/linux/device-tree/default.nix.
4+
#
5+
# This replaces the default device tree overlay application process
6+
# to use `dtmerge` from `libraspberrypi`. The default overlay
7+
# application process can be problematic on Raspberry Pis due to
8+
# (among other things) issues like this:
9+
#
10+
# https://github.com/raspberrypi/firmware/issues/1718
11+
#
12+
# and `fdtget`-based compatibility checks, which yield false
13+
# negatives (overlay is compatible, but the check says it is not):
14+
#
15+
# $ dtbCompat="$(fdtget -t s ./boot/bcm2710-rpi-3-b-plus.dtb / compatible | tee /dev/stderr)"
16+
# raspberrypi,3-model-b-plus brcm,bcm2837
17+
# $ overlayCompat="$(fdtget -t s ./boot/overlays/disable-bt.dtbo / compatible | tee /dev/stderr)"
18+
# brcm,bcm2835
19+
# $ [[ "$dtbCompat" =~ "$overlayCompat" ]] ; echo "$?"
20+
# 1
21+
#
22+
# The upstream/default merging logic is here:
23+
#
24+
# https://github.com/NixOS/nixpkgs/blob/c999f2e369508fca13646ca5a0fb926b3ce0063e/pkgs/os-specific/linux/device-tree/default.nix#L27-L65
25+
#
26+
# The `nixos-hardware` override is here:
27+
#
28+
# https://github.com/NixOS/nixos-hardware/blob/33a97b5814d36ddd65ad678ad07ce43b1a67f159/raspberry-pi/4/pkgs-overlays.nix#L5
29+
final: prev: {
30+
deviceTree =
31+
prev.deviceTree
32+
// {
33+
applyOverlays = base: overlays':
34+
final.stdenvNoCC.mkDerivation {
35+
name = "device-tree-overlays";
36+
nativeBuildInputs = with final; [dtc libraspberrypi];
37+
buildCommand = let
38+
overlays = final.lib.toList overlays';
39+
in ''
40+
mkdir -p $out
41+
cd "${base}"
42+
find . -type f -name '*.dtb' -print0 \
43+
| xargs -0 cp -v --no-preserve=mode --target-directory "$out" --parents
44+
45+
for dtb in $(find "$out" -type f -name '*.dtb'); do
46+
dtbCompat=$(fdtget -t s "$dtb" / compatible 2>/dev/null || true)
47+
# skip files without `compatible` string
48+
test -z "$dtbCompat" && continue
49+
50+
${final.lib.concatMapStringsSep "\n" (o: ''
51+
overlayCompat="$(fdtget -t s "${o.dtboFile}" / compatible)"
52+
53+
# skip incompatible and non-matching overlays
54+
if ! { [[ "$dtbCompat" =~ "$overlayCompat" ]] || [[ "$overlayCompat" = brcm,bcm2835 ]]; }; then
55+
echo "Skipping overlay ${o.name}: incompatible with $(basename "$dtb")"
56+
elif ${
57+
if ((o.filter or null) == null)
58+
then "false"
59+
else ''
60+
[[ "''${dtb//${o.filter}/}" == "$dtb" ]]
61+
''
62+
}
63+
then
64+
echo "Skipping overlay ${o.name}: filter does not match $(basename "$dtb")"
65+
else
66+
echo -n "Applying overlay ${o.name} to $(basename "$dtb")... "
67+
mv "$dtb"{,.in}
68+
69+
# dtmerge requires a .dtbo ext for dtbo files, otherwise it adds it to the given file implicitly
70+
dtboWithExt="$TMPDIR/$(basename "${o.dtboFile}").dtbo"
71+
cp -r ${o.dtboFile} "$dtboWithExt"
72+
73+
dtmerge "$dtb.in" "$dtb" "$dtboWithExt"
74+
75+
echo "ok"
76+
rm "$dtb.in" "$dtboWithExt"
77+
fi
78+
'')
79+
overlays}
80+
81+
done'';
82+
};
83+
};
84+
}

0 commit comments

Comments
 (0)