93 lines
2.4 KiB
Nix
93 lines
2.4 KiB
Nix
{ self, inputs, ... }:
|
|
let
|
|
nixpkgsLib = inputs.nixpkgs.lib.extend (final: prev:
|
|
let
|
|
date = final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101");
|
|
revCode = flake: flake.shortRev or "dirty";
|
|
in
|
|
{
|
|
trivial = prev.trivial // {
|
|
release = "24.08:u-${prev.trivial.release}";
|
|
codeName = "Alpha";
|
|
revisionWithDefault = default: self.rev or default;
|
|
versionSuffix = ".${date}.${revCode self}:u-${revCode inputs.nixpkgs}";
|
|
};
|
|
}
|
|
);
|
|
|
|
mkSystem = target: nixpkgsLib.nixosSystem {
|
|
modules = [
|
|
{
|
|
imports = [
|
|
inputs.impermanence.nixosModules.impermanence
|
|
];
|
|
}
|
|
|
|
./base.nix
|
|
./disk.nix
|
|
./network.nix
|
|
|
|
target
|
|
];
|
|
};
|
|
in
|
|
{
|
|
flake.nixosConfigurations = {
|
|
qclk-rpi3 = mkSystem target/rpi3.nix;
|
|
};
|
|
|
|
perSystem = { libMy, pkgs, ... }: {
|
|
devenv.shells.firmware = libMy.withRootdir {
|
|
packages = with pkgs; [
|
|
nixos-rebuild
|
|
nixVersions.latest
|
|
];
|
|
|
|
scripts = {
|
|
build.exec = ''
|
|
nix build "..#nixosConfigurations.qclk-$1.config.system.build.toplevel"
|
|
'';
|
|
build-image.exec = ''
|
|
set -e
|
|
export PATH="$PATH:${pkgs.util-linux}/bin:${pkgs.fakeroot}/bin:${pkgs.e2fsprogs}/bin"
|
|
die() {
|
|
echo "$1" >&2
|
|
exit 1
|
|
}
|
|
|
|
[ -z "$1" ] && die "Need to set target"
|
|
|
|
target=$1
|
|
out=qclkos-$target.img
|
|
|
|
nix build "..#nixosConfigurations.qclk-$target.config.my.disk.image"
|
|
|
|
persistRoot=$(mktemp --tmpdir -d qclkos-persist-XXXXX)
|
|
# TODO: bless with unique stuff (e.g. keys)
|
|
touch "$persistRoot"/test.txt
|
|
|
|
cp --sparse=always result/$out $out
|
|
chmod u+w $out
|
|
|
|
eval $(partx $out -o START,SECTORS --nr 2 --pairs)
|
|
persistImg=$(mktemp --tmpdir qclkos-persist-XXXXX.img)
|
|
truncate -s $((SECTORS * 512)) $persistImg
|
|
fakeroot mkfs.ext4 -L qclkos-persist -d $persistRoot $persistImg
|
|
|
|
dd conv=notrunc if=$persistImg of=$out seek=$START count=$SECTORS
|
|
rm -r "$persistRoot" "$persistImg"
|
|
'';
|
|
|
|
push-config.exec = ''
|
|
host=$1; shift
|
|
target=$1; shift
|
|
verb=$1; shift
|
|
|
|
export NIX_SSHOPTS="-i .keys/management.key"
|
|
nixos-rebuild $verb --flake ..#qclk-$target --target-host root@"$host" --use-substitutes "$@"
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|