@@ -0,0 +1,474 @@
1+{ compiler ? "ghc865" }:
5+ packageOverrides = pkgs: rec {
6+ haskell = pkgs.haskell // {
7+ packages = pkgs.haskell.packages // {
8+ "${compiler}" = pkgs.haskell.packages."${compiler}".override {
9+ overrides = haskellPackagesNew: haskellPackagesOld: rec {
11+ /*primitive-unlifted =
12+ haskellPackagesNew.callPackage ./primitive-unlifted.nix { };*/
13+ distributed-process-extras =
14+ haskellPackagesNew.callPackage ./distributed-process-extras.nix { };
15+ distributed-process-client-server =
16+ haskellPackagesNew.callPackage ./distributed-process-client-server.nix { };
17+ distributed-process-async =
18+ haskellPackagesNew.callPackage ./distributed-process-async.nix { };
20+ haskellPackagesNew.callPackage ./rank1dynamic.nix { };
22+ haskellPackagesNew.callPackage ./distributed-static.nix { };
23+ distributed-process =
24+ haskellPackagesNew.callPackage ./distributed-process.nix { };
26+ haskellPackagesNew.callPackage ./stm-hamt.nix { };
28+ haskellPackagesNew.callPackage ./stm-containers.nix { };
29+ network-transport-tcp =
30+ haskellPackagesNew.callPackage ./network-transport-tcp.nix { };
32+ haskellPackagesNew.callPackage ./data-interval.nix { };
34+ haskellPackagesNew.callPackage ./project-m36.nix { };
42+ pkgs = if builtins.pathExists ./nixpkgs then
43+ import (builtins.fetchGit (import ./nixpkgs)) { inherit config; }
45+ import <nixpkgs> { inherit config; };
47+ inherit (pkgs) dockerTools stdenv buildEnv writeText runCommand jq lib writeReferencesToFile jshon pigz coreutils findutils moreutils;
49+ project-m36 = pkgs.haskell.packages.${compiler}.project-m36;
51+ static-project-m36 = pkgs.haskell.lib.justStaticExecutables pkgs.haskell.packages.${compiler}.project-m36;
54+ root:x:0:0::/root:/run/current-system/sw/bin/bash
55+ project-m36:x:90001:90001::/var/empty:/run/current-system/sw/bin/nologin
61+ project-m36:x:90001:project-m36
65+ hosts: files dns myhostname mymachines
70+ip 0 IP # internet protocol, pseudo protocol number
71+#hopopt 0 HOPOPT # hop-by-hop options for ipv6
72+icmp 1 ICMP # internet control message protocol
73+igmp 2 IGMP # internet group management protocol
74+ggp 3 GGP # gateway-gateway protocol
75+ipencap 4 IP-ENCAP # IP encapsulated in IP
76+st2 5 ST2 # ST2 datagram mode
77+tcp 6 TCP # transmission control protocol
78+cbt 7 CBT # CBT, Tony Ballardie
79+egp 8 EGP # exterior gateway protocol
80+igp 9 IGP # any private interior gateway
81+bbn-rcc 10 BBN-RCC-MON # BBN RCC Monitoring
82+nvp 11 NVP-II # Network Voice Protocol
83+pup 12 PUP # PARC universal packet protocol
84+argus 13 ARGUS # ARGUS
85+emcon 14 EMCON # EMCON
86+xnet 15 XNET # Cross Net Debugger
87+chaos 16 CHAOS # Chaos
88+udp 17 UDP # user datagram protocol
89+mux 18 MUX # Multiplexing protocol
90+dcn 19 DCN-MEAS # DCN Measurement Subsystems
91+hmp 20 HMP # host monitoring protocol
92+prm 21 PRM # packet radio measurement protocol
93+xns-idp 22 XNS-IDP # Xerox NS IDP
94+trunk-1 23 TRUNK-1 # Trunk-1
95+trunk-2 24 TRUNK-2 # Trunk-2
96+leaf-1 25 LEAF-1 # Leaf-1
97+leaf-2 26 LEAF-2 # Leaf-2
98+rdp 27 RDP # "reliable datagram" protocol
99+irtp 28 IRTP # Internet Reliable Transaction Protocol
100+iso-tp4 29 ISO-TP4 # ISO Transport Protocol Class 4
101+netblt 30 NETBLT # Bulk Data Transfer Protocol
102+mfe-nsp 31 MFE-NSP # MFE Network Services Protocol
103+merit-inp 32 MERIT-INP # MERIT Internodal Protocol
104+dccp 33 DCCP # Datagram Congestion Control Protocol
105+3pc 34 3PC # Third Party Connect Protocol
106+idpr 35 IDPR # Inter-Domain Policy Routing Protocol
107+xtp 36 XTP # Xpress Tranfer Protocol
108+ddp 37 DDP # Datagram Delivery Protocol
109+idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport Proto
110+tp++ 39 TP++ # TP++ Transport Protocol
111+il 40 IL # IL Transport Protocol
113+sdrp 42 SDRP # Source Demand Routing Protocol
114+ipv6-route 43 IPV6-ROUTE # routing header for ipv6
115+ipv6-frag 44 IPV6-FRAG # fragment header for ipv6
116+idrp 45 IDRP # Inter-Domain Routing Protocol
117+rsvp 46 RSVP # Resource ReSerVation Protocol
118+gre 47 GRE # Generic Routing Encapsulation
119+dsr 48 DSR # Dynamic Source Routing Protocol
121+esp 50 ESP # encapsulating security payload
122+ah 51 AH # authentication header
123+i-nlsp 52 I-NLSP # Integrated Net Layer Security TUBA
124+swipe 53 SWIPE # IP with Encryption
125+narp 54 NARP # NBMA Address Resolution Protocol
126+mobile 55 MOBILE # IP Mobility
127+tlsp 56 TLSP # Transport Layer Security Protocol
129+ipv6-icmp 58 IPV6-ICMP icmp6 # ICMP for IPv6
130+ipv6-nonxt 59 IPV6-NONXT # no next header for ipv6
131+ipv6-opts 60 IPV6-OPTS # destination options for ipv6
132+# 61 # any host internal protocol
134+# 63 # any local network
135+sat-expak 64 SAT-EXPAK # SATNET and Backroom EXPAK
136+kryptolan 65 KRYPTOLAN # Kryptolan
137+rvd 66 RVD # MIT Remote Virtual Disk Protocol
138+ippc 67 IPPC # Internet Pluribus Packet Core
139+# 68 # any distributed filesystem
140+sat-mon 69 SAT-MON # SATNET Monitoring
141+visa 70 VISA # VISA Protocol
142+ipcv 71 IPCV # Internet Packet Core Utility
143+cpnx 72 CPNX # Computer Protocol Network Executive
144+cphb 73 CPHB # Computer Protocol Heart Beat
145+wsn 74 WSN # Wang Span Network
146+pvp 75 PVP # Packet Video Protocol
147+br-sat-mon 76 BR-SAT-MON # Backroom SATNET Monitoring
148+sun-nd 77 SUN-ND # SUN ND PROTOCOL-Temporary
149+wb-mon 78 WB-MON # WIDEBAND Monitoring
150+wb-expak 79 WB-EXPAK # WIDEBAND EXPAK
151+iso-ip 80 ISO-IP # ISO Internet Protocol
152+vmtp 81 VMTP # Versatile Message Transport
153+secure-vmtp 82 SECURE-VMTP # SECURE-VMTP
154+vines 83 VINES # VINES
156+#iptm 84 IPTM # Protocol Internet Protocol Traffic
157+nsfnet-igp 85 NSFNET-IGP # NSFNET-IGP
158+dgp 86 DGP # Dissimilar Gateway Protocol
160+eigrp 88 EIGRP # Enhanced Interior Routing Protocol
161+ospf 89 OSPFIGP # Open Shortest Path First IGP
162+sprite-rpc 90 Sprite-RPC # Sprite RPC Protocol
163+larp 91 LARP # Locus Address Resolution Protocol
164+mtp 92 MTP # Multicast Transport Protocol
165+ax.25 93 AX.25 # AX.25 Frames
166+ipip 94 IPIP # Yet Another IP encapsulation
167+micp 95 MICP # Mobile Internetworking Control Pro.
168+scc-sp 96 SCC-SP # Semaphore Communications Sec. Pro.
169+etherip 97 ETHERIP # Ethernet-within-IP Encapsulation
170+encap 98 ENCAP # Yet Another IP encapsulation
171+# 99 # any private encryption scheme
173+ifmp 101 IFMP # Ipsilon Flow Management Protocol
174+pnni 102 PNNI # PNNI over IP
175+pim 103 PIM # Protocol Independent Multicast
179+a/n 107 A/N # Active Networks
180+ipcomp 108 IPComp # IP Payload Compression Protocol
181+snp 109 SNP # Sitara Networks Protocol
182+compaq-peer 110 Compaq-Peer # Compaq Peer Protocol
183+ipx-in-ip 111 IPX-in-IP # IPX in IP
184+carp 112 CARP vrrp # Common Address Redundancy Protocol
185+pgm 113 PGM # PGM Reliable Transport Protocol
186+# 114 # any 0-hop protocol
187+l2tp 115 L2TP # Layer Two Tunneling Protocol
188+ddx 116 DDX # D-II Data Exchange
189+iatp 117 IATP # Interactive Agent Transfer Protocol
190+stp 118 STP # Schedule Transfer Protocol
191+srp 119 SRP # SpectraLink Radio Protocol
193+smp 121 SMP # Simple Message Protocol
195+ptp 123 PTP # Performance Transparency Protocol
196+isis 124 ISIS # ISIS over IPv4
198+crtp 126 CRTP # Combat Radio Transport Protocol
199+crudp 127 CRUDP # Combat Radio User Datagram
200+sscopmce 128 SSCOPMCE
202+sps 130 SPS # Secure Packet Shield
203+pipe 131 PIPE # Private IP Encapsulation within IP
204+sctp 132 SCTP # Stream Control Transmission Protocol
205+fc 133 FC # Fibre Channel
206+rsvp-e2e-ignore 134 RSVP-E2E-IGNORE # Aggregation of RSVP for IP reservations
207+mobility-header 135 Mobility-Header # Mobility Support in IPv6
208+udplite 136 UDPLite # The UDP-Lite Protocol
209+mpls-in-ip 137 MPLS-IN-IP # Encapsulating MPLS in IP
210+manet 138 MANET # MANET Protocols
211+hip 139 HIP # Host Identity Protocol
212+shim6 140 SHIM6 # Shim6 Protocol
213+wesp 141 WESP # Wrapped Encapsulating Security Payload
214+rohc 142 ROHC # Robust Header Compression
215+# 138-254 # Unassigned
216+pfsync 240 PFSYNC # PF Synchronization
217+# 253-254 # Use for experimentation and testing
219+divert 258 DIVERT # Divert pseudo-protocol
222+ project-m36-conf = ''
227+ project-m36-env = stdenv.mkDerivation {
228+ name = "project-m36-env";
229+ phases = [ "installPhase" "fixupPhase" ];
232+ mkdir -p $out/etc/project-m36
233+ echo '${project-m36-conf}' > $out/etc/project-m36/project-m36.conf
234+ echo '${passwd}' > $out/etc/passwd
235+ echo '${group}' > $out/etc/group
236+ echo '${protocols}' > $out/etc/ptotocols
237+ echo '${nsswitch}' > $out/etc/nsswitch.conf
241+ # following buildImage is copied from nixpkgs-20.03
242+ # to fix the arch always amd64 issue
243+ myarch = platform: {
251+ }.${platform.parsed.cpu.name} or (throw "Unsupported system");
253+ MYTARGETARCH = myarch stdenv.targetPlatform;
255+ # 1. extract the base image
256+ # 2. create the layer
257+ # 3. add layer deps to the layer itself, diffing with the base image
258+ # 4. compute the layer id
259+ # 5. put the layer in the image
260+ # 6. repack the image
261+ mybuildImage = with dockerTools; args@{
264+ # Image tag, when null then the nix output hash will be used.
266+ # Parent image, to append to.
268+ # Name of the parent image; will be read from the image otherwise.
269+ fromImageName ? null,
270+ # Tag of the parent image; will be read from the image otherwise.
271+ fromImageTag ? null,
272+ # Files to put on the image (a nix store path or list of paths).
274+ # When copying the contents into the image, preserve symlinks to
275+ # directories (see `rsync -K`). Otherwise, transform those symlinks
277+ keepContentsDirlinks ? false,
278+ # Docker config; e.g. what command to run on the container.
280+ # Optional bash script to run on the files prior to fixturizing the layer.
281+ extraCommands ? "", uid ? 0, gid ? 0,
282+ # Optional bash script to run as root on the image when provisioning.
284+ # Size of the virtual machine disk to provision when building the image.
286+ # Time of creation of the image.
287+ created ? "1970-01-01T00:00:01Z",
291+ baseName = baseNameOf name;
293+ # Create a JSON blob of the configuration. Set the date to unix zero.
295+ pure = writeText "${baseName}-config.json" (builtins.toJSON {
296+ inherit created config;
297+ architecture = MYTARGETARCH;
300+ impure = runCommand "${baseName}-config.json"
301+ { nativeBuildInputs = [ jq ]; }
303+ jq ".created = \"$(TZ=utc date --iso-8601="seconds")\"" ${pure} > $out
305+ in if created == "now" then impure else pure;
308+ if runAsRoot == null
311+ inherit baseJson contents keepContentsDirlinks extraCommands uid gid;
312+ } else mkRootLayer {
314+ inherit baseJson fromImage fromImageName fromImageTag
315+ contents keepContentsDirlinks runAsRoot diskSize
318+ result = runCommand "docker-image-${baseName}.tar.gz" {
319+ nativeBuildInputs = [ jshon pigz coreutils findutils jq moreutils ];
320+ # Image name and tag must be lowercase
321+ imageName = lib.toLower name;
322+ imageTag = if tag == null then "" else lib.toLower tag;
323+ inherit fromImage baseJson;
324+ layerClosure = writeReferencesToFile layer;
325+ passthru.buildArgs = args;
326+ passthru.layer = layer;
328+ ${lib.optionalString (tag == null) ''
329+ outName="$(basename "$out")"
330+ outHash=$(echo "$outName" | cut -d - -f 1)
333+ # Print tar contents:
334+ # 1: Interpreted as relative to the root directory
335+ # 2: With no trailing slashes on directories
336+ # This is useful for ensuring that the output matches the
337+ # values generated by the "find" command
339+ for f in $(tar -tf $1 | xargs realpath -ms --relative-to=.); do
340+ if [[ "$f" != "." ]]; then
347+ if [[ -n "$fromImage" ]]; then
348+ echo "Unpacking base image..."
349+ tar -C image -xpf "$fromImage"
350+ cat ./image/manifest.json | jq -r '.[0].Layers | .[]' > layer-list
351+ # Do not import the base image configuration and manifest
352+ chmod a+w image image/*.json
354+ if [[ -z "$fromImageName" ]]; then
355+ fromImageName=$(jshon -k < image/repositories|head -n1)
357+ if [[ -z "$fromImageTag" ]]; then
358+ fromImageTag=$(jshon -e $fromImageName -k \
359+ < image/repositories|head -n1)
361+ parentID=$(jshon -e $fromImageName -e $fromImageTag -u \
362+ < image/repositories)
363+ for l in image/*/layer.tar; do
364+ ls_tar $l >> baseFiles
369+ chmod -R ug+rw image
373+ for dep in $(cat $layerClosure); do
374+ find $dep >> layerFiles
376+ echo "Adding layer..."
377+ # Record the contents of the tarball with ls_tar.
378+ ls_tar temp/layer.tar >> baseFiles
379+ # Append nix/store directory to the layer so that when the layer is loaded in the
380+ # image /nix/store has read permissions for non-root users.
381+ # nix/store is added only if the layer has /nix/store paths in it.
382+ if [ $(wc -l < $layerClosure) -gt 1 ] && [ $(grep -c -e "^/nix/store$" baseFiles) -eq 0 ]; then
385+ echo "./nix" >> layerFiles
386+ echo "./nix/store" >> layerFiles
388+ # Get the files in the new layer which were *not* present in
389+ # the old layer, and record them as newFiles.
390+ comm <(sort -n baseFiles|uniq) \
391+ <(sort -n layerFiles|uniq|grep -v ${layer}) -1 -3 > newFiles
392+ # Append the new files to the layer.
393+ tar -rpf temp/layer.tar --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" \
394+ --owner=0 --group=0 --no-recursion --files-from newFiles
395+ echo "Adding meta..."
396+ # If we have a parentID, add it to the json metadata.
397+ if [[ -n "$parentID" ]]; then
398+ cat temp/json | jshon -s "$parentID" -i parent > tmpjson
399+ mv tmpjson temp/json
401+ # Take the sha256 sum of the generated json and use it as the layer ID.
402+ # Compute the size and add it to the json under the 'Size' field.
403+ layerID=$(sha256sum temp/json|cut -d ' ' -f 1)
404+ size=$(stat --printf="%s" temp/layer.tar)
405+ cat temp/json | jshon -s "$layerID" -i id -n $size -i Size > tmpjson
406+ mv tmpjson temp/json
407+ # Use the temp folder we've been working on to create a new image.
408+ mv temp image/$layerID
409+ # Add the new layer ID to the end of the layer list
412+ # originally this used `sed -i "1i$layerID" layer-list`, but
413+ # would fail if layer-list was completely empty.
414+ echo "$layerID/layer.tar"
415+ ) | sponge layer-list
416+ # Create image json and image manifest
417+ imageJson=$(cat ${baseJson} | jq ". + {\"rootfs\": {\"diff_ids\": [], \"type\": \"layers\"}}")
418+ manifestJson=$(jq -n "[{\"RepoTags\":[\"$imageName:$imageTag\"]}]")
419+ for layerTar in $(cat ./layer-list); do
420+ layerChecksum=$(sha256sum image/$layerTar | cut -d ' ' -f1)
421+ imageJson=$(echo "$imageJson" | jq ".history |= . + [{\"created\": \"$(jq -r .created ${baseJson})\"}]")
422+ # diff_ids order is from the bottom-most to top-most layer
423+ imageJson=$(echo "$imageJson" | jq ".rootfs.diff_ids |= . + [\"sha256:$layerChecksum\"]")
424+ manifestJson=$(echo "$manifestJson" | jq ".[0].Layers |= . + [\"$layerTar\"]")
426+ imageJsonChecksum=$(echo "$imageJson" | sha256sum | cut -d ' ' -f1)
427+ echo "$imageJson" > "image/$imageJsonChecksum.json"
428+ manifestJson=$(echo "$manifestJson" | jq ".[0].Config = \"$imageJsonChecksum.json\"")
429+ echo "$manifestJson" > image/manifest.json
430+ # Store the json under the name image/repositories.
432+ -n object -s "$layerID" -i "$imageTag" \
433+ -i "$imageName" > image/repositories
434+ # Make the image read-only.
436+ echo "Cooking the image..."
437+ tar -C image --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0 --xform s:'^./':: -c . | pigz -nT > $out
444+ project-m36-docker = mybuildImage {
445+ name = "project-m36";
446+ tag = project-m36.version;
449+ contents = [ static-project-m36
453+ "PATH=${static-project-m36}/bin:$PATH"
455+ "DATABASE_DIRECTORY=/var/project-m36/data"
456+ "HOSTNAME=localhost"
459+ User = "project-m36";
460+ Cmd = [ "project-m36-server" ];
464+ WorkingDir = "/var/project-m36/data";
466+ "/var/project-m36/data" = {};
471+ inherit project-m36;
472+ inherit static-project-m36;
473+ inherit project-m36-docker;