Skip to content

Commit 1a3b48c

Browse files
authored
Merge pull request #60 from Lassulus/simpler-modules
modules: simplify structure
2 parents 65d9c1c + 1d3c2a1 commit 1a3b48c

File tree

10 files changed

+464
-492
lines changed

10 files changed

+464
-492
lines changed

modules.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{ wlib, lib }:
22
lib.mapAttrs' (
3-
name: type: lib.nameValuePair name (import ./modules/${name}/module.nix { inherit wlib lib; })
3+
name: type: lib.nameValuePair name (wlib.wrapModule (import ./modules/${name}/module.nix))
44
) (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./modules))

modules/alacritty/module.nix

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1+
{ config, lib, ... }:
2+
let
3+
tomlFmt = config.pkgs.formats.toml { };
4+
in
15
{
2-
wlib,
3-
lib,
4-
...
5-
}:
6-
wlib.wrapModule (
7-
{ config, wlib, ... }:
8-
let
9-
tomlFmt = config.pkgs.formats.toml { };
10-
in
11-
{
12-
options = {
13-
settings = lib.mkOption {
14-
type = tomlFmt.type;
15-
default = { };
16-
description = ''
17-
Configuration of alacritty.
18-
See {manpage}`alacritty(5)` or <https://alacritty.org/config-alacritty.html>
19-
'';
20-
};
21-
extraFlags = lib.mkOption {
22-
type = lib.types.attrsOf lib.types.unspecified; # TODO add list handling
23-
default = { };
24-
description = "Extra flags to pass to alacritty.";
25-
};
6+
_class = "wrapper";
7+
options = {
8+
settings = lib.mkOption {
9+
type = tomlFmt.type;
10+
default = { };
11+
description = ''
12+
Configuration of alacritty.
13+
See {manpage}`alacritty(5)` or <https://alacritty.org/config-alacritty.html>
14+
'';
2615
};
27-
config.flags = {
28-
"--config-file" = tomlFmt.generate "alacritty.toml" config.settings;
29-
}
30-
// config.extraFlags;
31-
config.package = lib.mkDefault config.pkgs.alacritty;
32-
config.meta.maintainers = [ lib.maintainers.zimward ];
16+
extraFlags = lib.mkOption {
17+
type = lib.types.attrsOf lib.types.unspecified; # TODO add list handling
18+
default = { };
19+
description = "Extra flags to pass to alacritty.";
20+
};
21+
};
22+
config.flags = {
23+
"--config-file" = tomlFmt.generate "alacritty.toml" config.settings;
3324
}
34-
)
25+
// config.extraFlags;
26+
config.package = lib.mkDefault config.pkgs.alacritty;
27+
config.meta.maintainers = [ lib.maintainers.zimward ];
28+
}

modules/foot/module.nix

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
1+
{ config, lib, ... }:
2+
let
3+
iniFmt = config.pkgs.formats.ini { };
4+
in
15
{
2-
wlib,
3-
lib,
4-
}:
5-
wlib.wrapModule (
6-
{ config, wlib, ... }:
7-
let
8-
iniFmt = config.pkgs.formats.ini { };
9-
in
10-
{
11-
options = {
12-
settings = lib.mkOption {
13-
inherit (iniFmt) type;
14-
default = { };
15-
description = ''
16-
Configuration of foot terminal.
17-
See {manpage}`foot.ini(5)`
18-
'';
19-
};
20-
extraFlags = lib.mkOption {
21-
type = lib.types.attrsOf lib.types.unspecified; # TODO add list handling
22-
default = { };
23-
description = "Extra flags to pass to foot.";
24-
};
6+
_class = "wrapper";
7+
options = {
8+
settings = lib.mkOption {
9+
inherit (iniFmt) type;
10+
default = { };
11+
description = ''
12+
Configuration of foot terminal.
13+
See {manpage}`foot.ini(5)`
14+
'';
2515
};
26-
config.flags = {
27-
"--config" = iniFmt.generate "foot.ini" config.settings;
28-
}
29-
// config.extraFlags;
30-
config.package = lib.mkDefault config.pkgs.foot;
31-
config.meta.maintainers = [ lib.maintainers.randomdude ];
32-
config.meta.platforms = lib.platforms.linux;
16+
extraFlags = lib.mkOption {
17+
type = lib.types.attrsOf lib.types.unspecified; # TODO add list handling
18+
default = { };
19+
description = "Extra flags to pass to foot.";
20+
};
21+
};
22+
config.flags = {
23+
"--config" = iniFmt.generate "foot.ini" config.settings;
3324
}
34-
)
25+
// config.extraFlags;
26+
config.package = lib.mkDefault config.pkgs.foot;
27+
config.meta.maintainers = [ lib.maintainers.randomdude ];
28+
config.meta.platforms = lib.platforms.linux;
29+
}

modules/fuzzel/module.nix

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1+
{ config, lib, ... }:
2+
let
3+
iniFmt = config.pkgs.formats.ini { };
4+
in
15
{
2-
wlib,
3-
lib,
4-
...
5-
}:
6-
wlib.wrapModule (
7-
{ config, wlib, ... }:
8-
let
9-
iniFmt = config.pkgs.formats.ini { };
10-
in
11-
{
12-
options = {
13-
settings = lib.mkOption {
14-
type = iniFmt.type;
15-
default = { };
16-
description = ''
17-
Configuration of fuzzel.
18-
See {manpage}`fuzzel.ini(5)`
19-
'';
20-
};
21-
extraFlags = lib.mkOption {
22-
type = lib.types.attrsOf lib.types.unspecified; # TODO add list handling
23-
default = { };
24-
description = "Extra flags to pass to fuzzel.";
25-
};
6+
_class = "wrapper";
7+
options = {
8+
settings = lib.mkOption {
9+
type = iniFmt.type;
10+
default = { };
11+
description = ''
12+
Configuration of fuzzel.
13+
See {manpage}`fuzzel.ini(5)`
14+
'';
2615
};
27-
config.flagSeparator = "=";
28-
config.flags = {
29-
"--config" = iniFmt.generate "fuzzel.ini" config.settings;
30-
}
31-
// config.extraFlags;
32-
config.package = lib.mkDefault config.pkgs.fuzzel;
33-
config.meta.maintainers = [ lib.maintainers.zimward ];
34-
config.meta.platforms = lib.platforms.linux;
16+
extraFlags = lib.mkOption {
17+
type = lib.types.attrsOf lib.types.unspecified; # TODO add list handling
18+
default = { };
19+
description = "Extra flags to pass to fuzzel.";
20+
};
21+
};
22+
config.flagSeparator = "=";
23+
config.flags = {
24+
"--config" = iniFmt.generate "fuzzel.ini" config.settings;
3525
}
36-
)
26+
// config.extraFlags;
27+
config.package = lib.mkDefault config.pkgs.fuzzel;
28+
config.meta.maintainers = [ lib.maintainers.zimward ];
29+
config.meta.platforms = lib.platforms.linux;
30+
}

modules/helix/module.nix

Lines changed: 98 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,102 @@
1+
{ config, lib, ... }:
2+
let
3+
tomlFmt = config.pkgs.formats.toml { };
4+
conf =
5+
let
6+
base = tomlFmt.generate "helix-config" config.settings;
7+
in
8+
if config.extraSettings != "" then
9+
config.pkgs.concatText "helix-config" [
10+
base
11+
(config.pkgs.writeText "extraSettings" config.extraSettings)
12+
]
13+
else
14+
base;
15+
langs = tomlFmt.generate "helix-languages-config" config.languages;
16+
ignore = config.pkgs.writeText "helix-ignore" (lib.strings.concatLines config.ignores);
17+
themes = lib.mapAttrsToList (
18+
name: value:
19+
let
20+
fname = "helix-theme-${name}";
21+
in
22+
{
23+
name = "themes/${name}.toml";
24+
path =
25+
if lib.isString value then config.pkgs.writeText fname value else (tomlFmt.generate fname value);
26+
}
27+
) config.themes;
28+
in
129
{
2-
wlib,
3-
lib,
4-
...
5-
}:
6-
wlib.wrapModule (
7-
{ config, wlib, ... }:
8-
let
9-
tomlFmt = config.pkgs.formats.toml { };
10-
conf =
11-
let
12-
base = tomlFmt.generate "helix-config" config.settings;
13-
in
14-
if config.extraSettings != "" then
15-
config.pkgs.concatText "helix-config" [
16-
base
17-
(config.pkgs.writeText "extraSettings" config.extraSettings)
18-
]
19-
else
20-
base;
21-
langs = tomlFmt.generate "helix-languages-config" config.languages;
22-
ignore = config.pkgs.writeText "helix-ignore" (lib.strings.concatLines config.ignores);
23-
themes = lib.mapAttrsToList (
24-
name: value:
25-
let
26-
fname = "helix-theme-${name}";
27-
in
28-
{
29-
name = "themes/${name}.toml";
30-
path =
31-
if lib.isString value then config.pkgs.writeText fname value else (tomlFmt.generate fname value);
32-
}
33-
) config.themes;
34-
in
35-
{
36-
options = {
37-
settings = lib.mkOption {
38-
type = tomlFmt.type;
39-
description = ''
40-
General settings
41-
See <https://docs.helix-editor.com/configuration.html>
42-
'';
43-
default = { };
44-
};
45-
extraSettings = lib.mkOption {
46-
type = lib.types.lines;
47-
default = "";
48-
description = ''
49-
Extra lines appended to the config file.
50-
This can be used to maintain order for settings.
51-
'';
52-
};
53-
languages = lib.mkOption {
54-
type = tomlFmt.type;
55-
description = ''
56-
Language specific settings
57-
See <https://docs.helix-editor.com/languages.html>
58-
'';
59-
default = { };
60-
};
61-
themes = lib.mkOption {
62-
type = lib.types.attrsOf (
63-
lib.types.oneOf [
64-
tomlFmt.type
65-
lib.types.lines
66-
]
67-
);
68-
description = ''
69-
Themes to add to config.
70-
See <https://docs.helix-editor.com/themes.html>
71-
'';
72-
default = { };
73-
};
74-
ignores = lib.mkOption {
75-
type = lib.types.listOf lib.types.nonEmptyStr;
76-
default = [ ];
77-
description = ''
78-
List of paths to be ignored by the file-picker.
79-
The format is the same as in .gitignore.
80-
'';
81-
};
30+
_class = "wrapper";
31+
options = {
32+
settings = lib.mkOption {
33+
type = tomlFmt.type;
34+
description = ''
35+
General settings
36+
See <https://docs.helix-editor.com/configuration.html>
37+
'';
38+
default = { };
39+
};
40+
extraSettings = lib.mkOption {
41+
type = lib.types.lines;
42+
default = "";
43+
description = ''
44+
Extra lines appended to the config file.
45+
This can be used to maintain order for settings.
46+
'';
47+
};
48+
languages = lib.mkOption {
49+
type = tomlFmt.type;
50+
description = ''
51+
Language specific settings
52+
See <https://docs.helix-editor.com/languages.html>
53+
'';
54+
default = { };
8255
};
83-
config.package = lib.mkDefault config.pkgs.helix;
84-
config.env = {
85-
XDG_CONFIG_HOME = builtins.toString (
86-
config.pkgs.linkFarm "helix-merged-config" (
87-
map
88-
(a: {
89-
inherit (a) path;
90-
name = "helix/" + a.name;
91-
})
92-
(
93-
let
94-
entry = name: path: { inherit name path; };
95-
in
96-
[
97-
(entry "config.toml" conf)
98-
(entry "languages.toml" langs)
99-
(entry "ignore" ignore)
100-
]
101-
++ themes
102-
)
103-
)
56+
themes = lib.mkOption {
57+
type = lib.types.attrsOf (
58+
lib.types.oneOf [
59+
tomlFmt.type
60+
lib.types.lines
61+
]
10462
);
63+
description = ''
64+
Themes to add to config.
65+
See <https://docs.helix-editor.com/themes.html>
66+
'';
67+
default = { };
68+
};
69+
ignores = lib.mkOption {
70+
type = lib.types.listOf lib.types.nonEmptyStr;
71+
default = [ ];
72+
description = ''
73+
List of paths to be ignored by the file-picker.
74+
The format is the same as in .gitignore.
75+
'';
10576
};
106-
config.meta.maintainers = [ lib.maintainers.zimward ];
107-
}
108-
)
77+
};
78+
config.package = lib.mkDefault config.pkgs.helix;
79+
config.env = {
80+
XDG_CONFIG_HOME = builtins.toString (
81+
config.pkgs.linkFarm "helix-merged-config" (
82+
map
83+
(a: {
84+
inherit (a) path;
85+
name = "helix/" + a.name;
86+
})
87+
(
88+
let
89+
entry = name: path: { inherit name path; };
90+
in
91+
[
92+
(entry "config.toml" conf)
93+
(entry "languages.toml" langs)
94+
(entry "ignore" ignore)
95+
]
96+
++ themes
97+
)
98+
)
99+
);
100+
};
101+
config.meta.maintainers = [ lib.maintainers.zimward ];
102+
}

0 commit comments

Comments
 (0)