nix/vm: init, nix/default: fix building
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
/target
|
||||
result
|
||||
result-*
|
||||
|
||||
*.qcow2
|
||||
|
||||
24
flake.nix
24
flake.nix
@@ -32,6 +32,23 @@
|
||||
};
|
||||
in f system pkgs toolchain);
|
||||
in {
|
||||
apps = let
|
||||
mkApp = program: description: {
|
||||
type = "app";
|
||||
program = toString program;
|
||||
meta = {
|
||||
inherit description;
|
||||
};
|
||||
};
|
||||
mkVm = name: mkApp "${self.nixosConfigurations.${name}.config.system.build.vm}/bin/run-nixos-vm";
|
||||
in forAllSystems (system: pkgs: _: {
|
||||
vm = mkVm "vm" "Start a NixOS VM with roowho2 installed";
|
||||
});
|
||||
|
||||
nixosConfigurations = {
|
||||
vm = import ./nix/vm.nix { inherit self nixpkgs; };
|
||||
};
|
||||
|
||||
devShell = forAllSystems (system: pkgs: toolchain: pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
toolchain
|
||||
@@ -63,10 +80,15 @@
|
||||
./Cargo.lock
|
||||
];
|
||||
};
|
||||
|
||||
rustPlatform = pkgs.makeRustPlatform {
|
||||
rustc = pkgs.rust-bin.nightly.latest.default;
|
||||
cargo = pkgs.rust-bin.nightly.latest.cargo;
|
||||
};
|
||||
in {
|
||||
default = self.packages.${system}.roowho2;
|
||||
|
||||
roowho2 = pkgs.callPackage ./nix/default.nix { inherit cargoToml cargoLock src; };
|
||||
roowho2 = pkgs.callPackage ./nix/default.nix { inherit cargoToml cargoLock src rustPlatform; };
|
||||
|
||||
filteredSource = pkgs.runCommandLocal "filtered-source" { } ''
|
||||
ln -s ${src} $out
|
||||
|
||||
@@ -18,6 +18,8 @@ rustPlatform.buildRustPackage {
|
||||
|
||||
# buildType = "releaselto";
|
||||
|
||||
RUSTFLAGS = "-Zhigher-ranked-assumptions";
|
||||
|
||||
meta = with lib; {
|
||||
license = licenses.mit;
|
||||
platforms = platforms.linux ++ platforms.darwin;
|
||||
|
||||
@@ -12,7 +12,9 @@ in {
|
||||
freeformType = format.type;
|
||||
options = {
|
||||
rwhod = {
|
||||
enable = lib.mkEnableOption "the rwhod service";
|
||||
enable = lib.mkEnableOption "the rwhod service" // {
|
||||
default = true;
|
||||
};
|
||||
|
||||
# TODO: allow configuring socket config
|
||||
};
|
||||
@@ -24,10 +26,20 @@ in {
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.sockets.roowho2-client = {
|
||||
wantedBy = [ "sockets.target" ];
|
||||
description = "Roowho2 Client Communication Socket";
|
||||
listenStreams = [ "/run/roowho2/roowho2.varlink" ];
|
||||
socketConfig = {
|
||||
Service = "roowho2.service";
|
||||
FileDescriptorName = "client_socket";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.sockets.roowhoo2-rwhod = lib.mkIf cfg.settings.rwhod.enable {
|
||||
systemd.sockets.roowho2-rwhod = lib.mkIf cfg.settings.rwhod.enable {
|
||||
wantedBy = [ "sockets.target" ];
|
||||
description = "Roowho2 Rwhod Socket";
|
||||
listenDatagrams = [ 513 ];
|
||||
listenDatagrams = [ (toString 513) ];
|
||||
socketConfig = {
|
||||
Service = "roowho2.service";
|
||||
FileDescriptorName = "rwhod_socket";
|
||||
@@ -37,7 +49,7 @@ in {
|
||||
|
||||
systemd.services.roowho2 = {
|
||||
serviceConfig = {
|
||||
ExecStart = "${lib.getExe' cfg.package "roowho2d"} --config ${format.toFile cfg.settings}";
|
||||
ExecStart = "${lib.getExe' cfg.package "roowhod"} --config ${format.generate "roowho2-config.toml" cfg.settings}";
|
||||
Restart = "on-failure";
|
||||
DynamicUser = true;
|
||||
|
||||
|
||||
47
nix/vm.nix
Normal file
47
nix/vm.nix
Normal file
@@ -0,0 +1,47 @@
|
||||
{ self, nixpkgs, ... }:
|
||||
nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs {
|
||||
system = "x86_64-linux";
|
||||
overlays = [
|
||||
self.overlays.roowho2
|
||||
];
|
||||
};
|
||||
modules = [
|
||||
"${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix"
|
||||
"${nixpkgs}/nixos/tests/common/user-account.nix"
|
||||
|
||||
self.nixosModules.default
|
||||
|
||||
({ config, pkgs, ... }: {
|
||||
system.stateVersion = config.system.nixos.release;
|
||||
virtualisation.graphics = false;
|
||||
|
||||
services.getty.autologinUser = "alice";
|
||||
|
||||
users.motd = ''
|
||||
=================================
|
||||
Welcome to the roowho2 vm!
|
||||
|
||||
Try running any of:
|
||||
rwho
|
||||
|
||||
Password for alice is 'foobar'
|
||||
|
||||
To exit, press Ctrl+A, then X
|
||||
=================================
|
||||
'';
|
||||
|
||||
services.roowho2 = {
|
||||
enable = true;
|
||||
};
|
||||
|
||||
programs.vim = {
|
||||
enable = true;
|
||||
defaultEditor = true;
|
||||
};
|
||||
|
||||
environment.systemPackages = with pkgs; [ jq roowho2 ];
|
||||
})
|
||||
];
|
||||
}
|
||||
@@ -25,7 +25,7 @@ pub struct Args {
|
||||
async fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let mut conn = zlink::unix::connect("/run/roowho2/rwhod.varlink")
|
||||
let mut conn = zlink::unix::connect("/run/roowho2/roowho2.varlink")
|
||||
.await
|
||||
.expect("Failed to connect to rwhod server");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user