isle/default.nix

185 lines
4.1 KiB
Nix
Raw Normal View History

2023-02-15 13:58:47 +00:00
{
buildSystem ? builtins.currentSystem,
2023-03-25 14:58:20 +00:00
hostSystem ? buildSystem,
pkgsNix ? (import ./nix/pkgs.nix),
2023-02-15 13:58:47 +00:00
revision ? "dev",
2023-03-25 14:58:20 +00:00
releaseName ? "dev",
2023-02-15 13:58:47 +00:00
}: let
pkgs = pkgsNix.default {
inherit buildSystem hostSystem;
};
2023-03-25 14:58:20 +00:00
pkgsNative = pkgsNix.default {
inherit buildSystem;
hostSystem = buildSystem;
};
2023-02-15 13:58:47 +00:00
garageNix = (import ./nix/garage.nix);
2023-02-15 13:58:47 +00:00
in rec {
2022-10-20 20:30:30 +00:00
version = pkgs.stdenv.mkDerivation {
name = "isle-version";
2023-03-25 14:58:20 +00:00
inherit buildSystem hostSystem revision releaseName;
2023-03-25 14:58:20 +00:00
nativeBuildInputs = [ pkgsNative.git ];
2022-10-20 20:30:30 +00:00
goVersion = pkgs.go.version;
2023-02-15 13:58:47 +00:00
garageVersion = garageNix.version;
nixpkgsVersion = pkgsNix.version;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
versionFile=version
2023-03-25 14:58:20 +00:00
echo "Release: $releaseName" >> "$versionFile"
echo "Platform: $hostSystem" >> "$versionFile"
echo "Git Revision: $revision" >> "$versionFile"
echo "Go Version: $goVersion" >> "$versionFile"
echo "Garage Version: $garageVersion" >> "$versionFile"
echo "NixPkgs Version: $nixpkgsVersion" >> "$versionFile"
echo "Build Platform: $buildSystem" >> "$versionFile"
mkdir -p "$out"/share
cp "$versionFile" "$out"/share
'';
};
goBinaries = pkgs.buildGoModule {
pname = "isle-go-binaries";
version = "unstable";
# If this seems pointless, that's because it is! buildGoModule doesn't like
# it if the src derivation's name ends in "-go". So this mkDerivation here
# only serves to give buildGoModule a src derivation with a name it likes.
src = pkgs.stdenv.mkDerivation {
name = "isle-go-src";
src = ./go;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
cp -r "$src" "$out"
'';
};
vendorHash = "sha256-R+8uCjWnWCDG7WLuSnjKnVfZwYSbjKqMPqJfMnnj6G0=";
subPackages = [
"./cmd/entrypoint"
];
};
dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix {
stdenv = pkgs.pkgsStatic.stdenv;
});
nebula = pkgs.callPackage ./nix/nebula.nix {};
garage = let
hostPlatform = pkgs.stdenv.hostPlatform.parsed;
2023-02-15 13:58:47 +00:00
in pkgs.callPackage garageNix.package {
inherit buildSystem;
hostSystem = "${hostPlatform.cpu.name}-unknown-${hostPlatform.kernel.name}-musl";
pkgsSrc = pkgsNix.src;
};
2024-10-05 19:12:29 +00:00
appDirBase = pkgs.buildEnv {
name = "isle-AppDir-base";
paths = [
./AppDir
version
dnsmasq
nebula
garage
pkgs.minio-client
];
2024-10-05 19:12:29 +00:00
};
2024-10-05 19:12:29 +00:00
appDir = pkgs.stdenv.mkDerivation {
name = "isle-AppDir";
2024-10-05 19:12:29 +00:00
src = appDirBase;
inherit goBinaries;
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
cp -rL "$src" "$out"
chmod +w "$out" -R
cd "$out"
2024-10-05 19:12:29 +00:00
cp $goBinaries/bin/entrypoint ./AppRun
'';
};
appimagetool = pkgs.callPackage ./nix/appimagetool.nix {};
appImage = pkgs.stdenv.mkDerivation {
name = "isle-AppImage";
src = appDir;
nativeBuildInputs = [
appimagetool
];
2023-02-15 13:58:47 +00:00
ARCH = pkgs.stdenv.hostPlatform.parsed.cpu.name;
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
cp -rL "$src" isle.AppDir
chmod +w isle.AppDir -R
export VERSION=debug
# https://github.com/probonopd/go-appimage/issues/155
unset SOURCE_DATE_EPOCH
appimagetool ./isle.AppDir
mv Isle-* "$out"
'';
};
2023-08-30 16:16:19 +00:00
appImageBin = pkgs.runCommand "isle-AppImage-bin" {} ''
mkdir -p "$out"/bin
cp ${appImage} "$out"/bin/isle
'';
2023-09-01 16:28:22 +00:00
tests = pkgs.writeScript "isle-tests" ''
export PATH=${pkgs.lib.makeBinPath [
appImageBin
pkgs.busybox
pkgs.yq-go
pkgs.jq
2023-09-06 19:55:05 +00:00
pkgs.dig
pkgs.nebula
]}
2023-09-01 16:28:22 +00:00
export SHELL=${pkgs.bash}/bin/bash
exec ${pkgs.bash}/bin/bash ${./tests}/entrypoint.sh "$@"
2023-08-30 16:16:19 +00:00
'';
2024-10-05 19:12:29 +00:00
devShell = pkgs.mkShell {
buildInputs = [
pkgs.go
pkgs.golangci-lint
pkgs.gopls
2024-10-05 19:12:29 +00:00
(pkgs.callPackage ./nix/gowrap.nix {})
];
shellHook = ''
true # placeholder
'';
};
testShell = pkgs.mkShell {
APPDIR = appDirBase;
buildInputs = [
pkgs.go
];
};
}