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.
This commit is contained in:
Brian Picciano 2023-01-25 18:50:36 +01:00
parent 1dc22701cd
commit 17fb9bbd77
8 changed files with 265 additions and 120 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,7 +65,7 @@ in rec {
name = "cryptic-net-AppImage"; name = "cryptic-net-AppImage";
src = appDir; src = appDir;
buildInputs = [ appimagetool ]; nativeBuildInputs = [ appimagetool ];
ARCH = "x86_64"; ARCH = "x86_64";
@ -92,21 +73,23 @@ in rec {
source $stdenv/setup source $stdenv/setup
cp -rL "$src" cryptic-net cp -rL "$src" cryptic-net
chmod +w cryptic-net -R chmod +w cryptic-net -R
appimagetool cryptic-net "$out"
mkdir -p "$out/bin"
appimagetool 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,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