2021-04-20 21:31:37 +00:00
|
|
|
{
|
|
|
|
|
2022-10-20 20:30:30 +00:00
|
|
|
pkgsAttrs ? (import ./nix/pkgs.nix),
|
2021-04-20 21:31:37 +00:00
|
|
|
bootstrap ? null,
|
|
|
|
|
2022-10-20 20:30:30 +00:00
|
|
|
}: let
|
|
|
|
|
|
|
|
pkgs = pkgsAttrs.pkgs;
|
|
|
|
|
|
|
|
in rec {
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
rootedBootstrap = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "cryptic-net-rooted-bootstrap";
|
|
|
|
|
|
|
|
src = bootstrap;
|
|
|
|
|
|
|
|
builder = builtins.toFile "builder.sh" ''
|
|
|
|
source $stdenv/setup
|
|
|
|
mkdir -p "$out"/share
|
2022-11-02 13:34:40 +00:00
|
|
|
cp "$src" "$out"/share/bootstrap.yml
|
2021-04-20 21:31:37 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
version = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "cryptic-net-version";
|
|
|
|
|
|
|
|
buildInputs = [ pkgs.git pkgs.go ];
|
2022-10-20 20:30:30 +00:00
|
|
|
|
2021-04-20 21:31:37 +00:00
|
|
|
src = ./.;
|
|
|
|
inherit bootstrap;
|
2022-10-20 20:30:30 +00:00
|
|
|
nixPkgsVersion = pkgsAttrs.version;
|
|
|
|
nixPkgsRev = pkgsAttrs.rev;
|
|
|
|
builtByUser = builtins.getEnv "USER";
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
builder = builtins.toFile "builder.sh" ''
|
|
|
|
source $stdenv/setup
|
|
|
|
|
|
|
|
versionFile=version
|
|
|
|
|
2022-10-20 20:30:30 +00:00
|
|
|
cp -r "$src" srcCp
|
|
|
|
|
2021-04-20 21:31:37 +00:00
|
|
|
if [ "$bootstrap" != "" ]; then
|
|
|
|
hostName=$(tar -xzf "$bootstrap" --to-stdout ./hostname)
|
|
|
|
echo "Built for host: $hostName" >> "$versionFile"
|
|
|
|
fi
|
|
|
|
|
2022-10-20 20:30:30 +00:00
|
|
|
echo "Build date: $(date) ($(date +%s))" >> "$versionFile"
|
|
|
|
echo "Built by: $builtByUser" >> "$versionFile"
|
|
|
|
echo "Git rev: $(cd srcCp && git describe --always --long --dirty=' (dirty)')" >> "$versionFile"
|
2021-04-20 21:31:37 +00:00
|
|
|
echo "Go version: $(go version)" >> "$versionFile"
|
2022-10-20 20:30:30 +00:00
|
|
|
echo "Nixpkgs version: $nixPkgsVersion ($nixPkgsRev)" >> "$versionFile"
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
mkdir -p "$out"/share
|
|
|
|
cp "$versionFile" "$out"/share
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-10-20 20:06:22 +00:00
|
|
|
entrypoint = pkgs.callPackage ./entrypoint {};
|
2021-04-20 21:31:37 +00:00
|
|
|
|
2022-10-26 20:18:16 +00:00
|
|
|
dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix {
|
2021-04-20 21:31:37 +00:00
|
|
|
glibcStatic = pkgs.glibc.static;
|
2022-10-26 20:18:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
nebula = pkgs.callPackage ./nix/nebula.nix {};
|
2021-04-20 21:31:37 +00:00
|
|
|
|
2022-10-19 14:25:11 +00:00
|
|
|
garage = (pkgs.callPackage ./nix/garage.nix {}).env;
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
waitFor = pkgs.callPackage ./nix/wait-for.nix {};
|
|
|
|
|
|
|
|
appDir = pkgs.buildEnv {
|
|
|
|
name = "cryptic-net-AppDir";
|
|
|
|
paths = [
|
|
|
|
|
|
|
|
./AppDir
|
|
|
|
version
|
|
|
|
dnsmasq
|
2022-10-26 20:18:16 +00:00
|
|
|
nebula
|
2021-04-20 21:31:37 +00:00
|
|
|
garage
|
2022-10-20 20:06:22 +00:00
|
|
|
entrypoint
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
] ++ (if bootstrap != null then [ rootedBootstrap ] else []);
|
|
|
|
};
|
|
|
|
|
|
|
|
appimagetool = pkgs.callPackage ./nix/appimagetool.nix {};
|
|
|
|
|
|
|
|
appImage = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "cryptic-net-AppImage";
|
|
|
|
src = appDir;
|
|
|
|
|
|
|
|
buildInputs = [ appimagetool ];
|
|
|
|
|
|
|
|
ARCH = "x86_64";
|
|
|
|
|
|
|
|
builder = builtins.toFile "build.sh" ''
|
|
|
|
source $stdenv/setup
|
|
|
|
cp -rL "$src" cryptic-net
|
|
|
|
chmod +w cryptic-net -R
|
|
|
|
mkdir $out
|
|
|
|
appimagetool cryptic-net "$out/cryptic-net"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
service = pkgs.writeText "cryptic-service" ''
|
|
|
|
[Unit]
|
|
|
|
Description=cryptic nebula
|
|
|
|
Requires=network.target
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Restart=always
|
|
|
|
RestartSec=1s
|
|
|
|
User=root
|
|
|
|
ExecStart=${appImage}/cryptic-net
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
'';
|
|
|
|
}
|