Skip to content

Commit e67715f

Browse files
committed
Enable binary cache usage
This adds a new Make task `cache` that will build and push a machine configuration into the cache (requires an auth token). This configures pulling to use my binary cache, which is public and doesn't require any auth tokens. I only push my NixOS configs there which are already all public and contain no secrets. Cachix has to be configured in bootstrap0 because it requires a full complete Nix run before its active (not active until the next run). So by doing it in bootstrap0, our bootstrap uses the cache which is the custom part.
1 parent 1b409d3 commit e67715f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ switch:
1919
test:
2020
sudo NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nixos-rebuild test --flake ".#$(NIXNAME)"
2121

22+
# This builds the given NixOS configuration and pushes the results to the
23+
# cache. This does not alter the current running system. This requires
24+
# cachix authentication to be configured out of band.
25+
cache:
26+
nix build '.#nixosConfigurations.$(NIXNAME).config.system.build.toplevel' --json \
27+
| jq -r '.[].outputs | to_entries[].value' \
28+
| cachix push mitchellh-nixos-config
29+
2230
# bootstrap a brand new VM. The VM should have NixOS ISO on the CD drive
2331
# and just set the password of the root user to "root". This will install
2432
# NixOS. After installing NixOS, you must reboot and set the root password
@@ -45,6 +53,8 @@ vm/bootstrap0:
4553
sed --in-place '/system\.stateVersion = .*/a \
4654
nix.package = pkgs.nixUnstable;\n \
4755
nix.extraOptions = \"experimental-features = nix-command flakes\";\n \
56+
nix.binaryCaches = [\"https://mitchellh-nixos-config.cachix.org\"];\n \
57+
nix.binaryCachePublicKeys = [\"mitchellh-nixos-config.cachix.org-1:bjEbXJyLrL1HZZHBbO4QALnI5faYZppzkU4D2s0G8RQ=\"];\n \
4858
services.openssh.enable = true;\n \
4959
services.openssh.passwordAuthentication = true;\n \
5060
services.openssh.permitRootLogin = \"yes\";\n \
@@ -64,7 +74,6 @@ vm/bootstrap:
6474
sudo reboot; \
6575
"
6676

67-
6877
# copy our secrets into the VM
6978
vm/secrets:
7079
# GPG keyring

machines/vm-shared.nix

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
# Be careful updating this.
55
boot.kernelPackages = pkgs.linuxPackages_latest;
66

7-
# use unstable nix so we can access flakes
87
nix = {
8+
# use unstable nix so we can access flakes
99
package = pkgs.nixUnstable;
1010
extraOptions = ''
1111
experimental-features = nix-command flakes
1212
keep-outputs = true
1313
keep-derivations = true
1414
'';
15-
};
15+
16+
# public binary cache that I use for all my derivations. You can keep
17+
# this, use your own, or toss it. Its typically safe to use a binary cache
18+
# since the data inside is checksummed.
19+
binaryCaches = ["https://mitchellh-nixos-config.cachix.org"];
20+
binaryCachePublicKeys = ["mitchellh-nixos-config.cachix.org-1:bjEbXJyLrL1HZZHBbO4QALnI5faYZppzkU4D2s0G8RQ="];
21+
};
1622

1723
# We expect to run the VM on hidpi machines.
1824
hardware.video.hidpi.enable = true;
@@ -90,6 +96,7 @@
9096
# List packages installed in system profile. To search, run:
9197
# $ nix search wget
9298
environment.systemPackages = with pkgs; [
99+
cachix
93100
gnumake
94101
killall
95102
niv

0 commit comments

Comments
 (0)