isle/default.nix
2023-02-15 12:04:56 +01:00

142 lines
3.3 KiB
Nix

# TODO
# - allow injecting a bootstrap file
# - try stripping flake of source info
# - Revert to not using flake for garage, we'll need to compile it ourselves
# because flakes don't actually support cross-compilation in a nice way.
#
# - Set ARCH arg for appimagetool target in default.nix
let
flakeCompat = import (builtins.fetchGit {
url = "https://github.com/edolstra/flake-compat.git";
rev = "009399224d5e398d03b22badca40a37ac85412a1";
});
# if this gets updated then flake.nix needs to be updated as well
garageSrc = builtins.fetchGit {
url = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git";
rev = "76230f20282e73a5a5afa33af68152acaf732cf5";
shallow = true;
};
in {
buildSystem ? builtins.currentSystem,
hostSystem ? builtins.currentSystem,
pkgs ? (import ./nix/pkgs.nix).default {
inherit buildSystem hostSystem;
},
garage ? (flakeCompat { src = garageSrc; }).defaultNix.packages."${hostSystem}".default,
selfRev ? "",
releaseName ? "debug",
}: rec {
inherit garage;
version = pkgs.stdenv.mkDerivation {
name = "cryptic-net-version";
inherit selfRev hostSystem releaseName;
repoSrc = ./.;
nativeBuildInputs = [ pkgs.git ];
# TODO it'd be nice to be able to call `go version`, but that doesn't work
# when crossSystem is being used for some unknown reason.
goVersion = pkgs.go.version;
garageVersion = garage.version;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
versionFile=version
if [ "$selfRev" = "" ]; then
cp -r "$repoSrc" repoSrcCp
selfRev="$(cd repoSrcCp && git rev-parse HEAD)"
fi
echo "Release $releaseName" >> "$versionFile"
echo "System: $hostSystem" >> "$versionFile"
echo "Git Revision: $selfRev" >> "$versionFile"
echo "Go Version: $goVersion" >> "$versionFile"
echo "Garage Version: $garageVersion" >> "$versionFile"
mkdir -p "$out"/share
cp "$versionFile" "$out"/share
'';
};
entrypoint = pkgs.callPackage ./entrypoint {};
dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix {
stdenv = pkgs.pkgsStatic.stdenv;
});
nebula = pkgs.callPackage ./nix/nebula.nix {};
appDir = pkgs.buildEnv {
name = "cryptic-net-AppDir";
paths = [
./AppDir
version
dnsmasq
nebula
garage
entrypoint
];
};
appimagetool = pkgs.callPackage ./nix/appimagetool.nix {};
appImage = pkgs.stdenv.mkDerivation {
name = "cryptic-net-AppImage";
src = appDir;
nativeBuildInputs = [
appimagetool
];
ARCH = "x86_64";
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
cp -rL "$src" cryptic-net.AppDir
chmod +w cryptic-net.AppDir -R
export VERSION=debug
# https://github.com/probonopd/go-appimage/issues/155
unset SOURCE_DATE_EPOCH
appimagetool ./cryptic-net.AppDir
mkdir -p "$out"/bin
chmod +w "$out" -R
mv Cryptic_Net-* "$out"/bin/cryptic-net
'';
};
release = pkgs.stdenv.mkDerivation {
name = "cryptic-net-release";
inherit appImage;
nativeBuildInputs = [ pkgs.coreutils ];
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
mkdir -p "$out"
cp "$appImage" "$out"/cryptic-net
(cd "$out" && sha256sum * > sha256.txt)
'';
};
}