Compare commits

...

2 Commits

Author SHA1 Message Date
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
9 changed files with 331 additions and 134 deletions

View File

@ -1,51 +1,36 @@
{ {
pkgsAttrs ? (import ./nix/pkgs.nix), pkgs,
bootstrap ? null, garage,
releaseName ? "debug", selfRev,
hostSystem,
#buildSystem,
}: let }: rec {
pkgs = pkgsAttrs.pkgs; inherit garage;
in rec {
rootedBootstrap = pkgs.stdenv.mkDerivation {
name = "cryptic-net-rooted-bootstrap";
src = bootstrap;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
mkdir -p "$out"/share
cp "$src" "$out"/share/bootstrap.yml
'';
};
version = pkgs.stdenv.mkDerivation { version = pkgs.stdenv.mkDerivation {
name = "cryptic-net-version"; name = "cryptic-net-version";
buildInputs = [ pkgs.git pkgs.go ]; inherit selfRev hostSystem;
src = ./version.txt;
garageVersion = garage.version;
src = ./.; nativeBuildInputs = [ pkgs.go ];
inherit releaseName;
nixPkgsVersion = pkgsAttrs.version;
nixPkgsRev = pkgsAttrs.rev;
builtByUser = builtins.getEnv "USER";
builder = builtins.toFile "builder.sh" '' builder = builtins.toFile "builder.sh" ''
source $stdenv/setup source $stdenv/setup
versionFile=version versionFile=version
cp -r "$src" srcCp cat "$src" >> "$versionFile"
echo "" >> "$versionFile"
echo "Release: $releaseName" >> "$versionFile" echo "System: $hostSystem" >> "$versionFile"
echo "Git Revision: $(cd srcCp && git rev-parse HEAD)" >> "$versionFile" echo "Git Revision: $selfRev" >> "$versionFile"
echo "Build date: $(date) ($(date +%s))" >> "$versionFile" echo "Go Version: $(go version)" >> "$versionFile"
echo "Built by: $builtByUser" >> "$versionFile" echo "Garage Version: $garageVersion" >> "$versionFile"
echo "Go version: $(go version)" >> "$versionFile"
echo "Nixpkgs version: $nixPkgsVersion ($nixPkgsRev)" >> "$versionFile"
mkdir -p "$out"/share mkdir -p "$out"/share
cp "$versionFile" "$out"/share cp "$versionFile" "$out"/share
@ -55,15 +40,11 @@ in rec {
entrypoint = pkgs.callPackage ./entrypoint {}; entrypoint = pkgs.callPackage ./entrypoint {};
dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix { dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix {
glibcStatic = pkgs.glibc.static; stdenv = pkgs.pkgsStatic.stdenv;
}); });
nebula = pkgs.callPackage ./nix/nebula.nix {}; nebula = pkgs.callPackage ./nix/nebula.nix {};
garage = (pkgs.callPackage ./nix/garage.nix {}).env;
waitFor = pkgs.callPackage ./nix/wait-for.nix {};
appDir = pkgs.buildEnv { appDir = pkgs.buildEnv {
name = "cryptic-net-AppDir"; name = "cryptic-net-AppDir";
paths = [ paths = [
@ -75,7 +56,7 @@ in rec {
garage garage
entrypoint entrypoint
] ++ (if bootstrap != null then [ rootedBootstrap ] else []); ];
}; };
appimagetool = pkgs.callPackage ./nix/appimagetool.nix {}; appimagetool = pkgs.callPackage ./nix/appimagetool.nix {};
@ -84,29 +65,42 @@ in rec {
name = "cryptic-net-AppImage"; name = "cryptic-net-AppImage";
src = appDir; src = appDir;
buildInputs = [ appimagetool ]; nativeBuildInputs = [
appimagetool
pkgs.file
pkgs.fuse
];
ARCH = "x86_64"; ARCH = "x86_64";
builder = builtins.toFile "build.sh" '' builder = builtins.toFile "build.sh" ''
source $stdenv/setup source $stdenv/setup
cp -rL "$src" cryptic-net cp -rL "$src" cryptic-net.AppDir
chmod +w cryptic-net -R chmod +w cryptic-net.AppDir -R
appimagetool cryptic-net "$out"
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 { release = pkgs.stdenv.mkDerivation {
name = "cryptic-net-AppImage"; name = "cryptic-net-release";
inherit appImage releaseName; inherit appImage;
buildInputs = [ pkgs.coreutils ]; nativeBuildInputs = [ pkgs.coreutils ];
builder = builtins.toFile "build.sh" '' builder = builtins.toFile "build.sh" ''
source $stdenv/setup source $stdenv/setup
mkdir -p "$out" mkdir -p "$out"
cp "$appImage" "$out"/cryptic-net-$releaseName-linux-amd64 cp "$appImage" "$out"/cryptic-net
(cd "$out" && sha256sum * > sha256.txt) (cd "$out" && sha256sum * > sha256.txt)
''; '';
}; };

163
flake.lock Normal file
View File

@ -0,0 +1,163 @@
{
"nodes": {
"cargo2nix": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": [
"garage",
"nixpkgs"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1666087781,
"narHash": "sha256-trKVdjMZ8mNkGfLcY5LsJJGtdV3xJDZnMVrkFjErlcs=",
"owner": "Alexis211",
"repo": "cargo2nix",
"rev": "a7a61179b66054904ef6a195d8da736eaaa06c36",
"type": "github"
},
"original": {
"owner": "Alexis211",
"repo": "cargo2nix",
"rev": "a7a61179b66054904ef6a195d8da736eaaa06c36",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1650374568,
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"garage": {
"inputs": {
"cargo2nix": "cargo2nix",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1672666365,
"narHash": "sha256-lpNp/jw4YaczG3NM3pVWR0cZ8u/KBQCWvvfAswO4+Do=",
"ref": "main",
"rev": "76230f20282e73a5a5afa33af68152acaf732cf5",
"revCount": 1007,
"type": "git",
"url": "https://git.deuxfleurs.fr/Deuxfleurs/garage.git"
},
"original": {
"ref": "main",
"rev": "76230f20282e73a5a5afa33af68152acaf732cf5",
"type": "git",
"url": "https://git.deuxfleurs.fr/Deuxfleurs/garage.git"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1665657542,
"narHash": "sha256-mojxNyzbvmp8NtVtxqiHGhRfjCALLfk9i/Uup68Y5q8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a3073c49bc0163fea6a121c276f526837672b555",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a3073c49bc0163fea6a121c276f526837672b555",
"type": "github"
}
},
"pkgsSrc": {
"locked": {
"lastModified": 1672580127,
"narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0874168639713f547c05947c76124f78441ea46c",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-22.05",
"type": "indirect"
}
},
"root": {
"inputs": {
"garage": "garage",
"pkgsSrc": "pkgsSrc",
"utils": "utils"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"garage",
"cargo2nix",
"flake-utils"
],
"nixpkgs": [
"garage",
"cargo2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1664247556,
"narHash": "sha256-J4vazHU3609ekn7dr+3wfqPo5WGlZVAgV7jfux352L0=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "524db9c9ea7bc7743bb74cdd45b6d46ea3fcc2ab",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"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
}

53
flake.nix Normal file
View File

@ -0,0 +1,53 @@
{
inputs.pkgsSrc.url = "nixpkgs/nixos-22.05";
inputs.utils.url = "github:numtide/flake-utils";
# v0.8.1
inputs.garage.url = "git+https://git.deuxfleurs.fr/Deuxfleurs/garage.git?ref=main&rev=76230f20282e73a5a5afa33af68152acaf732cf5";
description = "cryptic-net provides the foundation for an autonomous community
cloud infrastructure";
outputs = {
self, pkgsSrc, utils, garage,
}: let
supportedSystems = [
"x86_64-linux"
#"aarch64-linux"
#"armv7l-linux" # rpi, I think?
#"i686-linux"
];
in utils.lib.eachSystem supportedSystems (system: let
pkgs = import pkgsSrc {
inherit system;
#crossSystem = {
# config = system;
#};
overlays = [
(import ./nix/overlays/go_1_18.nix)
];
};
defaultAttrs = (import ./default.nix) {
inherit pkgs;
hostSystem = system;
#buildSystem = self.system;
garage = garage.packages."${system}".default;
selfRev = if self ? rev then self.rev else "UNKNOWN";
};
in {
defaultPackage = defaultAttrs.appImage;
});
}

View File

@ -1,17 +1,58 @@
{ # Modified from https://github.com/matthewbauer/nix-bundle/blob/e9fa7e8a118942adafa8592a28b301ee23d37c13/appimagetool.nix
{ stdenv, lib, fetchurl, fuse, zlib, file, glib, }:
fetchFromGitHub, # This is from some binaries.
callPackage,
}: let # Ideally, this should be source based,
# but I can't get it to build from GitHub
src = fetchFromGitHub { let
owner = "matthewbauer";
repo = "nix-bundle";
rev = "223f4ffc4179aa318c34dc873a08cb00090db829";
sha256 = "0pqpx9vnjk9h24h9qlv4la76lh5ykljch6g487b26r1r2s9zg7kh";
};
in inherit (stdenv.cc.bintools) dynamicLinker;
callPackage "${src}/appimagetool.nix" {} version = "745";
cpuArch = stdenv.buildPlatform.parsed.cpu.arch;
src = {
"x86-64" = fetchurl {
url = "https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-${version}-x86_64.AppImage";
sha256 = "sha256-HQ7d9LQDaPm6sGZ5boWZdmGTNqiGN9NWHUWPiDhl2Xc=";
};
# TODO other archs
}."${cpuArch}";
in stdenv.mkDerivation rec {
inherit version src;
pname = "go-appimage";
sourceRoot = "squashfs-root";
unpackPhase = ''
cp $src appimagetool
chmod u+wx appimagetool
#patchelf --set-interpreter ${dynamicLinker} \
# --set-rpath ${fuse}/lib:${zlib}/lib \
# appimagetool
./appimagetool --appimage-extract
'';
installPhase = ''
mkdir -p $out
cp -r usr/* $out
for x in $out/bin/*; do
patchelf \
--set-interpreter ${dynamicLinker} \
--set-rpath ${lib.makeLibraryPath [ zlib stdenv.glibc.out fuse glib ]} \
$x || true
done
'';
dontStrip = true;
dontPatchELF = true;
}

View File

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

View File

@ -1,33 +0,0 @@
{
fetchgit,
buildEnv,
minio-client,
}: let
version = "0.8.0-unstable";
src = fetchgit {
name = "garage-v${version}";
url = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git";
rev = "293139a94a8911aaac1b650e4707379a972196aa";
sha256 = "sha256-b6HHLnxMdmpngiywll6Egr8O9/4cqBN01Mj3OwVMeBc=";
};
in rec {
garage = (import "${src}/default.nix") { git_version = version; };
minioClient = minio-client;
env = buildEnv {
name = "cryptic-net-garage";
paths = [
garage.pkgs.amd64.release
minioClient
];
};
}

21
nix/overlays/go_1_18.nix Normal file
View File

@ -0,0 +1,21 @@
# Make buildGoModules use static compilation by default, and use go 1.18
# everywhere.
(final: prev:
let
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);
}
)

View File

@ -1,38 +0,0 @@
rec {
overlays = [
# Make buildGoModules use static compilation by default, and use go 1.18
# everywhere.
(final: prev:
let
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";
src = fetchTarball {
name = "nixpkgs-${version}";
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
sha256 = "1pbfhlh4v8l70p44gspsci3i6w0wk70vaisiawg3jhka2nxb8367";
};
pkgs = import src { inherit overlays; };
}

1
version.txt Normal file
View File

@ -0,0 +1 @@
Release: 0.0.1