~kaction/config

fb2cfdb0b2cf032054cde714b9732ab2b9d0a5de — Dmitry Bogatov 7 months ago 7453c85
nix-sys: move more of build process out of Nix

This way it is possible to do incremental builds and development.
A system-v2/nix-sys/.gitignore => system-v2/nix-sys/.gitignore +2 -0
@@ 0,0 1,2 @@
.lock*
conf/*

A system-v2/nix-sys/all.do => system-v2/nix-sys/all.do +2 -0
@@ 0,0 1,2 @@
#!/bin/sh
exec redo-ifchange nix-sys

M system-v2/nix-sys/default.nix => system-v2/nix-sys/default.nix +11 -11
@@ 1,27 1,27 @@
{ stdenv, tinycdb, nix-sys-generate, manifest ? {} }:
{ stdenv, tinycdb, nix-sys-generate, redo-c, manifest ? {} }:
assert manifest != null;
let
in stdenv.mkDerivation {
  name = "nix-sys";
  src = ./.;
  outputs = [ "out" "cdb" ];
  nativeBuildInputs = [ nix-sys-generate ];
  nativeBuildInputs = [ nix-sys-generate redo-c ];
  buildInputs = [ tinycdb ];
  configurePhase = ''
    hash=$(echo ${placeholder "out"}|cut -b 12-43)
    nix-sys-generate \
      --manifest "$manifest" \
      --output-config config.h \
      --output-cdb $cdb \
      --staged-output-cdb index.cdb \
      --hash $hash
    mkdir conf
    echo $out > conf/out
    echo $cdb > conf/cdb
    echo "$manifest" > conf/manifest
    echo "${stdenv.cc.targetPrefix}cc -static -O2" > conf/cc
    echo "${stdenv.cc.targetPrefix}cc" > conf/ld
  '';
  buildPhase = "redo";
  installPhase = ''
    mkdir -p $out/bin
    ${stdenv.hostPlatform.config}-cc -static -O2 -g main.c -lcdb -o $out/bin/nix-sys
    ${stdenv.hostPlatform.config}-strip -s $out/bin/nix-sys
    install -m555 ./nix-sys $out/bin/nix-sys
    mv index.cdb $cdb
  '';
  postFixup = "rm -fr $out/nix-support";
  manifest = builtins.toJSON manifest;
}


A system-v2/nix-sys/default.o.do => system-v2/nix-sys/default.o.do +4 -0
@@ 0,0 1,4 @@
#!/bin/sh -eu
cc=$(cat conf/cc)
redo-ifchange conf/cc generate $2.c
$cc $2.c -c -o $3

A system-v2/nix-sys/generate.do => system-v2/nix-sys/generate.do +13 -0
@@ 0,0 1,13 @@
#!/bin/sh -eu
out=$(cat conf/out)
cdb=$(cat conf/cdb)
manifest=$(cat conf/manifest)
redo-ifchange conf/out conf/cdb conf/manifest

hash=$(echo "$out" | cut -b 12-43)
exec nix-sys-generate               \
      --manifest "$manifest"        \
      --output-config config.h      \
      --output-cdb "$cdb"           \
      --staged-output-cdb index.cdb \
      --hash "$hash"

A system-v2/nix-sys/nix-sys.do => system-v2/nix-sys/nix-sys.do +5 -0
@@ 0,0 1,5 @@
#!/bin/sh -eu
ld=$(cat conf/ld)
objs="main.o"
redo-ifchange conf/ld $objs
$ld $objs -lcdb -o $3