-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
88 lines (73 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
80
81
82
83
84
85
86
87
88
{
description = "SQL Course Materials";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
edify.url = "github:pjones/edify/nixos-21.11";
edify.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, edify, ... }:
let
supportedSystems = [
# "aarch64-darwin"
# "aarch64-linux"
# "armv7l-linux"
# "x86_64-darwin"
"x86_64-linux"
];
# Function to generate a set based on supported systems:
forAllSystems = f:
nixpkgs.lib.genAttrs supportedSystems (system: f system);
# Attribute set of nixpkgs for each system:
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
config.allowUnfree = false;
});
in
{
packages = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in
{
sql-intro = pkgs.stdenvNoCC.mkDerivation {
pname = "sql-intro";
version = "1.0";
src =
pkgs.lib.cleanSourceWith {
src = pkgs.lib.cleanSource ./.;
filter = path: type:
!(type == "directory"
&& baseNameOf path == "build");
};
buildInputs = [
edify.outputs.defaultPackage.${system}
pkgs.zip
pkgs.sqlite-interactive
];
buildPhase = ''
# It's safe to run shell commands in the Nix sandbox.
edify build --unsafe-allow-commands
'';
installPhase = ''
mkdir -p "$out/$name/handouts" "$out/$name/slides"
cp -a LICENSE README.md src "$out/$name"
# Copy PDF files into the correct locations:
find build -type f -name '*.handout.pdf' -exec mv '{}' "$out/$name/handouts" ';'
find build -type f -name '*.slides.pdf' -exec mv '{}' "$out/$name/slides" ';'
# Rename PDF files:
for file in $out/$name/{handouts,slides}/*.pdf; do
mv "$file" "$(sed -E 's/[.](handout|slides)[.]pdf/.pdf/' <<<"$file")"
done
# Build archives:
( cd "$out" && zip -9 -y -r -q "$name.zip" "$name" )
'';
};
});
defaultPackage = forAllSystems (system:
self.packages.${system}.sql-intro);
devShell = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in
pkgs.mkShell {
inputsFrom = builtins.attrValues self.packages.${system};
});
};
}