commit 37bf8df09c44d2a951e3a6813cfbbbec90da0a2b Author: Aly Sewelam Date: Wed Apr 22 18:09:57 2026 +0200 yes diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b511ae1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.qcow2 diff --git a/asterisk/asterisk.conf b/asterisk/asterisk.conf new file mode 100644 index 0000000..5a6e34d --- /dev/null +++ b/asterisk/asterisk.conf @@ -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 \ No newline at end of file diff --git a/asterisk/extensions.conf b/asterisk/extensions.conf new file mode 100644 index 0000000..1bbe7ad --- /dev/null +++ b/asterisk/extensions.conf @@ -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() \ No newline at end of file diff --git a/asterisk/sip.conf b/asterisk/sip.conf new file mode 100644 index 0000000..edd35e3 --- /dev/null +++ b/asterisk/sip.conf @@ -0,0 +1,11 @@ +[general] +context = default +bindport = 5060 +bindaddr = 0.0.0.0 +srvlookup = yes + +[公共] +type = friend +host = dynamic +secret = 1234 +context = default \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8dfa8fa --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..191600f --- /dev/null +++ b/flake.nix @@ -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}"; + }; + } + ); +} diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..c574155 --- /dev/null +++ b/module.nix @@ -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 + ]; + }; +}