diff --git a/README.md b/README.md index 738c3df..b1ae7c7 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Thebacknd is a proof-of-concept to run a NixOS system as a DigitalOcean virtual machine in a single command. ``` -$ scripts/build-toplevel.sh +$ scripts/build-toplevels.sh /nix/store/lk6igl2f0i137q36wscfrc6n9r0jn52l-nixos-system-unnamed-23.05pre-git $ scripts/thebacknd-run /nix/store/lk6igl2f0i137q36wscfrc6n9r0jn52l-nixos-system-unnamed-23.05pre-git ``` diff --git a/default.nix b/default.nix index e88b6c7..c1c25e8 100644 --- a/default.nix +++ b/default.nix @@ -14,26 +14,35 @@ let rustc = toolchain; }; - os = import "${toString sources.nixpkgs}/nixos/lib/eval-config.nix" { + base = import "${toString sources.nixpkgs}/nixos/lib/eval-config.nix" { modules = [ "${toString sources.nixpkgs}/nixos/modules/virtualisation/digital-ocean-image.nix" - ./machine/configuration.nix + ./machines/base/configuration.nix ]; }; qemu = import "${toString sources.nixpkgs}/nixos/lib/eval-config.nix" { modules = [ "${toString sources.nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix" - ./machine/configuration.nix - ./machine/no-gui.nix + ./machines/base/configuration.nix + ./machines/base/no-gui.nix + ]; + }; + + example = import "${toString sources.nixpkgs}/nixos/lib/eval-config.nix" { + modules = [ + "${toString sources.nixpkgs}/nixos/modules/virtualisation/digital-ocean-image.nix" + ./machines/base/configuration.nix + ./machines/example/hello.nix ]; }; in rec { # Build with nix-build -A - toplevel = os.config.system.build.toplevel; - image = os.config.system.build.digitalOceanImage; + toplevels.base = base.config.system.build.toplevel; + toplevels.example = example.config.system.build.toplevel; + image = base.config.system.build.digitalOceanImage; runvm = qemu.config.system.build.vm; binaries = naersk.buildPackage ./.; diff --git a/machine/configuration.nix b/machines/base/configuration.nix similarity index 100% rename from machine/configuration.nix rename to machines/base/configuration.nix diff --git a/machine/no-gui.nix b/machines/base/no-gui.nix similarity index 100% rename from machine/no-gui.nix rename to machines/base/no-gui.nix diff --git a/machine/scripts.nix b/machines/base/scripts.nix similarity index 85% rename from machine/scripts.nix rename to machines/base/scripts.nix index 12c49c1..cf4739e 100644 --- a/machine/scripts.nix +++ b/machines/base/scripts.nix @@ -1,7 +1,7 @@ { pkgs }: let current-system = pkgs.runCommandLocal "current-system" { - script = ../scripts/current-system.sh; + script = ../../scripts/current-system.sh; nativeBuildInputs = [ pkgs.makeWrapper ]; } '' makeWrapper $script $out/bin/current-system \ @@ -9,7 +9,7 @@ current-system = pkgs.runCommandLocal "current-system" { ''; desired-system = pkgs.runCommandLocal "desired-system" { - script = ../scripts/desired-system.sh; + script = ../../scripts/desired-system.sh; nativeBuildInputs = [ pkgs.makeWrapper pkgs.curl ]; } '' makeWrapper $script $out/bin/desired-system \ @@ -17,7 +17,7 @@ desired-system = pkgs.runCommandLocal "desired-system" { ''; destroy-system = pkgs.runCommandLocal "destroy-system" { - script = ../scripts/destroy-system.sh; + script = ../../scripts/destroy-system.sh; nativeBuildInputs = [ pkgs.makeWrapper pkgs.curl pkgs.jq ]; } '' makeWrapper $script $out/bin/destroy-system \ @@ -25,7 +25,7 @@ destroy-system = pkgs.runCommandLocal "destroy-system" { ''; update-system = pkgs.runCommandLocal "update-system" { - script = ../scripts/update-system.sh; + script = ../../scripts/update-system.sh; nativeBuildInputs = [ pkgs.makeWrapper ]; } '' install -m755 $script -D $out/bin/update-system diff --git a/machines/example/hello.nix b/machines/example/hello.nix new file mode 100644 index 0000000..1f528c8 --- /dev/null +++ b/machines/example/hello.nix @@ -0,0 +1,7 @@ +{ config, lib, pkgs, + ... }: +{ + environment.systemPackages = [ + pkgs.hello + ]; +} diff --git a/scripts/build-toplevel.sh b/scripts/build-toplevels.sh similarity index 50% rename from scripts/build-toplevel.sh rename to scripts/build-toplevels.sh index 70b12dd..31c701a 100755 --- a/scripts/build-toplevel.sh +++ b/scripts/build-toplevels.sh @@ -1,26 +1,36 @@ #! /usr/bin/env bash -# Build, sign, and cache the toplevel and binaries. +# Build, sign, and cache the toplevels and binaries. -nix-build -A toplevel --out-link result-toplevel +nix-build -A toplevels.base --out-link result-toplevel-base +nix-build -A toplevels.example --out-link result-toplevel-example nix-build -A binaries --out-link result-binaries nix store sign \ --recursive \ --key-file signing-keys/cache-priv-key.pem \ - $(readlink ./result-toplevel) + $(readlink ./result-toplevel-base) +nix store sign \ + --recursive \ + --key-file signing-keys/cache-priv-key.pem \ + $(readlink ./result-toplevel-example) nix store sign \ --recursive \ --key-file signing-keys/cache-priv-key.pem \ $(readlink ./result-binaries) +exit 0 + set -a source .env-nix-build set +a nix copy --to \ 's3://hypered-private-store/cache?endpoint=s3.eu-central-003.backblazeb2.com' \ - $(readlink ./result-toplevel) + $(readlink ./result-toplevel-base) +nix copy --to \ + 's3://hypered-private-store/cache?endpoint=s3.eu-central-003.backblazeb2.com' \ + $(readlink ./result-toplevel-example) nix copy --to \ 's3://hypered-private-store/cache?endpoint=s3.eu-central-003.backblazeb2.com' \ $(readlink ./result-binaries)