Skip to content

Commit c44e690

Browse files
authored
Init project demos (#613)
1 parent 4391ebb commit c44e690

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
result
22
.tmp
3+
*.qcow2
34

45
# Generated by nix-pre-commit-hooks
56
/.pre-commit-config.yaml

default.nix

+86
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,90 @@ rec {
262262
shell = pkgs.mkShellNoCC {
263263
packages = [ ];
264264
};
265+
266+
demo-system =
267+
module:
268+
let
269+
nixosSystem =
270+
args:
271+
import (sources.nixpkgs + "/nixos/lib/eval-config.nix") (
272+
{
273+
inherit lib;
274+
system = null;
275+
}
276+
// args
277+
);
278+
in
279+
nixosSystem {
280+
system = "x86_64-linux";
281+
modules = [
282+
module
283+
(sources.nixpkgs + "/nixos/modules/profiles/qemu-guest.nix")
284+
(sources.nixpkgs + "/nixos/modules/virtualisation/qemu-vm.nix")
285+
(
286+
{ config, ... }:
287+
{
288+
users.users.nixos = {
289+
isNormalUser = true;
290+
extraGroups = [ "wheel" ];
291+
initialPassword = "nixos";
292+
};
293+
294+
users.users.root = {
295+
initialPassword = "root";
296+
};
297+
298+
security.sudo.wheelNeedsPassword = false;
299+
300+
services.getty.autologinUser = "nixos";
301+
services.getty.helpLine = ''
302+
303+
Welcome to NGIpkgs!
304+
'';
305+
306+
services.openssh = {
307+
enable = true;
308+
settings = {
309+
PasswordAuthentication = true;
310+
PermitEmptyPasswords = "yes";
311+
PermitRootLogin = "yes";
312+
};
313+
};
314+
315+
system.stateVersion = "25.05";
316+
317+
networking.firewall.enable = false;
318+
319+
virtualisation = {
320+
memorySize = 4096;
321+
cores = 4;
322+
graphics = false;
323+
324+
qemu.options = [
325+
"-cpu host"
326+
"-enable-kvm"
327+
];
328+
329+
# ssh + open service ports
330+
forwardPorts = map (port: {
331+
from = "host";
332+
guest.port = port;
333+
host.port = port + 10000;
334+
proto = "tcp";
335+
}) config.networking.firewall.allowedTCPPorts;
336+
};
337+
}
338+
)
339+
] ++ extendedNixosModules;
340+
};
341+
342+
demo =
343+
module:
344+
pkgs.writeShellScript "demo-vm" ''
345+
exec ${(demo-system module).config.system.build.vm}/bin/run-nixos-vm "$@"
346+
'';
347+
348+
# $ nix-build . -A demo-test
349+
# $ ./result
350+
demo-test = demo ./projects/Cryptpad/demo.nix;
265351
}

0 commit comments

Comments
 (0)