Compare commits

...

10 Commits

Author SHA1 Message Date
Brian Picciano
e9190e4dbb Allow injecting bootstrap again, plus some additions to version 2023-02-15 15:09:31 +01:00
Brian Picciano
94c6ad8774 Fix up some TODOs 2023-02-15 14:58:47 +01:00
Brian Picciano
8e800951a6 Remove sources from flake, everything is defined in default.nix now
This includes re-adding the garage build ourselves, rather than using
their flake.
2023-02-15 13:56:22 +01:00
Brian Picciano
b7d49bff5b Allow building from either flake or nix-build 2023-02-15 12:04:56 +01:00
Brian Picciano
1354c96ba9 Accidentally left flake building garage rather than full appimage 2023-01-29 19:08:16 +01:00
Brian Picciano
a8856fba99 Update docs a bit in light of the new architectures 2023-01-29 19:01:58 +01:00
Brian Picciano
1379291c1e Got flake set up for cross-compilation, but it still doesn't work 2023-01-29 18:57:55 +01:00
Brian Picciano
05f9064d10 Update nixpkgs, add appimagetool for other archs 2023-01-29 15:31:11 +01:00
Brian Picciano
5061fb5670 Update appimagetool-ing to something which can theoretically be used on other architectures 2023-01-28 22:57:06 +01:00
Brian Picciano
17fb9bbd77 Add a flake.nix
I spent some time trying to get compilation on non-x86_64 systems
possibly working, but we're currently limited by AppImage, which doesn't
want to work properly.
2023-01-28 20:43:09 +01:00
8 changed files with 274 additions and 117 deletions

View File

@ -1,15 +1,81 @@
{
pkgsAttrs ? (import ./nix/pkgs.nix),
bootstrap ? null,
buildSystem ? builtins.currentSystem,
hostSystem ? builtins.currentSystem,
revision ? "",
releaseName ? "debug",
bootstrap ? null,
}: let
pkgs = pkgsAttrs.pkgs;
pkgsNix = (import ./nix/pkgs.nix);
pkgs = pkgsNix.default {
inherit buildSystem hostSystem;
};
garageNix = (import ./nix/garage.nix);
in rec {
version = pkgs.stdenv.mkDerivation {
name = "cryptic-net-version";
inherit buildSystem revision releaseName;
repoSrc = ./.;
nativeBuildInputs = [ pkgs.git ];
goVersion = pkgs.go.version;
garageVersion = garageNix.version;
nixpkgsVersion = pkgsNix.version;
release = "${releaseName}-${hostSystem}";
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
versionFile=version
if [ "$revision" = "" ]; then
cp -r "$repoSrc" repoSrcCp
revision="$(cd repoSrcCp && git rev-parse HEAD)"
fi
echo "Release $release" >> "$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
'';
};
entrypoint = pkgs.callPackage ./entrypoint {};
dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix {
stdenv = pkgs.pkgsStatic.stdenv;
});
nebula = pkgs.callPackage ./nix/nebula.nix {};
garage = let
hostPlatform = pkgs.stdenv.hostPlatform.parsed;
in pkgs.callPackage garageNix.package {
inherit buildSystem;
hostSystem = "${hostPlatform.cpu.name}-unknown-${hostPlatform.kernel.name}-musl";
pkgsSrc = pkgsNix.src;
};
rootedBootstrap = pkgs.stdenv.mkDerivation {
name = "cryptic-net-rooted-bootstrap";
@ -22,48 +88,6 @@ in rec {
'';
};
version = pkgs.stdenv.mkDerivation {
name = "cryptic-net-version";
buildInputs = [ pkgs.git pkgs.go ];
src = ./.;
inherit releaseName;
nixPkgsVersion = pkgsAttrs.version;
nixPkgsRev = pkgsAttrs.rev;
builtByUser = builtins.getEnv "USER";
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
versionFile=version
cp -r "$src" srcCp
echo "Release: $releaseName" >> "$versionFile"
echo "Git Revision: $(cd srcCp && git rev-parse HEAD)" >> "$versionFile"
echo "Build date: $(date) ($(date +%s))" >> "$versionFile"
echo "Built by: $builtByUser" >> "$versionFile"
echo "Go version: $(go version)" >> "$versionFile"
echo "Nixpkgs version: $nixPkgsVersion ($nixPkgsRev)" >> "$versionFile"
mkdir -p "$out"/share
cp "$versionFile" "$out"/share
'';
};
entrypoint = pkgs.callPackage ./entrypoint {};
dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix {
glibcStatic = pkgs.glibc.static;
});
nebula = pkgs.callPackage ./nix/nebula.nix {};
garage = (pkgs.callPackage ./nix/garage.nix {}).env;
waitFor = pkgs.callPackage ./nix/wait-for.nix {};
appDir = pkgs.buildEnv {
name = "cryptic-net-AppDir";
paths = [
@ -73,6 +97,7 @@ in rec {
dnsmasq
nebula
garage
pkgs.minio-client
entrypoint
] ++ (if bootstrap != null then [ rootedBootstrap ] else []);
@ -84,29 +109,41 @@ in rec {
name = "cryptic-net-AppImage";
src = appDir;
buildInputs = [ appimagetool ];
nativeBuildInputs = [
appimagetool
];
ARCH = "x86_64";
ARCH = pkgs.stdenv.hostPlatform.parsed.cpu.name;
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
cp -rL "$src" cryptic-net
chmod +w cryptic-net -R
appimagetool cryptic-net "$out"
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-AppImage";
inherit appImage releaseName;
name = "cryptic-net-release";
inherit appImage;
buildInputs = [ pkgs.coreutils ];
nativeBuildInputs = [ pkgs.coreutils ];
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
mkdir -p "$out"
cp "$appImage" "$out"/cryptic-net-$releaseName-linux-amd64
cp "$appImage" "$out"/cryptic-net
(cd "$out" && sha256sum * > sha256.txt)
'';
};

View File

@ -3,7 +3,16 @@
This document will guide you through the process of obtaining a cryptic-net
binary and joining the network.
NOTE currently only linux machines with amd64/x86_64 processors are supported.
NOTE currently only linux machines with the following architectures are
supported:
- `x86_64` / `amd64`
- `aarch64` / `arm64`
- `armv7l` (Raspberry Pi)
- `i686`
(Only `x86_64` has been tested.)
More OSs and architectures coming soon!
## Obtaining a cryptic-net Binary

26
flake.lock Normal file
View File

@ -0,0 +1,26 @@
{
"nodes": {
"root": {
"inputs": {
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

49
flake.nix Normal file
View File

@ -0,0 +1,49 @@
{
inputs.utils.url = "github:numtide/flake-utils";
description = "cryptic-net provides the foundation for an autonomous community cloud infrastructure";
outputs = {
self, utils,
}: let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"armv7l-linux" # rpi, I think?
"i686-linux"
];
mkPkg = (buildSystem: hostSystem: let
defaultAttrs = (import ./default.nix) {
inherit hostSystem buildSystem;
revision = if self ? rev then self.rev else "dirty";
releaseName = "flake";
};
in
defaultAttrs.appImage
);
#pkgsForBuildSystem = (buildSystem: builtins.foldl'
# (sysPkgs: hostSystem:
# sysPkgs // { "compiled-for-${hostSystem}" = mkPkg buildSystem hostSystem; })
# { default = mkPkg buildSystem buildSystem; }
# supportedSystems
#);
pkgsForBuildSystem = (buildSystem:
{ default = mkPkg buildSystem buildSystem; });
in {
packages = (builtins.foldl'
(pkgs: buildSystem:
pkgs // { "${buildSystem}" = pkgsForBuildSystem buildSystem; })
{}
supportedSystems
);
};
}

View File

@ -1,17 +1,50 @@
{
{ stdenv, fetchurl }:
fetchFromGitHub,
callPackage,
let
}: let
version = "745";
src = fetchFromGitHub {
owner = "matthewbauer";
repo = "nix-bundle";
rev = "223f4ffc4179aa318c34dc873a08cb00090db829";
sha256 = "0pqpx9vnjk9h24h9qlv4la76lh5ykljch6g487b26r1r2s9zg7kh";
};
cpuArch = stdenv.buildPlatform.parsed.cpu.name;
in
src = {
callPackage "${src}/appimagetool.nix" {}
"x86_64" = fetchurl {
url = "https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-${version}-x86_64.AppImage";
sha256 = "sha256-HQ7d9LQDaPm6sGZ5boWZdmGTNqiGN9NWHUWPiDhl2Xc=";
};
"aarch64" = fetchurl {
url = "https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-${version}-aarch64.AppImage";
sha256 = "sha256-VvH2qXULliCiyFrisaIJbM0ApXp++ZAtxHiS6FM3XT0=";
};
"armv7l" = fetchurl {
url = "https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-${version}-armhf.AppImage";
sha256 = "sha256-ytJjN2dLYOSwqCCFZvqnt+wt2wX/lZ1R+nVz5C+Akvo=";
};
"i686" = fetchurl {
url = "https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-${version}-i686.AppImage";
sha256 = "sha256-GLEhn3dcrwdU3mG0lB6H7PQ5JwEIGqWlGrO1IifeQv4=";
};
}."${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

@ -1,7 +1,6 @@
{
stdenv,
glibcStatic,
}: stdenv.mkDerivation rec {
@ -13,11 +12,7 @@
sha256 = "sha256-rZjTgD32h+W5OAgPPSXGKP5ByHh1LQP7xhmXh/7jEvo=";
};
nativeBuildInputs = [ glibcStatic ];
makeFlags = [
"LDFLAGS=-static"
"DESTDIR="
"BINDIR=$(out)/bin"
"MANDIR=$(out)/man"
"LOCALEDIR=$(out)/share/locale"

View File

@ -1,33 +1,33 @@
{
rec {
fetchgit,
buildEnv,
minio-client,
version = "0.8.1";
}: let
version = "0.8.0-unstable";
src = fetchgit {
src = builtins.fetchGit {
name = "garage-v${version}";
url = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git";
rev = "293139a94a8911aaac1b650e4707379a972196aa";
sha256 = "sha256-b6HHLnxMdmpngiywll6Egr8O9/4cqBN01Mj3OwVMeBc=";
rev = "76230f20282e73a5a5afa33af68152acaf732cf5";
};
in rec {
package = {
pkgsSrc,
buildSystem,
hostSystem,
}: let
garage = (import "${src}/default.nix") { git_version = version; };
compile = (import "${src}/nix/compile.nix") {
minioClient = minio-client;
system = buildSystem;
target = hostSystem;
pkgsSrc = pkgsSrc;
env = buildEnv {
name = "cryptic-net-garage";
paths = [
garage.pkgs.amd64.release
minioClient
];
};
cargo2nixOverlay = (import "${src}/nix/common.nix").cargo2nixOverlay;
release = true;
git_version = version;
};
in
compile.workspace.garage {
compileMode = "build";
};
}

View File

@ -2,37 +2,45 @@ rec {
overlays = [
# Make buildGoModules use static compilation by default, and use go 1.18
# everywhere.
(final: prev:
# Make buildGoModules use static compilation by default
(final: prev: let
buildArgs = {
doCheck = false;
CGO_ENABLED=0;
tags = [ "netgo" "timetzdata" ];
ldflags = [ "-w" "-extldflags=-static" ];
};
in {
buildGoModule = args: prev.buildGoModule (buildArgs // args);
})
let
# for whatever reason git checks fail when flake is being used (or maybe
# it's crossSystem's fault)
(final: prev: {
git = prev.git.overrideAttrs (oldAttrs: {
installCheckPhase = ''
# noop
'';
});
})
buildArgs = {
doCheck = false;
CGO_ENABLED=0;
tags = [ "netgo" "timetzdata" ];
ldflags = [ "-w" "-extldflags=-static" ];
};
in {
go = prev.go_1_18;
buildGoModule = args: prev.buildGo118Module (buildArgs // args);
buildGo118Module = args: prev.buildGo118Module (buildArgs // args);
}
)
];
version = "22-05";
rev = "2aec372cdcd4d73b94863611fea70e0884270fdc";
version = "22.11";
rev = "ce20e9ebe1903ea2ba1ab006ec63093020c761cb";
src = fetchTarball {
name = "nixpkgs-${version}";
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
sha256 = "1pbfhlh4v8l70p44gspsci3i6w0wk70vaisiawg3jhka2nxb8367";
sha256 = "sha256-eFNm2h6fNbgD7ZpO4MHikCB5pSnCJ7DTmwPisjetmwc=";
};
pkgs = import src { inherit overlays; };
default = {
buildSystem,
hostSystem,
}: import src {
system = buildSystem;
crossSystem.config = hostSystem;
inherit overlays;
};
}