aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2022-11-14 00:40:17 +0100
committerpacien2022-11-14 00:40:17 +0100
commit94b4db41750a7b6846ba57f643cb05d8bf94e1cb (patch)
tree9a2b81b2ce8347ae300f57a39ac9cf808a83a92c
parente8459a4a34f2611a547b966b2c58867d99d0f40c (diff)
downloadflaky-utils-94b4db41750a7b6846ba57f643cb05d8bf94e1cb.tar.gz
mkSandboxSystem: add tools and envVars option with printing
-rw-r--r--example/flake.nix13
-rw-r--r--lib/mk-sandbox-system.nix20
2 files changed, 32 insertions, 1 deletions
diff --git a/example/flake.nix b/example/flake.nix
index 50931c6..17d15fc 100644
--- a/example/flake.nix
+++ b/example/flake.nix
@@ -50,6 +50,10 @@
50 # By default, the VM is launched in the current console without a graphical 50 # By default, the VM is launched in the current console without a graphical
51 # interface, dropping to a shell for the default dummy user within. 51 # interface, dropping to a shell for the default dummy user within.
52 # 52 #
53 # The binaries made available through the `tools` option and the
54 # environment variable set through the `envVars` option are printed when
55 # entering the shell.
56 #
53 # The current working directory from which the Flake is run is mounted and 57 # The current working directory from which the Flake is run is mounted and
54 # made available within the virtual machine in /mnt. The root filesystem 58 # made available within the virtual machine in /mnt. The root filesystem
55 # is ephemeral (written to a temporary file in /tmp). 59 # is ephemeral (written to a temporary file in /tmp).
@@ -64,6 +68,15 @@
64 name = "sandbox"; 68 name = "sandbox";
65 user = "dummy"; 69 user = "dummy";
66 70
71 tools = with pkgs; [
72 postgresql
73 pgcli
74 ];
75
76 envVars = {
77 PGDATABASE = "app";
78 };
79
67 config = { 80 config = {
68 virtualisation.forwardPorts = [ 81 virtualisation.forwardPorts = [
69 { from = "host"; host.port = 5432; guest.port = 5432; } # postgres 82 { from = "host"; host.port = 5432; guest.port = 5432; } # postgres
diff --git a/lib/mk-sandbox-system.nix b/lib/mk-sandbox-system.nix
index a56bdab..b678399 100644
--- a/lib/mk-sandbox-system.nix
+++ b/lib/mk-sandbox-system.nix
@@ -3,11 +3,16 @@ flake:
3, name ? "sandbox" 3, name ? "sandbox"
4, user ? "dummy" 4, user ? "dummy"
5, config ? { } 5, config ? { }
6, tools ? []
7, envVars ? { }
6, restrictNetwork ? true # to be replaced with virtualisation.restrictNetwork 8, restrictNetwork ? true # to be replaced with virtualisation.restrictNetwork
7, patchQemu9p ? false # until qemu 7.2.0 becomes available in nixpkgs 9, patchQemu9p ? false # until qemu 7.2.0 becomes available in nixpkgs
8}: 10}:
9 11
10rec { 12let
13 shellLib = flake.lib.shell { inherit pkgs; };
14
15in rec {
11 16
12 nixosConfigurations.${name} = pkgs.nixos ({ modulesPath, lib, pkgs, ... }: { 17 nixosConfigurations.${name} = pkgs.nixos ({ modulesPath, lib, pkgs, ... }: {
13 imports = [ 18 imports = [
@@ -43,6 +48,19 @@ rec {
43 ''; 48 '';
44 }; 49 };
45 50
51 environment = {
52 variables = envVars;
53 systemPackages = tools;
54
55 # TODO: also print a summary of the host mount points
56 # TODO: also print a summary of the forwarded ports
57 interactiveShellInit = lib.mkBefore ''
58 ${lib.optionalString (envVars != {}) (shellLib.printEnvVars envVars)}
59 ${lib.optionalString (tools != []) (shellLib.printBins tools)}
60 echo
61 '';
62 };
63
46 virtualisation = { 64 virtualisation = {
47 graphics = lib.mkDefault false; 65 graphics = lib.mkDefault false;
48 diskImage = lib.mkDefault "$TMP_DISK"; 66 diskImage = lib.mkDefault "$TMP_DISK";