diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..883c706 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,43 @@ +{ + "name": "mixnet", + "dockerComposeFile": "docker-compose.yml", + "service": "devcontainer", + "updateContentCommand": "devenv ci", + "workspaceFolder": "/workspace", + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + }, + "customizations": { + "vscode": { + "extensions": [ + // run commands on save + // https://marketplace.visualstudio.com/items?itemName=fsevenm.run-it-on + "fsevenm.run-it-on", + + // Docker for Visual Studio Code + "ms-azuretools.vscode-docker", + + // direnv support + "mkhl.direnv", + + // Nix language support + "jnoortheen.nix-ide", + + // Markdown support and previsualization + "yzhang.markdown-all-in-one", + + // Debugging + "vadimcn.vscode-lldb", + + // Allows to use Alt+Q (or Option+Q in mac) to rewrap lines + "stkb.rewrap", + + // TOML support, for poetry + "tamasfe.even-better-toml", + + // For java support + "vscjava.vscode-java-pack" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..0f2a300 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.6" +services: + devcontainer: + image: ghcr.io/cachix/devenv:latest + volumes: + # Update this to wherever you want VS Code to mount the folder of your project + - ..:/workspace:cached + # Required for ptrace-based debuggers like C++, Go, and Rust + cap_add: + - SYS_PTRACE + security_opt: + - label:disable diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8cb5c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.devenv +.devenv.flake.nix +result diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..befa23f --- /dev/null +++ b/devenv.lock @@ -0,0 +1,156 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1690413082, + "narHash": "sha256-CPR3WcnrrIiDZJiMo4RlyZB0M3576pHmtlTUnMUTugA=", + "owner": "cachix", + "repo": "devenv", + "rev": "148c4a21e50428728e97f3cdf59166b6007db8a7", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1690327932, + "narHash": "sha256-Fv7PYZxN4eo0K6zXhHG/vOc+e2iuqQ5ywDrh0yeRjP0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a9b47d85504bdd199e90846622c76aa0bfeabfac", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1689668210, + "narHash": "sha256-XAATwDkaUxH958yXLs1lcEOmU6pSEIkatY3qjqk8X0E=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "eb433bff05b285258be76513add6f6c57b441775", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..c81c386 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,28 @@ +{ pkgs, config, lib, ... }: + +{ + # https://devenv.sh/basics/ + env.GREET = "devenv"; + + # https://devenv.sh/packages/ + packages = [ + pkgs.git + pkgs.ack + + # to create containers + pkgs.docker + + pkgs.libffi + ]; + + enterShell = '' + git --version + ''; + + # https://devenv.sh/languages/ + languages.nix.enable = true; + languages.java = { + enable = true; + jdk.package = pkgs.jdk8; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4640da2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1688466019, + "narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1690272529, + "narHash": "sha256-MakzcKXEdv/I4qJUtq/k/eG+rVmyOZLnYNC2w1mB59Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ef99fa5c5ed624460217c31ac4271cfb5cb2502c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1688049487, + "narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2a82a98 --- /dev/null +++ b/flake.nix @@ -0,0 +1,27 @@ +{ + description = "A simple flake for building and installing the mixnet."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } (let + mixnetModule = (import ./mixnet-module.nix); + in { + imports = []; + systems = [ "x86_64-linux" ]; + + # Per-system attributes can be defined here. The self' and inputs' + # module parameters provide easy access to attributes of the same + # system. + perSystem = perSystemInputs@{ config, self', inputs', pkgs, system, lib, ... }: + { + packages = rec { + mixnet = mixnetModule (perSystemInputs); + default = mixnet; + }; + }; + flake = {}; + }); +} diff --git a/mixnet-module.nix b/mixnet-module.nix new file mode 100644 index 0000000..5faabaa --- /dev/null +++ b/mixnet-module.nix @@ -0,0 +1,47 @@ +{ pkgs, jvmMemorySize ? "-Xmx4000m", ... }: + pkgs.stdenv.mkDerivation rec { + pname = "mixnet"; + version = "9.0.0"; + src = ./.; + + nativeBuildInputs = [ + pkgs.python3Minimal + pkgs.gnum4 + pkgs.automake + pkgs.makeWrapper + pkgs.patchelf + pkgs.autoconf + pkgs.jdk8 + ]; + buildInputs = [ + pkgs.jre8 + pkgs.gmp + ]; + + configureFlags = [ + "--enable-jgmpmee" + "--enable-jecn" + ]; + + makeFlags = [ + "JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8" + "JVM_MEMORY_SIZE=${jvmMemorySize}" + ]; + + installPhase = '' + echo "edu-install-phase: start" + mkdir -p $out/bin + mkdir -p $out/share/java + mkdir -p $out/lib + find mixnet/bin -type f -not -name '*.src' -exec cp {} $out/bin \; + find . -name "*.jar" -exec cp {} $out/share/java \; + find . -name "*.so*" -exec cp {} $out/lib \; + patchelf --remove-rpath $out/lib/*.so*; + echo "edu-install-phase: stop" + ''; + # TODO: + # - convert patchelf into a find -exec + # - add a find -exec wrapProgram to bins + # - nix flake update in eo + + } \ No newline at end of file diff --git a/mixnet/bin/vog.src b/mixnet/bin/vog.src index 8f09ca0..81b4391 100644 --- a/mixnet/bin/vog.src +++ b/mixnet/bin/vog.src @@ -32,19 +32,15 @@ # 32-bit mode instead of 64-bit mode. It is not needed in Linux or # FreeBSD. +set -eux -o pipefail # Extract the name of this shell script without its path. COMMAND_NAME=$0 COMMAND_NAME=${COMMAND_NAME##*/} -if [ x${VFORK_RANDOM_SOURCE} = x ]; then - VFORK_RANDOM_SOURCE=~/.mixnet_random_source -fi +VFORK_RANDOM_SOURCE="${VFORK_RANDOM_SOURCE:-~/.mixnet_random_source}" +VFORK_RANDOM_SEED="${VFORK_RANDOM_SEED:-~/.mixnet_random_seed}" -if [ x${VFORK_RANDOM_SEED} = x ]; then - VFORK_RANDOM_SEED=~/.mixnet_random_seed -fi - # If you want to be able to list and generate instances of your own # classes, you should set VFORK_VOG to be a comma-separated list # of classnames. This allows this command to list and generate @@ -52,17 +48,15 @@ fi # implements the # mixnet.ui.gen.Generator-interface. Alternatively, you can use # the -pkgs switch of this command. -if [ x${VFORK_VOG} = x ]; then - VFORK_VOG= -fi +VFORK_VOG="${VFORK_VOG:-}" -VFORK_VOG=${VFORK_VOG}:VFORK_VOG_BUILTIN +VFORK_VOG="${VFORK_VOG}:VFORK_VOG_BUILTIN" java \ -JVM_DATAMODEL \ --Djava.security.egd=file:/dev/./urandom \ -mixnet.ui.gen.GeneratorTool \ -"$COMMAND_NAME" \ -"$VFORK_VOG" \ -"$VFORK_RANDOM_SOURCE" \ -"$VFORK_RANDOM_SEED" "$@" + JVM_DATAMODEL \ + -Djava.security.egd=file:/dev/./urandom \ + mixnet.ui.gen.GeneratorTool \ + "$COMMAND_NAME" \ + "$VFORK_VOG" \ + "$VFORK_RANDOM_SOURCE" \ + "$VFORK_RANDOM_SEED" "$@"