summaryrefslogtreecommitdiff
path: root/ymir
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-06-02 02:11:28 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-06-02 02:11:28 +0200
commit9af39788be8d359239b238c49c60247bda9fd69d (patch)
tree50ef3fb235b5a5f2f55ac78601a1927eccea63fc /ymir
parent1af57675931369e3b1a7b908b18469fc14497be7 (diff)
downloadnixos-9af39788be8d359239b238c49c60247bda9fd69d.tar
nixos-9af39788be8d359239b238c49c60247bda9fd69d.tar.gz
nixos-9af39788be8d359239b238c49c60247bda9fd69d.tar.bz2
nixos-9af39788be8d359239b238c49c60247bda9fd69d.tar.xz
nixos-9af39788be8d359239b238c49c60247bda9fd69d.zip
mlmmj-expose
Diffstat (limited to 'ymir')
-rw-r--r--ymir/hw.nix39
-rw-r--r--ymir/mlmmj-expose.nix87
2 files changed, 126 insertions, 0 deletions
diff --git a/ymir/hw.nix b/ymir/hw.nix
new file mode 100644
index 00000000..3ddf1035
--- /dev/null
+++ b/ymir/hw.nix
@@ -0,0 +1,39 @@
1# Do not modify this file! It was generated by ‘nixos-generate-config’
2# and may be overwritten by future invocations. Please make changes
3# to /etc/nixos/configuration.nix instead.
4{ config, lib, pkgs, ... }:
5
6{
7 imports =
8 [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
9 <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
10 ];
11
12 boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "virtio_pci" "virtio_blk" ];
13 boot.kernelModules = [ ];
14 boot.extraModulePackages = [ ];
15
16 fileSystems."/" =
17 {
18 device = "/dev/disk/by-label/ymir-root";
19 fsType = "ext4";
20 };
21
22 fileSystems."/boot" =
23 {
24 device = "/dev/disk/by-label/ymir-boot";
25 fsType = "ext2";
26 };
27
28 fileSystems."/home" =
29 {
30 device = "/dev/disk/by-label/ymir-home";
31 fsType = "ext4";
32 };
33
34 swapDevices =
35 [ { device = "/dev/disk/by-label/ymir-swap"; }
36 ];
37
38 nix.maxJobs = 2;
39}
diff --git a/ymir/mlmmj-expose.nix b/ymir/mlmmj-expose.nix
new file mode 100644
index 00000000..4fa317a0
--- /dev/null
+++ b/ymir/mlmmj-expose.nix
@@ -0,0 +1,87 @@
1{ config, pkgs, ... }:
2
3let
4 haskellEnv = pkgs.haskellPackages.ghcWithPackages (pkgs: with pkgs; [ filepath directory simpleAES bytestring base64-bytestring ]);
5 mlmmj-exposed = pkgs.stdenv.mkDerivation {
6 name = "mlmmj-exposed";
7 src = pkgs.writeScript "mlmmj-exposed" ''
8 #! ${haskellEnv}/bin/runghc
9
10 {-# LANGUAGE ViewPatterns #-}
11
12 import System.IO
13 import System.IO.Error
14 import System.FilePath
15 import System.Environment
16 import System.Exit
17 import System.Directory
18 import System.Process
19
20 import Data.Char
21
22 import Control.Monad
23
24 import Codec.Crypto.SimpleAES
25
26 import qualified Data.ByteString.Lazy as LBS
27 import qualified Data.ByteString.Lazy.Char8 as CLBS
28 import qualified Data.ByteString as BS
29
30 import qualified Data.ByteString.Base64 as Base64
31
32 main :: IO ()
33 main = do
34 progName <- takeFileName <$> getProgName
35 case progName of
36 "mlmmj-exposed" -> do
37 args <- getArgs
38 case args of
39 [listDir, (Base64.decodeLenient -> extension)] -> do
40 setCurrentDirectory listDir
41 key <- (BS.readFile "exposed.key") `catchIOError` (\e -> if isDoesNotExistError e then randomKey >>= (\k -> BS.writeFile "exposed.key" k >> return k) else ioError e)
42 let (((map toLower -> ident), (map toLower -> recipient)) :: (String, String)) = read . CLBS.unpack $ decryptMsg CBC key recipientExt
43 identities <- (read <$> readFile "exposed.ids") `catchIOError` (\e -> if isDoesNotExistError e then return [] else ioError e)
44 unless (ident `elem` identities) . die $ "Unknown sender: ‘" ++ ident ++ "’"
45 subscribers <- getSubscribers
46 unless (recipient `elem` subscribers) . dio $ "Unknown recipient: ‘" ++ recipient ++ "’"
47 getContents >>= writeFile "queue/exposed"
48 callProcess "${pkgs.mlmmj}/bin/mlmmj-send" ["-L", listDir, "-l", "6", "-m", "queue/exposed", "-T", recipient]
49 _ -> hPutStrLn stderr ("Called without expected arguments (<listDirectory> <recipientExtension>)") >> exitWith (ExitFailure 2)
50 "mlmmj-expose" -> do
51 args <- getArgs
52 case args of
53 [listDir, (map toLower -> ident)] -> do
54 setCurrentDirectory listDir
55 identities <- (read <$> readFile "exposed.ids") `catchIOError` (\e -> if isDoesNotExistError e then return [] else ioError e)
56 case ident `elem` identities of
57 True -> putStrLn "Identity is already known"
58 False -> writeFile "exosed.ids" . show $ ident : identities
59 _ -> hPutStrLn stderr ("Called without expected arguments (<listDirectory> <senderIdentity>)") >> exitWith (ExitFailure 2)
60 "mlmmj-get-exposed" -> do
61 args <- getArgs
62 case args of
63 [listDir, (map toLower -> ident), (map toLower -> recipient)] -> do
64 setCurrentDirectory listDir
65 key <- (BS.readFile "exposed.key") `catchIOError` (\e -> if isDoesNotExistError e then randomKey >>= (\k -> BS.writeFile "exposed.key" k >> return k) else ioError e)
66 identities <- (read <$> readFile "exposed.ids") `catchIOError` (\e -> if isDoesNotExistError e then return [] else ioError e)
67 unless (ident `elem` identities) . die $ "Unknown sender: ‘" ++ ident ++ "’"
68 subscribers <- getSubscribers
69 unless (recipient `elem` subscribers) . dio $ "Unknown recipient: ‘" ++ recipient ++ "’"
70 encryptMsg CBC key (CLBS.pack . show $ (ident, recipient)) >>= CLBS.putStrLn
71 _ -> hPutStrLn stderr ("Called without expected arguments (<listDirectory> <senderIdentity> <recipient>)") >> exitWith (ExitFailure 2)
72 _ -> hPutStrLn stderr ("Called under unsupported name ‘" ++ progName ++ "’") >> exitWith (ExitFailure 2)
73
74 getSubscribers :: IO [String]
75 getSubscribers = map (map toLower) . concat <$> mapM (flip catchIOError (\e -> if isDoesNotExistError e then return [] else ioError e) . readDir) ["subscribers.d", "digesters.d"]
76 where
77 readDir dir = concat <$> mapM (fmap lines . readFile) =<< (getDirectoryContents dir)
78 '';
79 buildCommand = ''
80 mkdir -p $out/bin
81 cp $src $out/bin/.mlmmj-exposed
82 ln -s $out/bin/mlmmj-exposed .mlmmj-exposed
83 '';
84 };
85in rec {
86 environment.systemPackages = [ mlmmj-exposed ];
87}