feat(users/Profpatsch/aerc): use toINI
Uses the list-based toINI, which removes a lot of the complications caused by the INI DSL (it was fun to write but really not necessary). Change-Id: Ia6c30a726662416c99ed74f9eb33537573543383 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5530 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
parent
0c51608f6c
commit
54684f6c34
2 changed files with 42 additions and 157 deletions
|
@ -1,60 +1,16 @@
|
||||||
let
|
let NameVal = λ(T : Type) → { name : Text, value : T }
|
||||||
-- DSL for building INI files
|
|
||||||
ToIniFns =
|
|
||||||
λ ( Ini
|
|
||||||
: { -- A Section in the ini
|
|
||||||
Section : Type
|
|
||||||
, -- A couple of sections
|
|
||||||
SectionList : Type
|
|
||||||
}
|
|
||||||
) →
|
|
||||||
{ -- Create a new section
|
|
||||||
newSection : Ini.Section
|
|
||||||
, -- Add a key/value pair to the section
|
|
||||||
add : Text → Text → Ini.Section → Ini.Section
|
|
||||||
, -- Add all these key/value pairs to the section
|
|
||||||
addAll :
|
|
||||||
List { name : Text, value : Text } → Ini.Section → Ini.Section
|
|
||||||
, -- Create a new SectionList
|
|
||||||
newSectionList : Ini.SectionList
|
|
||||||
, -- Add a section to the list of sections
|
|
||||||
addSection : Text → Ini.Section → Ini.SectionList → Ini.SectionList
|
|
||||||
}
|
|
||||||
|
|
||||||
in λ ( imports
|
in λ ( imports
|
||||||
: { -- concatenate a list with newlines
|
: { -- Take an aerc filter from the aerc distribution /share directory
|
||||||
concatNewline : List Text → Text
|
|
||||||
, -- 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
|
, -- given a dsl of functions to create an Ini, render the ini file
|
||||||
toIni :
|
toIni :
|
||||||
( ∀(Ini : { Section : Type, SectionList : Type }) →
|
{ globalSection : List (NameVal Text)
|
||||||
ToIniFns Ini →
|
, sections : List (NameVal (List (NameVal Text)))
|
||||||
{ globalSection : Ini.Section, sections : Ini.SectionList }
|
} →
|
||||||
) →
|
|
||||||
Text
|
Text
|
||||||
}
|
}
|
||||||
) →
|
) →
|
||||||
let List/foldLeft
|
|
||||||
: ∀(a : Type) →
|
|
||||||
List a →
|
|
||||||
∀(list : Type) →
|
|
||||||
∀(cons : list → a → list) →
|
|
||||||
∀(nil : list) →
|
|
||||||
list
|
|
||||||
= λ(a : Type) →
|
|
||||||
λ(xs : List a) →
|
|
||||||
λ(list : Type) →
|
|
||||||
λ(cons : list → a → list) →
|
|
||||||
λ(nil : list) →
|
|
||||||
List/fold
|
|
||||||
a
|
|
||||||
xs
|
|
||||||
(list → list)
|
|
||||||
(λ(x : a) → λ(f : list → list) → λ(l : list) → f (cons l x))
|
|
||||||
(λ(l : list) → l)
|
|
||||||
nil
|
|
||||||
|
|
||||||
let List/map
|
let List/map
|
||||||
: ∀(a : Type) → ∀(b : Type) → (a → b) → List a → List b
|
: ∀(a : Type) → ∀(b : Type) → (a → b) → List a → List b
|
||||||
= λ(a : Type) →
|
= λ(a : Type) →
|
||||||
|
@ -68,67 +24,42 @@ in λ ( imports
|
||||||
List/fold a xs list (λ(x : a) → cons (f x))
|
List/fold a xs list (λ(x : a) → cons (f x))
|
||||||
)
|
)
|
||||||
|
|
||||||
let
|
|
||||||
-- A builder is a list of “build methods” that go from (a -> a) and change the a step by step.
|
|
||||||
Builder/build =
|
|
||||||
λ(a : Type) →
|
|
||||||
λ(init : a) →
|
|
||||||
λ(builders : List (a → a)) →
|
|
||||||
List/foldLeft
|
|
||||||
(a → a)
|
|
||||||
builders
|
|
||||||
a
|
|
||||||
(λ(acc : a) → λ(f : a → a) → f acc)
|
|
||||||
init
|
|
||||||
|
|
||||||
in { accounts =
|
in { accounts =
|
||||||
imports.toIni
|
imports.toIni
|
||||||
( λ(Ini : { Section : Type, SectionList : Type }) →
|
{ globalSection = [] : List (NameVal Text)
|
||||||
λ(ini : ToIniFns Ini) →
|
, sections =
|
||||||
{ globalSection = ini.newSection
|
[ { name = "mail"
|
||||||
, sections =
|
, value =
|
||||||
ini.addSection
|
[ { name = "archive", value = "Archive" }
|
||||||
"mail"
|
, { name = "copy-to", value = "Sent" }
|
||||||
( ini.addAll
|
, { name = "default", value = "INBOX" }
|
||||||
[ { name = "archive", value = "Archive" }
|
, { name = "from"
|
||||||
, { name = "copy-to", value = "Sent" }
|
, value = "Profpatsch <mail@profpatsch.de>"
|
||||||
, { name = "default", value = "INBOX" }
|
}
|
||||||
, { name = "from"
|
, { name = "source", value = "maildir://~/.Mail/mail" }
|
||||||
, value = "Profpatsch <mail@profpatsch.de>"
|
, { name = "postpone", value = "Drafts" }
|
||||||
}
|
]
|
||||||
, { name = "source"
|
|
||||||
, value = "maildir://~/.Mail/mail"
|
|
||||||
}
|
|
||||||
, { name = "postpone", value = "Drafts" }
|
|
||||||
]
|
|
||||||
ini.newSection
|
|
||||||
)
|
|
||||||
ini.newSectionList
|
|
||||||
}
|
}
|
||||||
)
|
]
|
||||||
|
}
|
||||||
, aerc =
|
, aerc =
|
||||||
imports.toIni
|
imports.toIni
|
||||||
( λ(Ini : { Section : Type, SectionList : Type }) →
|
{ globalSection = [] : List (NameVal Text)
|
||||||
λ(ini : ToIniFns Ini) →
|
, sections =
|
||||||
{ globalSection = ini.newSection
|
[ { name = "filters"
|
||||||
, sections =
|
, value =
|
||||||
ini.addSection
|
[ { name = "text/html"
|
||||||
"filters"
|
, value = imports.aercFilter "html"
|
||||||
( Builder/build
|
}
|
||||||
Ini.Section
|
, let _ = "-- TODO: this awk should be taken from nix!"
|
||||||
ini.newSection
|
|
||||||
[ ini.add "text/html" (imports.aercFilter "html")
|
|
||||||
, let _ =
|
|
||||||
"-- TODO: this awk should be taken from nix!"
|
|
||||||
|
|
||||||
in ini.add
|
in { name = "text/*"
|
||||||
"text/*"
|
, value = "awk -f ${imports.aercFilter "plaintext"}"
|
||||||
"awk -f ${imports.aercFilter "plaintext"}"
|
}
|
||||||
]
|
]
|
||||||
)
|
|
||||||
ini.newSectionList
|
|
||||||
}
|
}
|
||||||
)
|
]
|
||||||
|
}
|
||||||
, binds =
|
, binds =
|
||||||
let
|
let
|
||||||
-- keybinding and command to run
|
-- keybinding and command to run
|
||||||
|
@ -140,21 +71,22 @@ in λ ( imports
|
||||||
renderKey =
|
renderKey =
|
||||||
λ(k : Key) →
|
λ(k : Key) →
|
||||||
if k.ctrl
|
if k.ctrl
|
||||||
then "<C-${k.key}> = ${k.cmd}"
|
then { name = "<C-${k.key}>", value = k.cmd }
|
||||||
else "${k.key} = ${k.cmd}"
|
else { name = k.key, value = k.cmd }
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
-- render a list of keys to config format
|
-- render a list of keys to config format
|
||||||
renderKeys =
|
renderKeys =
|
||||||
λ(keys : List Key) → List/map Key Text renderKey keys
|
λ(keys : List Key) →
|
||||||
|
List/map Key (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
|
||||||
sect =
|
sect =
|
||||||
λ(section : Text) →
|
λ(section : Text) →
|
||||||
λ(keys : List Key) →
|
λ(keys : List Key) →
|
||||||
{ section, keys = renderKeys keys }
|
{ name = section, value = renderKeys keys }
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
@ -221,33 +153,5 @@ in λ ( imports
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
let Section = { section : Text, keys : List Text }
|
in imports.toIni config
|
||||||
|
|
||||||
let iniToJson =
|
|
||||||
λ ( ini
|
|
||||||
: { globalSection : List Text
|
|
||||||
, sections : List Section
|
|
||||||
}
|
|
||||||
) →
|
|
||||||
let mkKeys = imports.concatNewline
|
|
||||||
|
|
||||||
let
|
|
||||||
-- TODO: escaping section header?
|
|
||||||
mkSection =
|
|
||||||
λ(section : Section) →
|
|
||||||
''
|
|
||||||
[${section.section}]
|
|
||||||
''
|
|
||||||
++ mkKeys section.keys
|
|
||||||
|
|
||||||
in mkKeys ini.globalSection
|
|
||||||
++ mkKeys
|
|
||||||
( List/map
|
|
||||||
Section
|
|
||||||
Text
|
|
||||||
mkSection
|
|
||||||
ini.sections
|
|
||||||
)
|
|
||||||
|
|
||||||
in iniToJson config
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,29 +20,10 @@ let
|
||||||
deps = [ ];
|
deps = [ ];
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
concatNewline = lib.concatStringsSep "\n";
|
|
||||||
aercFilter = name: "${aerc-patched}/share/aerc/filters/${name}";
|
aercFilter = name: "${aerc-patched}/share/aerc/filters/${name}";
|
||||||
toIni = getSections:
|
toIni = depot.users.Profpatsch.toINI { };
|
||||||
lib.generators.toINIWithGlobalSection { }
|
|
||||||
(getSections { } toIniDhall);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
toIniDhall = {
|
|
||||||
newSection = { };
|
|
||||||
add = key: val: sect: sect // { ${key} = val; };
|
|
||||||
addAll = keyVals: sect: sect // builtins.listToAttrs keyVals;
|
|
||||||
newSectionList = { };
|
|
||||||
addSection = key: val: sect: sect // { ${key} = val; };
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
ini-file = name: ini: lib.pipe ini [
|
|
||||||
(lib.generators.toINI { })
|
|
||||||
(pkgs.writeText name)
|
|
||||||
];
|
|
||||||
|
|
||||||
binds-file = name: binds: pkgs.writeText name binds;
|
|
||||||
|
|
||||||
aerc-config = pkgs.linkFarm "alacritty-config" [
|
aerc-config = pkgs.linkFarm "alacritty-config" [
|
||||||
{
|
{
|
||||||
name = "aerc/accounts.conf";
|
name = "aerc/accounts.conf";
|
||||||
|
@ -54,7 +35,7 @@ let
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "aerc/binds.conf";
|
name = "aerc/binds.conf";
|
||||||
path = binds-file "binds.conf" config.binds;
|
path = pkgs.writeText "binds.conf" config.binds;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue