Skip to content

Commit 4dbffeb

Browse files
committedFeb 20, 2024
Add SSH
1 parent 46bf62f commit 4dbffeb

10 files changed

+398
-0
lines changed
 

‎.envrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
watch_file *.nix
2+
use flake . --impure

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.devenv
2+
.direnv
3+
.pre-commit-config.yaml
4+
nixos.qcow2

‎README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# VM
2+
Host marlowe-vm
3+
HostName localhost
4+
Port 2221
5+
ForwardAgent yes
6+
StrictHostKeyChecking no
7+
UserKnownHostsFile /dev/null

‎access.nix

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{ lib, config, pkgs, ... }:
2+
let
3+
inherit (lib) types mkOption;
4+
userType = types.submodule {
5+
options = {
6+
admin = mkOption {
7+
type = types.bool;
8+
default = false;
9+
description = "Whether the user is an admin";
10+
};
11+
keys = mkOption {
12+
type = types.listOf types.str;
13+
description = "The user's SSH public key";
14+
};
15+
name = mkOption {
16+
type = types.str;
17+
description = "The user's name";
18+
};
19+
};
20+
};
21+
in {
22+
options = {
23+
marlowe.users = lib.mkOption {
24+
type = lib.types.attrsOf userType;
25+
internal = true;
26+
description = "The users with access to the machine";
27+
};
28+
};
29+
config = {
30+
marlowe.users = lib.importTOML ./users.toml;
31+
32+
users.users = lib.mapAttrs (_: user:
33+
{
34+
isNormalUser = true;
35+
openssh.authorizedKeys.keys = user.keys;
36+
description = user.name;
37+
} // lib.optionalAttrs user.admin { extraGroups = [ "wheel" ]; })
38+
config.marlowe.users;
39+
40+
# Enable SSH + mosh
41+
environment.systemPackages = with pkgs; [ mosh ];
42+
services.openssh.enable = true;
43+
networking.firewall.allowedTCPPorts = [ 22 ];
44+
networking.firewall.allowedUDPPortRanges = lib.singleton {
45+
from = 60001;
46+
to = 60999;
47+
};
48+
security.pam.enableSSHAgentAuth = true;
49+
security.pam.services.sudo.sshAgentAuth = true;
50+
};
51+
}

‎bootloader.nix

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
boot.loader.systemd-boot.enable = true;
3+
boot.loader.efi.canTouchEfiVariables = true;
4+
}

‎configuration.nix

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
imports = [ ./access.nix ./bootloader.nix ./vm.nix ];
3+
4+
nixpkgs.localSystem.system = "x86_64-linux";
5+
6+
system.stateVersion = "23.11";
7+
}

‎flake.lock

+272
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
inputs = {
3+
# When updating past 23.11, use runtimeEnv in writeShellApplication
4+
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
5+
devenv.url = "github:cachix/devenv";
6+
};
7+
8+
outputs = inputs@{ flake-parts, devenv, nixpkgs, self }:
9+
flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: {
10+
imports = [ devenv.flakeModule ];
11+
systems = [ "x86_64-linux" ];
12+
flake.nixosConfigurations.marlowe = nixpkgs.lib.nixosSystem {
13+
modules = lib.singleton ./configuration.nix;
14+
};
15+
16+
perSystem = { pkgs, ... }:
17+
let
18+
utilities = {
19+
start-vm = pkgs.writeShellApplication {
20+
name = "start-vm";
21+
text = ''
22+
export QEMU_NET_OPTS="hostfwd=tcp::2221-:22"
23+
exec run-nixos-vm
24+
'';
25+
runtimeInputs =
26+
[ self.nixosConfigurations.marlowe.config.system.build.vm ];
27+
};
28+
};
29+
in {
30+
apps =
31+
lib.mapAttrs (name: prog: { program = "${prog}/bin/${name}"; });
32+
devenv.shells.default = {
33+
pre-commit.hooks = {
34+
nixfmt.enable = true;
35+
deadnix.enable = true;
36+
statix.enable = true;
37+
};
38+
packages = with pkgs;
39+
[ nixos-rebuild ] ++ lib.mapAttrsToList (_: prog: prog) utilities;
40+
};
41+
};
42+
});
43+
}

0 commit comments

Comments
 (0)