refactor(users/Profpatsch/aerc): move ini stuff out
First shot at generating a dhall FFI standard. Change-Id: I1cdf7eeaa6b2668a49282315f308a8e51abd0cf6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5887 Reviewed-by: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
2cf67e113e
commit
3c3713c69f
5 changed files with 246 additions and 135 deletions
|
@ -1,41 +1,25 @@
|
||||||
let NameVal = λ(T : Type) → { name : Text, value : T }
|
let Lib = ./dhall/lib.dhall
|
||||||
|
|
||||||
|
let List/map = Lib.List/map
|
||||||
|
|
||||||
|
let Ini = ./ini/ini.dhall
|
||||||
|
|
||||||
in λ ( imports
|
in λ ( imports
|
||||||
: { -- Take an aerc filter from the aerc distribution /share directory
|
: { -- Take an aerc filter from the aerc distribution /share directory
|
||||||
aercFilter : Text → Text
|
aercFilter : Text → Text
|
||||||
, -- given a dsl of functions to create an Ini, render the ini file
|
, Ini/externs : Ini.Externs
|
||||||
toIni :
|
|
||||||
{ globalSection : List (NameVal Text)
|
|
||||||
, sections : List (NameVal (List (NameVal Text)))
|
|
||||||
} →
|
|
||||||
Text
|
|
||||||
}
|
}
|
||||||
) →
|
) →
|
||||||
let List/map
|
{ accounts =
|
||||||
: ∀(a : Type) → ∀(b : Type) → (a → b) → List a → List b
|
imports.Ini/externs.renderIni
|
||||||
= λ(a : Type) →
|
{ globalSection = [] : Ini.Section
|
||||||
λ(b : Type) →
|
|
||||||
λ(f : a → b) →
|
|
||||||
λ(xs : List a) →
|
|
||||||
List/build
|
|
||||||
b
|
|
||||||
( λ(list : Type) →
|
|
||||||
λ(cons : b → list → list) →
|
|
||||||
List/fold a xs list (λ(x : a) → cons (f x))
|
|
||||||
)
|
|
||||||
|
|
||||||
in { accounts =
|
|
||||||
imports.toIni
|
|
||||||
{ globalSection = [] : List (NameVal Text)
|
|
||||||
, sections =
|
, sections =
|
||||||
[ { name = "mail"
|
[ { name = "mail"
|
||||||
, value =
|
, value =
|
||||||
[ { name = "archive", value = "Archive" }
|
[ { name = "archive", value = "Archive" }
|
||||||
, { name = "copy-to", value = "Sent" }
|
, { name = "copy-to", value = "Sent" }
|
||||||
, { name = "default", value = "INBOX" }
|
, { name = "default", value = "INBOX" }
|
||||||
, { name = "from"
|
, { name = "from", value = "Profpatsch <mail@profpatsch.de>" }
|
||||||
, value = "Profpatsch <mail@profpatsch.de>"
|
|
||||||
}
|
|
||||||
, { name = "source", value = "maildir://~/.Mail/mail" }
|
, { name = "source", value = "maildir://~/.Mail/mail" }
|
||||||
, { name = "postpone", value = "Drafts" }
|
, { name = "postpone", value = "Drafts" }
|
||||||
]
|
]
|
||||||
|
@ -43,14 +27,12 @@ in λ ( imports
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
, aerc =
|
, aerc =
|
||||||
imports.toIni
|
imports.Ini/externs.renderIni
|
||||||
{ globalSection = [] : List (NameVal Text)
|
{ globalSection = [] : Ini.Section
|
||||||
, sections =
|
, sections =
|
||||||
[ { name = "filters"
|
[ { name = "filters"
|
||||||
, value =
|
, value =
|
||||||
[ { name = "text/html"
|
[ { name = "text/html", value = imports.aercFilter "html" }
|
||||||
, value = imports.aercFilter "html"
|
|
||||||
}
|
|
||||||
, let _ = "-- TODO: this awk should be taken from nix!"
|
, let _ = "-- TODO: this awk should be taken from nix!"
|
||||||
|
|
||||||
in { name = "text/*"
|
in { name = "text/*"
|
||||||
|
@ -79,7 +61,7 @@ in λ ( imports
|
||||||
-- render a list of keys to config format
|
-- render a list of keys to config format
|
||||||
renderKeys =
|
renderKeys =
|
||||||
λ(keys : List Key) →
|
λ(keys : List Key) →
|
||||||
List/map Key (NameVal Text) renderKey keys
|
List/map Key (Ini.NameVal Text) renderKey keys
|
||||||
|
|
||||||
let
|
let
|
||||||
-- create a section whith a name and a list of keys
|
-- create a section whith a name and a list of keys
|
||||||
|
@ -153,5 +135,5 @@ in λ ( imports
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
in imports.toIni config
|
in imports.Ini/externs.renderIni config
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,16 @@ let
|
||||||
root = ./.;
|
root = ./.;
|
||||||
files = [
|
files = [
|
||||||
"aerc.dhall"
|
"aerc.dhall"
|
||||||
|
"dhall/lib.dhall"
|
||||||
|
"ini/ini.dhall"
|
||||||
];
|
];
|
||||||
main = "aerc.dhall";
|
main = "aerc.dhall";
|
||||||
deps = [ ];
|
deps = [
|
||||||
|
];
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
aercFilter = name: "${aerc-patched}/share/aerc/filters/${name}";
|
aercFilter = name: "${aerc-patched}/share/aerc/filters/${name}";
|
||||||
toIni = depot.users.Profpatsch.toINI { };
|
"Ini/externs" = depot.users.Profpatsch.ini.externs;
|
||||||
};
|
};
|
||||||
|
|
||||||
aerc-config = pkgs.linkFarm "alacritty-config" [
|
aerc-config = pkgs.linkFarm "alacritty-config" [
|
||||||
|
|
84
users/Profpatsch/dhall/lib.dhall
Normal file
84
users/Profpatsch/dhall/lib.dhall
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
let List/map
|
||||||
|
: ∀(a : Type) → ∀(b : Type) → (a → b) → List a → List b
|
||||||
|
= λ(a : Type) →
|
||||||
|
λ(b : Type) →
|
||||||
|
λ(f : a → b) →
|
||||||
|
λ(xs : List a) →
|
||||||
|
List/build
|
||||||
|
b
|
||||||
|
( λ(list : Type) →
|
||||||
|
λ(cons : b → list → list) →
|
||||||
|
List/fold a xs list (λ(x : a) → cons (f x))
|
||||||
|
)
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
--| Concatenate a `List` of `List`s into a single `List`
|
||||||
|
List/concat
|
||||||
|
: ∀(a : Type) → List (List a) → List a
|
||||||
|
= λ(a : Type) →
|
||||||
|
λ(xss : List (List a)) →
|
||||||
|
List/build
|
||||||
|
a
|
||||||
|
( λ(list : Type) →
|
||||||
|
λ(cons : a → list → list) →
|
||||||
|
λ(nil : list) →
|
||||||
|
List/fold
|
||||||
|
(List a)
|
||||||
|
xss
|
||||||
|
list
|
||||||
|
(λ(xs : List a) → λ(ys : list) → List/fold a xs list cons ys)
|
||||||
|
nil
|
||||||
|
)
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
|
||||||
|
-- Transform a list by applying a function to each element and flattening the results
|
||||||
|
List/concatMap
|
||||||
|
: ∀(a : Type) → ∀(b : Type) → (a → List b) → List a → List b
|
||||||
|
= λ(a : Type) →
|
||||||
|
λ(b : Type) →
|
||||||
|
λ(f : a → List b) →
|
||||||
|
λ(xs : List a) →
|
||||||
|
List/build
|
||||||
|
b
|
||||||
|
( λ(list : Type) →
|
||||||
|
λ(cons : b → list → list) →
|
||||||
|
List/fold a xs list (λ(x : a) → List/fold b (f x) list cons)
|
||||||
|
)
|
||||||
|
|
||||||
|
let Status = < Empty | NonEmpty : Text >
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
{-|
|
||||||
|
Transform each value in a `List` to `Text` and then concatenate them with a
|
||||||
|
separator in between each value
|
||||||
|
-}
|
||||||
|
Text/concatMapSep
|
||||||
|
: ∀(separator : Text) → ∀(a : Type) → (a → Text) → List a → Text
|
||||||
|
= λ(separator : Text) →
|
||||||
|
λ(a : Type) →
|
||||||
|
λ(f : a → Text) →
|
||||||
|
λ(elements : List a) →
|
||||||
|
let status =
|
||||||
|
List/fold
|
||||||
|
a
|
||||||
|
elements
|
||||||
|
Status
|
||||||
|
( λ(x : a) →
|
||||||
|
λ(status : Status) →
|
||||||
|
merge
|
||||||
|
{ Empty = Status.NonEmpty (f x)
|
||||||
|
, NonEmpty =
|
||||||
|
λ(result : Text) →
|
||||||
|
Status.NonEmpty (f x ++ separator ++ result)
|
||||||
|
}
|
||||||
|
status
|
||||||
|
)
|
||||||
|
Status.Empty
|
||||||
|
|
||||||
|
in merge { Empty = "", NonEmpty = λ(result : Text) → result } status
|
||||||
|
|
||||||
|
in { List/map, List/concat, List/concatMap, Text/concatMapSep }
|
6
users/Profpatsch/ini/default.nix
Normal file
6
users/Profpatsch/ini/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{ depot, ... }:
|
||||||
|
{
|
||||||
|
externs = {
|
||||||
|
renderIni = depot.users.Profpatsch.toINI { };
|
||||||
|
};
|
||||||
|
}
|
36
users/Profpatsch/ini/ini.dhall
Normal file
36
users/Profpatsch/ini/ini.dhall
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
let lib = ../dhall/lib.dhall
|
||||||
|
|
||||||
|
let NameVal = λ(T : Type) → { name : Text, value : T }
|
||||||
|
|
||||||
|
let ValueList = λ(T : Type) → List (NameVal T)
|
||||||
|
|
||||||
|
let Section = ValueList Text
|
||||||
|
|
||||||
|
let Sections = ValueList Section
|
||||||
|
|
||||||
|
let Ini = { globalSection : Section, sections : Sections }
|
||||||
|
|
||||||
|
let
|
||||||
|
-- Takes to INI files and merges their global sections and their section lists,
|
||||||
|
-- without duplicating by section name.
|
||||||
|
appendInis =
|
||||||
|
λ(inis : List Ini) →
|
||||||
|
{ globalSection =
|
||||||
|
lib.List/concat
|
||||||
|
(NameVal Text)
|
||||||
|
(lib.List/map Ini Section (λ(i : Ini) → i.globalSection) inis)
|
||||||
|
, sections =
|
||||||
|
lib.List/concat
|
||||||
|
(NameVal Section)
|
||||||
|
(lib.List/map Ini Sections (λ(i : Ini) → i.sections) inis)
|
||||||
|
}
|
||||||
|
: Ini
|
||||||
|
|
||||||
|
let
|
||||||
|
-- Signatures of functions that are input via FFI.
|
||||||
|
Externs =
|
||||||
|
{ -- given a dsl of functions to create an Ini, render the ini file
|
||||||
|
renderIni : Ini → Text
|
||||||
|
}
|
||||||
|
|
||||||
|
in { NameVal, ValueList, Section, Sections, Ini, appendInis, Externs }
|
Loading…
Reference in a new issue