This commit is contained in:
2026-04-22 18:09:57 +02:00
commit 37bf8df09c
7 changed files with 172 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.qcow2

9
asterisk/asterisk.conf Normal file
View File

@@ -0,0 +1,9 @@
[directories]
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlib => /var/lib/asterisk
astdb => /var/lib/asterisk
[options]
verbose = 3
debug = 0

9
asterisk/extensions.conf Normal file
View File

@@ -0,0 +1,9 @@
[default]
exten => 100,1,Answer()
same => n,Playback(demo-congrats)
same => n,Hangup()
exten => 200,1,Answer()
same => n,Wait(1)
same => n,Playback(demo-instruct)
same => n,Hangup()

11
asterisk/sip.conf Normal file
View File

@@ -0,0 +1,11 @@
[general]
context = default
bindport = 5060
bindaddr = 0.0.0.0
srvlookup = yes
[公共]
type = friend
host = dynamic
secret = 1234
context = default

44
flake.lock generated Normal file
View File

@@ -0,0 +1,44 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1652776076,
"narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8",
"type": "github"
},
"original": {
"owner": "numtide",
"ref": "v1.0.0",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1764521362,
"narHash": "sha256-M101xMtWdF1eSD0xhiR8nG8CXRlHmv6V+VoY65Smwf4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "871b9fd269ff6246794583ce4ee1031e1da71895",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "25.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

49
flake.nix Normal file
View File

@@ -0,0 +1,49 @@
{ inputs = {
flake-utils.url = "github:numtide/flake-utils/v1.0.0";
nixpkgs.url = "github:NixOS/nixpkgs/25.11";
};
outputs = { flake-utils, nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}";
base = { lib, modulesPath, ... }: {
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ];
# https://github.com/utmapp/UTM/issues/2353
networking.nameservers = lib.mkIf pkgs.stdenv.isDarwin [ "8.8.8.8" ];
virtualisation = {
graphics = false;
host = { inherit pkgs; };
};
};
machine = nixpkgs.lib.nixosSystem {
system = builtins.replaceStrings [ "darwin" ] [ "linux" ] system;
modules = [ base ./module.nix ];
};
program = pkgs.writeShellScript "run-vm.sh" ''
export NIX_DISK_IMAGE=$(mktemp -u -t nixos.qcow2)
trap "rm -f $NIX_DISK_IMAGE" EXIT
${machine.config.system.build.vm}/bin/run-nixos-vm
'';
in
{ packages = { inherit machine; };
apps.default = {
type = "app";
program = "${program}";
};
}
);
}

49
module.nix Normal file
View File

@@ -0,0 +1,49 @@
{
config,
pkgs,
lib,
modulesPath,
...
}:
let
asteriskDir = ./asterisk;
asteriskFiles = builtins.readDir asteriskDir;
fileNames = builtins.attrNames asteriskFiles;
entries = builtins.map (name: {
name = name;
path = "${asteriskDir}/${name}";
}) fileNames;
in
{
config =
let
configFarm = pkgs.linkFarm "asterisk-config" entries;
in
{
services.getty.autologinUser = "root";
systemd.services.asterisk = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkgs.asterisk}/bin/asterisk -f -C ${configFarm}/asterisk.conf";
Restart = "on-failure";
User = "asterisk";
};
};
users.users.asterisk = {
isSystemUser = true;
group = "asterisk";
};
users.groups.asterisk = { };
environment.etc."asterisk".source = configFarm;
networking.firewall.allowedTCPPorts = [ 5060 ];
networking.firewall.allowedUDPPorts = [
5060
4569
];
};
}