Allow building from either flake or nix-build

This commit is contained in:
Brian Picciano 2023-02-14 20:46:28 +01:00
parent 1354c96ba9
commit b7d49bff5b
6 changed files with 98 additions and 51 deletions

View File

@ -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, let
garage,
selfRev, flakeCompat = import (builtins.fetchGit {
hostSystem, 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 { }: rec {
@ -15,23 +41,27 @@
version = pkgs.stdenv.mkDerivation { version = pkgs.stdenv.mkDerivation {
name = "cryptic-net-version"; name = "cryptic-net-version";
inherit selfRev hostSystem; inherit selfRev hostSystem releaseName;
src = ./version.txt; repoSrc = ./.;
garageVersion = garage.version; nativeBuildInputs = [ pkgs.git ];
# TODO it'd be nice to be able to call `go version`, but that doesn't work # 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. # when crossSystem is being used for some unknown reason.
goVersion = pkgs.go.version; goVersion = pkgs.go.version;
garageVersion = garage.version;
builder = builtins.toFile "builder.sh" '' builder = builtins.toFile "builder.sh" ''
source $stdenv/setup source $stdenv/setup
versionFile=version versionFile=version
cat "$src" >> "$versionFile" if [ "$selfRev" = "" ]; then
echo "" >> "$versionFile" cp -r "$repoSrc" repoSrcCp
selfRev="$(cd repoSrcCp && git rev-parse HEAD)"
fi
echo "Release $releaseName" >> "$versionFile"
echo "System: $hostSystem" >> "$versionFile" echo "System: $hostSystem" >> "$versionFile"
echo "Git Revision: $selfRev" >> "$versionFile" echo "Git Revision: $selfRev" >> "$versionFile"
echo "Go Version: $goVersion" >> "$versionFile" echo "Go Version: $goVersion" >> "$versionFile"

View File

@ -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.pkgsSrc.url = "nixpkgs/nixos-22.11";
inputs.utils.url = "github:numtide/flake-utils"; inputs.utils.url = "github:numtide/flake-utils";
# v0.8.1 # 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"; 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"; description = "cryptic-net provides the foundation for an autonomous community cloud infrastructure";
outputs = { outputs = {
self, pkgsSrc, utils, garage, self, utils,
pkgsSrc, garage,
}: let }: let
@ -31,34 +34,20 @@
config = hostSystem; config = hostSystem;
}; };
overlays = [ overlays = (import ./nix/pkgs.nix).overlays;
(import ./nix/overlays/go.nix)
];
}; };
defaultAttrs = (import ./default.nix) { defaultAttrs = (import ./default.nix) {
inherit pkgs; inherit pkgs hostSystem buildSystem;
hostSystem = hostSystem;
garage = garage.packages."${hostSystem}".default; 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 in
defaultAttrs.appImage 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' #pkgsForBuildSystem = (buildSystem: builtins.foldl'
# (sysPkgs: hostSystem: # (sysPkgs: hostSystem:
# sysPkgs // { "compiled-for-${hostSystem}" = mkPkg buildSystem hostSystem; }) # sysPkgs // { "compiled-for-${hostSystem}" = mkPkg buildSystem hostSystem; })

View File

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

View File

@ -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);
}
)

47
nix/pkgs.nix Normal file
View File

@ -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;
};
}

View File

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