/
flake.nix
93 lines (89 loc) · 3 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
89
90
91
92
93
{
description = "LICK: Install Puppy Linux in a few clicks";
inputs = {
nixpkgs.follows = "nix/nixpkgs";
fltk_tarball = {
type = "file";
url = "https://www.fltk.org/pub/fltk/1.3.5/fltk-1.3.5-source.tar.bz2";
flake = false;
};
libarchive_tarball = {
type = "file";
url = "https://libarchive.org/downloads/libarchive-3.3.1.tar.gz";
flake = false;
};
catch_header = {
type = "file";
url = "https://github.com/catchorg/Catch2/releases/download/v2.13.9/catch.hpp";
flake = false;
};
};
outputs = { self, nix, nixpkgs, fltk_tarball, libarchive_tarball, catch_header }: (
let
systems = [ "x86_64-linux" "mingw32" ];
forEachItem = items: f: (nixpkgs.lib.genAttrs items (item: (f item)));
forEachSystem = forEachItem systems;
project = nix_pkgs: {
name = "lick";
src = self;
buildInputs = ([]
++ nix_pkgs.lib.optional nix_pkgs.targetPlatform.isLinux [
nix_pkgs.pkgs.xorg.libX11
]
);
nativeBuildInputs = [
nix_pkgs.pkgs.buildPackages.cmake
nix_pkgs.pkgs.buildPackages.fltk
nix_pkgs.pkgs.buildPackages.nsis
];
configurePhase = ''
# Write nix cmake flags (including cross-compilation flags) to file.
touch nix-cmake-config.cmake
for i in $cmakeFlags; do
i="''${i:2}"
echo "set(''${i/%=*/} ''${i/#*=/})" >> nix-cmake-config.cmake
done
cmake . -DCMAKE_TOOLCHAIN_FILE=nix-cmake-config.cmake -DCMAKE_BUILD_TYPE=Release
# Copy external dependencies to avoid downloading them.
mkdir -p libarchive-3.3.1-prefix/src/
cp ${libarchive_tarball} libarchive-3.3.1-prefix/src/libarchive-3.3.1.tar.gz
mkdir -p fltk-1.3.5-prefix/src/
cp ${fltk_tarball} fltk-1.3.5-prefix/src/fltk-1.3.5-source.tar.bz2
mkdir -p test/catch-2.13.9/src/
cp ${catch_header} test/catch-2.13.9/src/catch.hpp
'';
buildPhase = ''
make
'';
doCheck = true;
checkPhase = ''
make test
'';
installPhase = ''
make package
mkdir -p $out
install -t $out LICK-*.zip;
# Linux does not create `.exe` files.
to_install=(LICK-*.exe)
for f in "''${to_install[@]}"; do install -t $out "$f"; done
'';
};
in {
packages = (
forEachSystem (system: (
let
nix_pkgs = (import nixpkgs { system = "${system}"; });
otherSystems = (nixpkgs.lib.filter (x: x != system) systems);
forEachOtherSystem = forEachItem otherSystems;
in {
default = nix_pkgs.stdenv.mkDerivation ((project nix_pkgs));
pkgsCross = forEachOtherSystem (target: (
let crossPkgs = nix_pkgs.pkgsCross."${target}";
in crossPkgs.stdenv.mkDerivation (project crossPkgs)
));
}
))
);
}
);
}