Allow building from either flake or nix-build

main
Brian Picciano 1 year ago
parent 1354c96ba9
commit b7d49bff5b
  1. 54
      default.nix
  2. 27
      flake.nix
  3. 2
      nix/appimagetool.nix
  4. 18
      nix/overlays/go.nix
  5. 47
      nix/pkgs.nix
  6. 1
      version.txt

@ -1,12 +1,38 @@
{
# TODO
# - allow injecting a bootstrap file
# - try stripping flake of source info
# - Revert to not using flake for garage, we'll need to compile it ourselves
# because flakes don't actually support cross-compilation in a nice way.
#
# - Set ARCH arg for appimagetool target in default.nix
# TODO make this usable again! Add sane defaults for inputs, and allow for
# injecting a bootstrap file.
pkgs,
garage,
selfRev,
hostSystem,
let
flakeCompat = import (builtins.fetchGit {
url = "https://github.com/edolstra/flake-compat.git";
rev = "009399224d5e398d03b22badca40a37ac85412a1";
});
# if this gets updated then flake.nix needs to be updated as well
garageSrc = builtins.fetchGit {
url = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git";
rev = "76230f20282e73a5a5afa33af68152acaf732cf5";
shallow = true;
};
in {
buildSystem ? builtins.currentSystem,
hostSystem ? builtins.currentSystem,
pkgs ? (import ./nix/pkgs.nix).default {
inherit buildSystem hostSystem;
},
garage ? (flakeCompat { src = garageSrc; }).defaultNix.packages."${hostSystem}".default,
selfRev ? "",
releaseName ? "debug",
}: rec {
@ -15,23 +41,27 @@
version = pkgs.stdenv.mkDerivation {
name = "cryptic-net-version";
inherit selfRev hostSystem;
src = ./version.txt;
inherit selfRev hostSystem releaseName;
repoSrc = ./.;
garageVersion = garage.version;
nativeBuildInputs = [ pkgs.git ];
# TODO it'd be nice to be able to call `go version`, but that doesn't work
# when crossSystem is being used for some unknown reason.
goVersion = pkgs.go.version;
garageVersion = garage.version;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
versionFile=version
cat "$src" >> "$versionFile"
echo "" >> "$versionFile"
if [ "$selfRev" = "" ]; then
cp -r "$repoSrc" repoSrcCp
selfRev="$(cd repoSrcCp && git rev-parse HEAD)"
fi
echo "Release $releaseName" >> "$versionFile"
echo "System: $hostSystem" >> "$versionFile"
echo "Git Revision: $selfRev" >> "$versionFile"
echo "Go Version: $goVersion" >> "$versionFile"

@ -1,17 +1,20 @@
{
# If this gets updated then nix/pkgs.nix needs to be updated as well
inputs.pkgsSrc.url = "nixpkgs/nixos-22.11";
inputs.utils.url = "github:numtide/flake-utils";
# v0.8.1
# if this gets updated then default.nix needs to be updated as well
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,
self, utils,
pkgsSrc, garage,
}: let
@ -31,34 +34,20 @@
config = hostSystem;
};
overlays = [
(import ./nix/overlays/go.nix)
];
overlays = (import ./nix/pkgs.nix).overlays;
};
defaultAttrs = (import ./default.nix) {
inherit pkgs;
hostSystem = hostSystem;
inherit pkgs hostSystem buildSystem;
garage = garage.packages."${hostSystem}".default;
selfRev = if self ? rev then self.rev else "UNKNOWN";
selfRev = if self ? rev then self.rev else "dirty";
releaseName = "flake";
};
in
defaultAttrs.appImage
);
# TODO Once everything else is prepared for cross compilation this can be
# re-enabled. Things left to do:
#
# - Revert to not using flake for garage, we'll need to compile it
# ourselves because flakes don't actually support cross-compilation in a
# nice way.
#
# - Set ARCH arg for appimagetool target in default.nix
#
# - Test builds in QEMU or something.
#
# - Probably other things which will come up
#pkgsForBuildSystem = (buildSystem: builtins.foldl'
# (sysPkgs: hostSystem:
# sysPkgs // { "compiled-for-${hostSystem}" = mkPkg buildSystem hostSystem; })

@ -8,7 +8,7 @@ let
src = {
"x86-64" = fetchurl {
"x86_64" = fetchurl {
url = "https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-${version}-x86_64.AppImage";
sha256 = "sha256-HQ7d9LQDaPm6sGZ5boWZdmGTNqiGN9NWHUWPiDhl2Xc=";
};

@ -1,18 +0,0 @@
# 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);
}
)

@ -0,0 +1,47 @@
rec {
overlays = [
# 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);
})
# 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
'';
});
})
];
# if this changes then flake.nix needs to be updated as well.
version = "22.11";
rev = "ce20e9ebe1903ea2ba1ab006ec63093020c761cb";
src = fetchTarball {
name = "nixpkgs-${version}";
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
sha256 = "sha256-eFNm2h6fNbgD7ZpO4MHikCB5pSnCJ7DTmwPisjetmwc=";
};
default = {
buildSystem,
hostSystem,
}: import src {
system = buildSystem;
crossSystem.config = hostSystem;
inherit overlays;
};
}

@ -1 +0,0 @@
Release: 0.0.1
Loading…
Cancel
Save