Compare commits

...

5 Commits
v0.0.3 ... main

26 changed files with 283 additions and 180 deletions

View File

@ -3,8 +3,13 @@
hostSystem ? buildSystem,
pkgsNix ? (import ./nix/pkgs.nix),
revision ? "dev",
# We allow passing in the revision because nix flakes have their own mechanism
# for determining the git revision, and they don't have the git repo present
# to determine it off of the normal way.
revision ? null,
releaseName ? "dev",
buildNumber ? "1",
}: let
pkgs = pkgsNix.default {
@ -20,12 +25,22 @@
in rec {
revisionFile = if builtins.isNull revision
then pkgsNative.stdenv.mkDerivation {
name = "revision.txt";
nativeBuildInputs = [ pkgsNative.git ];
src = ./.git;
phases = [ "installPhase" ];
installPhase = ''
git -c safe.directory='*' -C $src describe --tags > $out
'';
}
else pkgsNative.writeText "revision.txt" revision;
version = pkgs.stdenv.mkDerivation {
name = "isle-version";
inherit buildSystem hostSystem revision releaseName;
nativeBuildInputs = [ pkgsNative.git ];
inherit buildSystem hostSystem revisionFile;
goVersion = pkgs.go.version;
garageVersion = garageNix.version;
@ -36,41 +51,37 @@ in rec {
versionFile=version
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"
echo "Version: $(cat $revisionFile)" >> "$versionFile"
echo "Platform: $hostSystem" >> "$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
mkdir -p "$out"
cp "$versionFile" "$out"/version
'';
};
goBinaries = pkgs.buildGoModule {
pname = "isle-go-binaries";
version = "unstable";
entrypoint = {
systemRoot ? null,
}: (pkgs.buildGoModule {
pname = "isle-entrypoint";
version = builtins.readFile revisionFile;
# 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"
'';
};
src = pkgs.runCommand "isle-go-src" {} ''cp -r "${./go}" "$out"'';
vendorHash = "sha256-uq+UgoVKqMUE4hEVlMFQnZuyFOilUyZDmiy7ASrq338=";
subPackages = [
"./cmd/entrypoint"
];
};
subPackages = [ "./cmd/entrypoint" ];
}).overrideAttrs (prev: {
ldflags = prev.ldflags ++
(if builtins.isNull systemRoot
then []
else [ "-X main.systemRoot=${systemRoot}" ]);
});
dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix {
stdenv = pkgs.pkgsStatic.stdenv;
@ -78,30 +89,28 @@ in rec {
nebula = pkgs.callPackage ./nix/nebula.nix {};
garage = let
hostPlatform = pkgs.stdenv.hostPlatform.parsed;
in garageNix.package {
inherit pkgsNix buildSystem;
hostSystem = "${hostPlatform.cpu.name}-unknown-${hostPlatform.kernel.name}-musl";
garage = garageNix.package {
inherit pkgsNix buildSystem hostSystem;
};
appDirBase = pkgs.buildEnv {
name = "isle-AppDir-base";
paths = [
./AppDir
version
dnsmasq
nebula
garage
pkgs.minio-client
];
};
appDirBase = pkgs.runCommand "isle-AppDir-base" {} ''
mkdir -p "$out"/usr/libexec/isle
cp ${dnsmasq}/bin/* "$out"/usr/libexec/isle
cp ${nebula}/bin/* "$out"/usr/libexec/isle
cp ${garage}/bin/* "$out"/usr/libexec/isle
cp ${pkgs.minio-client}/bin/* "$out"/usr/libexec/isle
appDir = pkgs.stdenv.mkDerivation {
cp ${./AppDir}/* "$out"/
mkdir -p "$out"/usr/share/isle
cp ${version}/* "$out"/usr/share/isle
'';
appDir = { systemRoot ? null, }: pkgs.stdenv.mkDerivation {
name = "isle-AppDir";
src = appDirBase;
inherit goBinaries;
entrypoint = entrypoint { inherit systemRoot; };
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
@ -109,7 +118,9 @@ in rec {
chmod +w "$out" -R
cd "$out"
cp $goBinaries/bin/entrypoint ./AppRun
mkdir -p ./usr/bin
cp $entrypoint/bin/entrypoint ./usr/bin/isle
ln -s ./usr/bin/isle ./AppRun
'';
};
@ -133,36 +144,40 @@ in rec {
];
};
appimagekit = pkgsNative.callPackage ./nix/appimagetool {
inherit hostSystem;
};
build = rec {
appImage = pkgs.stdenv.mkDerivation {
name = "isle-AppImage";
src = appDir;
src = appDir {};
inherit revisionFile;
nativeBuildInputs = [
(pkgsNative.callPackage ./nix/appimagetool.nix {})
];
ARCH = pkgs.stdenv.hostPlatform.parsed.cpu.name;
nativeBuildInputs = [ appimagekit ];
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
export VERSION=$(cat $revisionFile)
mkdir -p "$out"/bin
mv Isle-* "$out"/bin/isle
appimagetool ./isle.AppDir "$out"/bin/isle
'';
};
archPkg = ((import ./dist/linux/arch) {
inherit hostSystem releaseName appImage;
inherit hostSystem releaseName buildNumber;
pkgs = pkgsNative;
appDir = appDir { systemRoot = "/"; };
});
debPkg = ((import ./dist/linux/deb) {
inherit hostSystem releaseName buildNumber;
pkgs = pkgsNative;
appDir = appDir { systemRoot = "/"; };
});
};
}

View File

@ -2,7 +2,8 @@
pkgs,
hostSystem,
releaseName,
appImage,
buildNumber ? "1",
appDir,
}: let
cpuArch = (pkgs.lib.systems.parse.mkSystemFromString hostSystem).cpu.name;
@ -10,33 +11,25 @@
pkgbuild = pkgs.writeText "isle-arch-PKGBUILD-${releaseName}-${cpuArch}" ''
pkgname=isle
pkgver=${builtins.replaceStrings ["-"] ["_"] releaseName}
pkgrel=0
pkgdesc="The foundation for an autonomous community cloud infrastructure."
pkgrel=${buildNumber}
pkgdesc="The foundation for an autonomous community cloud infrastructure"
arch=('${cpuArch}')
url="https://code.betamike.com/micropelago/isle"
license=('AGPL-3.0-or-later')
depends=(
'fuse2'
)
# The appImage is deliberately kept separate from the src.tar.zst. For some
# reason including the appImage within the archive results in a large part
# of the binary being stripped away and some weird skeleton appImage comes
# out the other end.
source=('isle' 'src.tar.zst')
md5sums=('SKIP' 'SKIP')
noextract=('isle')
source=('src.tar.zst')
md5sums=('SKIP')
package() {
cp -r etc "$pkgdir"/etc
cp -r usr "$pkgdir"/usr
mkdir -p "$pkgdir"/usr/bin/
cp isle "$pkgdir"/usr/bin/
}
'';
linuxRoot = (import ../default.nix).buildRoot {
inherit pkgs appDir;
};
in
pkgs.stdenv.mkDerivation {
name = "isle-arch-pkg-${releaseName}-${cpuArch}";
@ -49,28 +42,13 @@ in
];
inherit pkgbuild;
src = appImage;
defaultDaemonYml = ../../../go/daemon/daecommon/daemon.yml;
systemdService = ../isle.service;
src = linuxRoot;
dontUnpack = true;
buildPhase = ''
mkdir -p root/etc/isle/
cp "$defaultDaemonYml" root/etc/isle/daemon.yml
mkdir -p root/usr/lib/sysusers.d/
cat >root/usr/lib/sysusers.d/isle.conf <<EOF
u isle - "isle Daemon"
EOF
mkdir -p root/usr/lib/systemd/system
cp "$systemdService" root/usr/lib/systemd/system/isle.service
tar -cf src.tar.zst --zstd --mode=a+rX,u+w -C "$src" .
cp $pkgbuild PKGBUILD
tar -cf src.tar.zst --zstd --mode=a+rX,u+w -C root .
cp "$src"/bin/isle isle
PKGEXT=".pkg.tar.zst" CARCH="${cpuArch}" makepkg \
--nodeps \
--config ${pkgs.pacman}/etc/makepkg.conf

73
dist/linux/deb/default.nix vendored Normal file
View File

@ -0,0 +1,73 @@
{
pkgs,
hostSystem,
releaseName,
buildNumber ? "1",
appDir,
}: let
debArch = builtins.getAttr hostSystem {
"x86_64-linux" = "amd64";
"aarch64-linux" = "arm64";
"armv6l-linux" = "armhf";
"i686-linux" = "i386";
};
control = pkgs.writeTextDir "DEBIAN/control" ''
Package: isle
Version: ${releaseName}-${buildNumber}
Section: net
Priority: optional
Architecture: ${debArch}
Maintainer: Brian Picciano <me@mediocregopher.com>
Description: The foundation for an autonomous community cloud infrastructure
Homepage: https://code.betamike.com/micropelago/isle
'';
postinst = pkgs.writeTextDir "DEBIAN/postinst" ''
#!/bin/sh
systemctl daemon-reload
systemd-sysusers /usr/lib/sysusers.d/isle.conf
'';
postrm = pkgs.writeTextDir "DEBIAN/postrm" ''
#!/bin/sh
systemctl daemon-reload
'';
linuxRoot = (import ../default.nix).buildRoot {
inherit pkgs appDir;
};
root = pkgs.buildEnv {
name = "isle-deb-pkg-root";
paths = [
linuxRoot
control
postinst
postrm
];
};
in pkgs.stdenv.mkDerivation {
name = "isle-deb-pkg";
nativeBuildInputs = [
pkgs.zstd
pkgs.dpkg
];
src = root;
buildPhase = ''
cp -rL "$src" root
chmod +w -R root
chmod +x root/DEBIAN/post*
dpkg-deb \
--root-owner-group \
-Z zstd \
-b root isle_${releaseName}-${buildNumber}_${debArch}.deb
'';
installPhase = ''
mkdir -p "$out"
cp *.deb "$out"
'';
}

18
dist/linux/default.nix vendored Normal file
View File

@ -0,0 +1,18 @@
{
buildRoot = { pkgs, appDir}: pkgs.runCommand "isle-linux-root" {} ''
mkdir -p "$out"
cp -r ${appDir}/usr "$out"/
chmod +w -R "$out"/usr
mkdir -p "$out"/etc/isle
cp "${../../go/daemon/daecommon/daemon.yml}" "$out"/etc/isle/daemon.yml
mkdir -p "$out"/usr/lib/sysusers.d/
cat >"$out"/usr/lib/sysusers.d/isle.conf <<EOF
u isle - "isle Daemon"
EOF
mkdir -p "$out"/usr/lib/systemd/system
cp "${./isle.service}" "$out"/usr/lib/systemd/system/isle.service
'';
}

View File

@ -8,12 +8,21 @@ A release consists of:
- A file containing a signature of the hash file, created by whoever is building
the release.
Releases are named using semantic versioning: <major>.<minor>.<patch>. A
preceding "v" is NOT a part of the canonical release name, though it use used in
specific contexts.
Release artifacts are also be labeled with a suffix indicating build number, eg
"0.1.3-2" which indicates that this is of release "0.1.3". The first build of a
release is always "1". Different build numbers of the same release indicate that
no code is different, only the packaging.
## Building
*NOTE: This has only been tested from an x86_64 linux machine*
To create a release only a functional nix installation is required. Simply run
the `./release.sh` script, and input a release name when prompted.
the `./release.sh` script, providing the release name and build number.
From here an `isle` binary will be cross-compiled for all supported
platforms. This will take a long time the first time you perform it on your
@ -25,12 +34,13 @@ create the signature.
## Releasing
Release artifactes are hosted at `micropelago.net` under
`/isle/releases/<release name>`. An `index.gmi` page should be created in that
Release artifacts are hosted at `micropelago.net` under
`/isle/releases/v<release name>`. An `index.gmi` page should be created in that
directory which includes links to each artifact, as well as a changelog
detailing all new features and fixes included since the previous release.
A link to the new release should be included at `/isle/releases/index.gmi`.
The release shoulld be tagged in the git repo using its release name as well,
with the tag notes linking to the `micropelago.net` page.
Each release should be tagged in the git repo using the release name and build
number prefixed with a "v". If the build number of the release is "1" then the
tag notes should link to the `micropelago.net` release page for the release.

View File

@ -9,6 +9,7 @@ supported:
- `x86_64` (aka `amd64`)
- `aarch64` (aka `arm64`)
- `i686`
- `armv6l` (For older Raspberry Pis)
(`i686` has not been tested.)

View File

@ -43,7 +43,7 @@ var subCmdDaemon = subCmd{
networkLoader, err := network.NewLoader(
ctx,
ctx.logger.WithNamespace("network-loader"),
envBinDirPath,
getBinDirPath(),
nil,
)
if err != nil {

View File

@ -15,18 +15,30 @@ import (
"github.com/adrg/xdg"
)
func getAppDirPath() string {
appDirPath := os.Getenv("APPDIR")
if appDirPath == "" {
appDirPath = "."
const systemRootPath = ""
func getSystemRootPath() string {
if systemRootPath != "" {
return systemRootPath
}
return appDirPath
if appDirPath := os.Getenv("APPDIR"); appDirPath != "" {
return appDirPath
}
return "/"
}
func getBinDirPath() string {
return filepath.Join(getSystemRootPath(), "usr/libexec/isle")
}
func getShareDirPath() string {
return filepath.Join(getSystemRootPath(), "usr/share/isle")
}
var (
envAppDirPath = getAppDirPath()
envBinDirPath = filepath.Join(envAppDirPath, "bin")
envCacheDir = sync.OnceValue(func() toolkit.Dir {
envCacheDir = sync.OnceValue(func() toolkit.Dir {
cacheHome, err := toolkit.MkDir(xdg.CacheHome, true)
if err != nil {
panic(fmt.Errorf("creating cache directory %q: %w", xdg.CacheHome, err))
@ -42,7 +54,7 @@ var (
)
func binPath(name string) string {
return filepath.Join(envBinDirPath, name)
return filepath.Join(getBinDirPath(), name)
}
var rootCmd = subCmd{

View File

@ -17,7 +17,7 @@ var subCmdVersion = subCmd{
return fmt.Errorf("parsing flags: %w", err)
}
versionPath := filepath.Join(envAppDirPath, "share/version")
versionPath := filepath.Join(getShareDirPath(), "version")
version, err := os.ReadFile(versionPath)
if err != nil {

View File

@ -28,7 +28,7 @@ var (
if appDirPath == "" {
panic("APPDIR not set")
}
return filepath.Join(appDirPath, "bin")
return filepath.Join(appDirPath, "usr/libexec/isle")
})
ipNetCounter = new(atomic.Uint64)

View File

@ -1,40 +0,0 @@
{ stdenv, fetchurl }:
let
version = "765";
cpuArch = stdenv.buildPlatform.parsed.cpu.name;
srcDir = ./go-appimage;
# https://github.com/probonopd/go-appimage
# The author of go-appimage has set up some crazy continuous integration build
# system with github, which is really cool, except that it doesn't preserve
# any older builds of the project. And it's pretty difficult to build it
# ourselves. So fuck it, just embed the build artifacts directly in this
# project.
src = {
"x86_64" = "${srcDir}/appimagetool-${version}-x86_64.AppImage";
"aarch64" = "${srcDir}/go-appimage/appimagetool-${version}-aarch64.AppImage";
"armv7l" = "${srcDir}/go-appimage/appimagetool-${version}-armhf.AppImage";
"i686" = "${srcDir}/go-appimage/appimagetool-${version}-i686.AppImage";
}."${cpuArch}";
in stdenv.mkDerivation rec {
pname = "go-appimage";
inherit version src;
sourceRoot = "squashfs-root";
unpackPhase = ''
cp $src appimagetool
chmod u+wx appimagetool
./appimagetool --appimage-extract
'';
installPhase = ''
mkdir -p $out
cp -r usr/* $out
'';
}

View File

@ -0,0 +1,22 @@
{ appimagekit, hostSystem, writeScriptBin }: let
arch = builtins.getAttr hostSystem {
"x86_64-linux" = "x86_64";
"aarch64-linux" = "aarch64";
"armv6l-linux" = "armhf";
"i686-linux" = "i686";
};
# https://github.com/AppImage/type2-runtime
# The author has set up some crazy continuous integration build system with
# github, which is really cool, except that it doesn't preserve any older
# builds of the project. And it's pretty difficult to build it ourselves. So
# fuck it, just embed the build artifacts directly in this project.
runtimeFileVersion = "81de3e1";
runtimeFile = "${./.}/runtime-${arch}-${runtimeFileVersion}";
in writeScriptBin "appimagetool" ''
export PATH=$PATH:${appimagekit}/bin
export ARCH=${arch}
exec ${appimagekit}/bin/appimagetool --runtime-file ${runtimeFile} "$@"
''

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,6 +8,13 @@ rec {
hostSystem,
}: let
hostSystemTarget = builtins.getAttr hostSystem {
"x86_64-linux" = "x86_64-unknown-linux-musl";
"aarch64-linux" = "aarch64-unknown-linux-musl";
"i686-linux" = "i686-unknown-linux-musl";
"armv6l-linux" = "armv6l-unknown-linux-musleabihf";
};
pkgs = pkgsNix.default {
inherit buildSystem hostSystem;
};
@ -31,7 +38,7 @@ rec {
compile = (import "${src}/nix/compile.nix") {
system = buildSystem;
target = hostSystem;
target = hostSystemTarget;
pkgsSrc = pkgsNix.src;
cargo2nixOverlay = common.cargo2nixOverlay;

View File

@ -20,7 +20,7 @@
vendorHash = "sha256-GvMiOEC3Y/pGG++Z+XCgLVADKymUR9shDxjx3xIz8u0=";
subPackages = [ "cmd/nebula" "cmd/nebula-cert" ];
subPackages = [ "cmd/nebula" ];
ldflags = [ "-X main.Build=${version}" ];
}

View File

@ -9,6 +9,11 @@ rec {
CGO_ENABLED=0;
tags = [ "netgo" "timetzdata" ];
ldflags = [ "-w" "-extldflags=-static" ];
# Not sure why buildGoModule doesn't handle this correctly.
GOARM = if prev.stdenv.hostPlatform.parsed.cpu.name == "armv6l"
then "6,hardfloat"
else null;
};
in {
buildGoModule = args: prev.buildGoModule (buildArgs // args);
@ -35,11 +40,16 @@ rec {
sha256 = "sha256:1lr1h35prqkd1mkmzriwlpvxcb34kmhc9dnr48gkm8hh089hifmx";
};
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"i686-linux"
];
lib = import "${src}/lib";
crossSystems = {
"x86_64-linux" = {config = "x86_64-linux";};
"aarch64-linux" = lib.systems.examples.aarch64-multiplatform;
"i686-linux" = {config = "i686-linux";};
"armv6l-linux" = lib.systems.examples.raspberryPi;
};
supportedSystems = builtins.attrNames crossSystems;
default = {
buildSystem,
@ -55,7 +65,6 @@ rec {
# enabled, even if the target platform is actually the same as the build
# platform (and therefore it's not really cross-compiling). So we only set
# up the cross-compiling config if the target platform is different.
crossSystem.config = hostSystem;
crossSystem = builtins.getAttr hostSystem crossSystems;
}));
}

View File

@ -1,11 +1,10 @@
{
revision ? "dev",
releaseName ? "dev",
buildNumber ? "1",
buildSystem ? builtins.currentSystem,
pkgsNix ? (import ./nix/pkgs.nix),
supportedSystems ? pkgsNix.supportedSystems,
}: let
pkgs = pkgsNix.default { inherit buildSystem; };
@ -13,22 +12,24 @@
mkRelease = hostSystem: let
build = ((import ./default.nix) {
inherit buildSystem hostSystem releaseName revision;
inherit buildSystem hostSystem releaseName buildNumber;
}).build;
in pkgs.stdenv.mkDerivation {
name = "isle-release-${hostSystem}";
inherit releaseName hostSystem;
inherit releaseName buildNumber hostSystem;
appImage = build.appImage;
archPkg = build.archPkg;
debPkg = build.debPkg;
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
mkdir -p "$out"/
cp "$appImage"/bin/isle "$out"/isle-$releaseName-$hostSystem.AppImage
cp "$archPkg"/*.tar.zst "$out"/isle-$releaseName-$hostSystem.pkg.tar.zst
cp "$appImage"/bin/isle "$out"/isle-$releaseName-$buildNumber-$hostSystem.AppImage
cp "$archPkg"/* "$out"/
cp "$debPkg"/* "$out"/
'';
};

View File

@ -7,21 +7,25 @@ cd "$scriptDir"
releaseName="$1"
if [ -z "$releaseName" ]; then
echo "USAGE: $0 \"v0.1.2\""
echo "USAGE: $0 \"0.1.2\" [build number]"
exit 1
fi
buildNumber="$2"
if [ -z "$buildNumber" ]; then
buildNumber="0"
fi
releasesDir="$(pwd)/releases"
mkdir -p "$releasesDir"
echo '*' > "$releasesDir"/.gitignore
out="$releasesDir/$releaseName"
revision=$(git rev-parse HEAD)
out="$releasesDir/$releaseName-$buildNumber"
rm -rf "$out"
result=$(nix-build -v \
--argstr revision "$revision" \
--argstr releaseName "$releaseName" \
--argstr buildNumber "$buildNumber" \
--no-out-link \
release.nix \
)

View File

@ -1,7 +0,0 @@
---
type: task
---
# Raspberry Pi Build
Get Isle build system to include rpi (armv7l-linux-musl)