Skip to content

Commit

Permalink
bazelisk-env: init
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Sep 9, 2024
1 parent bcd055e commit 2d390da
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@
})
];
};

bazelisk = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs.inputs = inputs;
modules = self.nixosModules.default ++ [
(import ./os/bazelisk/configuration.nix)
({
nixpkgs.overlays = [ self.overlays.default ];
})
];
};
};

templates.default = {
Expand Down
17 changes: 17 additions & 0 deletions os/bazelisk/configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ config, pkgs, lib, inputs, modulesPath, ... }: {
imports =
[
../incus/configuration.nix
];

environment.systemPackages = with pkgs; [
git
bazelisk-env
];

networking.hostName = "bazelisk";

users.users.test = {
isNormalUser = true;
};
}
10 changes: 10 additions & 0 deletions os/bazelisk/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euxo pipefail

if [ ! -e /tmp/mgit ]; then
git clone [email protected]:mgit/mgit /tmp/mgit
fi
incus exec bazelisk -- rm -rf /home/test/mgit
incus exec bazelisk -- rm -rf /home/test/.cache
incus file push /tmp/mgit bazelisk/home/test -r
14 changes: 14 additions & 0 deletions os/bazelisk/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euxo pipefail

cd "$(dirname "$(readlink -f "$0")")"
BASE=$(git rev-parse --show-toplevel)

incus launch images:nixos/unstable bazelisk -c security.nesting=true
incus config device add bazelisk nixos-common disk "source=$BASE" "path=/etc/nixos"
sleep 10s # allow it some time to boot
incus exec bazelisk -- nix shell --extra-experimental-features "nix-command flakes" nixpkgs#git --command git config --global --add safe.directory /etc/nixos || true
incus exec bazelisk -- nix shell --extra-experimental-features "nix-command flakes" nixpkgs#git --command nixos-rebuild switch --flake /etc/nixos#bazelisk || true
bash reset.sh
incus restart bazelisk
8 changes: 8 additions & 0 deletions os/bazelisk/shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -euxo pipefail

cd "$(dirname "$(readlink -f "$0")")"
BASE=$(git rev-parse --show-toplevel)

incus exec bazelisk -- su test -l -c "USE_SHELL=1 bazelisk-env"
11 changes: 11 additions & 0 deletions os/bazelisk/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euxo pipefail

cd "$(dirname "$(readlink -f "$0")")"
BASE=$(git rev-parse --show-toplevel)

incus exec bazelisk -- nixos-rebuild switch
incus restart bazelisk # kill old bazel processes
sleep 5s # allow it some time to boot
incus exec bazelisk -- sh -c "cd /home/test/mgit && su test -c 'bazelisk-env build //... --sandbox_debug --verbose_failures --keep_going'"
61 changes: 61 additions & 0 deletions pkgs/bazelisk-env/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
buildFHSUserEnv,
}:

buildFHSUserEnv {
name = "bazelisk-env";
extraOutputsToInstall = ["include" "dev"]; # TODO: make it saner?

# this is necesarry to make sure we don't inherit things from nixos that we don't want to inherit
# like non-FHS bash interactive from /run/current-system/sw/bin
extraBwrapArgs = [
# for debugging
"--ro-bind" "/run" "/.host-run"

"--tmpfs" "/run"
# dns
"--ro-bind" "/run/systemd" "/run/systemd"
# several things, including dns
"--ro-bind" "/run/nscd" "/run/nscd"
];

# for go build
multiArch = true;

# NOTE: since /run/current-system is inaccessible
# EVERY required tool must be specified here
targetPkgs = pkgs: with pkgs; [
# include no more than this
# crt1.o is already taken care of by buildFHSEnv.nix
gcc_multi.out
binutils
pkg-config
python3
coreutils-full # is not multi since takes forever to build and no cache available
bazelisk
git
which
python3
patch
iputils
host
];

# everything that we need both 64bit and 32bit versions of
multiPkgs = pkgs: with pkgs; [
zlib
];

profile = ''
export BAZELISK_ENV=1
export CC=$(which gcc)
CMD=bazelisk
if [ -v USE_SHELL ]; then
CMD="/usr/bin/bash"
fi
'';

runScript = "$CMD"; # $@ will already be appended by nix
}

0 comments on commit 2d390da

Please sign in to comment.