Skip to content

Commit bf3f364

Browse files
authored
Merge pull request #77 from ryan4yin/use-optionals
refactor: use lib.optionals instead of if...then...else
2 parents 54c2240 + 3247e4a commit bf3f364

File tree

5 files changed

+126
-133
lines changed

5 files changed

+126
-133
lines changed

home/base/desktop/cloud/default.nix

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
{pkgs, ...}: {
1+
{
2+
lib,
3+
pkgs,
4+
...
5+
}: {
26
home.packages = with pkgs;
37
[
48
# general tools
@@ -26,12 +30,10 @@
2630
aliyun-cli
2731
]
2832
++ (
29-
if pkgs.stdenv.isLinux
30-
then [
33+
lib.optionals pkgs.stdenv.isLinux [
3134
# cloud tools that nix do not have cache for.
3235
terraform
3336
terraformer # generate terraform configs from existing cloud resources
3437
]
35-
else []
3638
);
3739
}

home/base/desktop/dev-tools.nix

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
exercism
4242
]
4343
++ (
44-
if pkgs.stdenv.isLinux
45-
then [
44+
lib.optionals pkgs.stdenv.isLinux [
4645
# Automatically trims your branches whose tracking remote refs are merged or gone
4746
# It's really useful when you work on a project for a long time.
4847
git-trim
@@ -57,7 +56,6 @@
5756
wireshark # network analyzer
5857
ventoy # create bootable usb
5958
]
60-
else []
6159
);
6260

6361
programs = {

home/base/desktop/editors/packages.nix

+1-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@
129129
(ripgrep.override {withPCRE2 = true;}) # recursively searches directories for a regex pattern
130130
]
131131
++ (
132-
if pkgs.stdenv.isDarwin
133-
then []
134-
else [
132+
lib.optionals pkgs.stdenv.isLinux [
135133
#-- verilog / systemverilog
136134
verible
137135
gdb

home/base/desktop/terminal/wezterm.nix

+72-77
Original file line numberDiff line numberDiff line change
@@ -18,93 +18,88 @@
1818
# we can add wezterm as a flake input once this PR is merged:
1919
# https://github.com/wez/wezterm/pull/3547
2020

21-
programs.wezterm =
22-
{
23-
enable = false; # disable
21+
programs.wezterm = {
22+
enable = true; # disable
2423

25-
# TODO: Fix: https://github.com/wez/wezterm/issues/4483
26-
# package = pkgs.wezterm.override { };
24+
# install wezterm via homebrew on macOS to avoid compilation, dummy package here.
25+
package =
26+
if pkgs.stdenv.isLinux
27+
then pkgs.wezterm
28+
else pkgs.hello;
2729

28-
extraConfig = let
29-
fontsize =
30-
if pkgs.stdenv.isDarwin
31-
then "14.0"
32-
else "13.0";
33-
in ''
34-
-- Pull in the wezterm API
35-
local wezterm = require 'wezterm'
30+
enableBashIntegration = pkgs.stdenv.isLinux;
31+
enableZshIntegration = pkgs.stdenv.isLinux;
3632

37-
-- This table will hold the configuration.
38-
local config = {}
33+
extraConfig = let
34+
fontsize =
35+
if pkgs.stdenv.isLinux
36+
then "13.0"
37+
else "14.0";
38+
in ''
39+
-- Pull in the wezterm API
40+
local wezterm = require 'wezterm'
3941
40-
-- In newer versions of wezterm, use the config_builder which will
41-
-- help provide clearer error messages
42-
if wezterm.config_builder then
43-
config = wezterm.config_builder()
44-
end
45-
46-
wezterm.on('toggle-opacity', function(window, pane)
47-
local overrides = window:get_config_overrides() or {}
48-
if not overrides.window_background_opacity then
49-
overrides.window_background_opacity = 0.93
50-
else
51-
overrides.window_background_opacity = nil
52-
end
53-
window:set_config_overrides(overrides)
54-
end)
42+
-- This table will hold the configuration.
43+
local config = {}
5544
56-
wezterm.on('toggle-maximize', function(window, pane)
57-
window:maximize()
58-
end)
45+
-- In newer versions of wezterm, use the config_builder which will
46+
-- help provide clearer error messages
47+
if wezterm.config_builder then
48+
config = wezterm.config_builder()
49+
end
5950
60-
-- This is where you actually apply your config choices
61-
config.color_scheme = "Catppuccin Mocha"
62-
config.font = wezterm.font_with_fallback {
63-
"JetBrainsMono Nerd Font",
64-
"FiraCode Nerd Font",
51+
wezterm.on('toggle-opacity', function(window, pane)
52+
local overrides = window:get_config_overrides() or {}
53+
if not overrides.window_background_opacity then
54+
overrides.window_background_opacity = 0.93
55+
else
56+
overrides.window_background_opacity = nil
57+
end
58+
window:set_config_overrides(overrides)
59+
end)
6560
66-
-- To avoid 'Chinese characters displayed as variant (Japanese) glyphs'
67-
"Source Han Sans SC",
68-
"Source Han Sans TC"
69-
}
61+
wezterm.on('toggle-maximize', function(window, pane)
62+
window:maximize()
63+
end)
7064
71-
config.hide_tab_bar_if_only_one_tab = true
72-
config.scrollback_lines = 10000
73-
config.enable_scroll_bar = true
74-
config.term = 'wezterm'
65+
-- This is where you actually apply your config choices
66+
config.color_scheme = "Catppuccin Mocha"
67+
config.font = wezterm.font_with_fallback {
68+
"JetBrainsMono Nerd Font",
69+
"FiraCode Nerd Font",
7570
76-
config.keys = {
77-
-- toggle opacity(CTRL + SHIFT + B)
78-
{
79-
key = 'B',
80-
mods = 'CTRL',
81-
action = wezterm.action.EmitEvent 'toggle-opacity',
82-
},
83-
{
84-
key = 'M',
85-
mods = 'CTRL',
86-
action = wezterm.action.EmitEvent 'toggle-maximize',
87-
},
88-
}
89-
config.font_size = ${fontsize}
71+
-- To avoid 'Chinese characters displayed as variant (Japanese) glyphs'
72+
"Source Han Sans SC",
73+
"Source Han Sans TC"
74+
}
9075
91-
-- To resolve issues:
92-
-- 1. https://github.com/ryan4yin/nix-config/issues/26
93-
-- 2. https://github.com/ryan4yin/nix-config/issues/8
94-
-- Spawn a nushell in login mode via `bash`
95-
config.default_prog = { '${pkgs.bash}/bin/bash', '--login', '-c', 'nu --login --interactive' }
76+
config.hide_tab_bar_if_only_one_tab = true
77+
config.scrollback_lines = 10000
78+
config.enable_scroll_bar = true
79+
config.term = 'wezterm'
9680
97-
return config
98-
'';
99-
}
100-
// (
101-
if pkgs.stdenv.isDarwin
102-
then {
103-
# install wezterm via homebrew on macOS to avoid compilation, dummy package here.
104-
# package = pkgs.hello;
105-
enableBashIntegration = false;
106-
enableZshIntegration = false;
81+
config.keys = {
82+
-- toggle opacity(CTRL + SHIFT + B)
83+
{
84+
key = 'B',
85+
mods = 'CTRL',
86+
action = wezterm.action.EmitEvent 'toggle-opacity',
87+
},
88+
{
89+
key = 'M',
90+
mods = 'CTRL',
91+
action = wezterm.action.EmitEvent 'toggle-maximize',
92+
},
10793
}
108-
else {}
109-
);
94+
config.font_size = ${fontsize}
95+
96+
-- To resolve issues:
97+
-- 1. https://github.com/ryan4yin/nix-config/issues/26
98+
-- 2. https://github.com/ryan4yin/nix-config/issues/8
99+
-- Spawn a nushell in login mode via `bash`
100+
config.default_prog = { '${pkgs.bash}/bin/bash', '--login', '-c', 'nu --login --interactive' }
101+
102+
return config
103+
'';
104+
};
110105
}

home/base/server/core.nix

+46-46
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,59 @@
44
nur-ryan4yin,
55
...
66
}: {
7-
home.packages = with pkgs; [
8-
# Misc
9-
tldr
10-
cowsay
11-
gnupg
12-
gnumake
7+
home.packages = with pkgs;
8+
[
9+
# Misc
10+
tldr
11+
cowsay
12+
gnupg
13+
gnumake
1314

14-
# Morden cli tools, replacement of grep/sed/...
15+
# Morden cli tools, replacement of grep/sed/...
1516

16-
# Interactively filter its input using fuzzy searching, not limit to filenames.
17-
fzf
18-
# search for files by name, faster than find
19-
fd
20-
# search for files by its content, replacement of grep
21-
(ripgrep.override {withPCRE2 = true;})
17+
# Interactively filter its input using fuzzy searching, not limit to filenames.
18+
fzf
19+
# search for files by name, faster than find
20+
fd
21+
# search for files by its content, replacement of grep
22+
(ripgrep.override {withPCRE2 = true;})
2223

23-
# A fast and polyglot tool for code searching, linting, rewriting at large scale
24-
# supported languages: only some mainstream languages currently(do not support nix/nginx/yaml/toml/...)
25-
ast-grep
24+
# A fast and polyglot tool for code searching, linting, rewriting at large scale
25+
# supported languages: only some mainstream languages currently(do not support nix/nginx/yaml/toml/...)
26+
ast-grep
2627

27-
sad # CLI search and replace, just like sed, but with diff preview.
28-
yq-go # yaml processer https://github.com/mikefarah/yq
29-
just # a command runner like make, but simpler
30-
delta # A viewer for git and diff output
31-
lazygit # Git terminal UI.
32-
hyperfine # command-line benchmarking tool
33-
gping # ping, but with a graph(TUI)
34-
doggo # DNS client for humans
35-
duf # Disk Usage/Free Utility - a better 'df' alternative
36-
du-dust # A more intuitive version of `du` in rust
37-
ncdu # analyzer your disk usage Interactively, via TUI(replacement of `du`)
38-
gdu # disk usage analyzer(replacement of `du`)
28+
sad # CLI search and replace, just like sed, but with diff preview.
29+
yq-go # yaml processer https://github.com/mikefarah/yq
30+
just # a command runner like make, but simpler
31+
delta # A viewer for git and diff output
32+
lazygit # Git terminal UI.
33+
hyperfine # command-line benchmarking tool
34+
gping # ping, but with a graph(TUI)
35+
doggo # DNS client for humans
36+
duf # Disk Usage/Free Utility - a better 'df' alternative
37+
du-dust # A more intuitive version of `du` in rust
38+
ncdu # analyzer your disk usage Interactively, via TUI(replacement of `du`)
39+
gdu # disk usage analyzer(replacement of `du`)
3940

40-
# nix related
41-
#
42-
# it provides the command `nom` works just like `nix
43-
# with more details log output
44-
nix-output-monitor
45-
hydra-check # check hydra(nix's build farm) for the build status of a package
46-
nix-index # A small utility to index nix store paths
47-
nix-init # generate nix derivation from url
48-
# https://github.com/nix-community/nix-melt
49-
nix-melt # A TUI flake.lock viewer
50-
# https://github.com/utdemir/nix-tree
51-
nix-tree # A TUI to visualize the dependency graph of a nix derivation
52-
53-
# productivity
54-
caddy # A webserver with automatic HTTPS via Let's Encrypt(replacement of nginx)
55-
croc # File transfer between computers securely and easily
41+
# nix related
42+
#
43+
# it provides the command `nom` works just like `nix
44+
# with more details log output
45+
nix-output-monitor
46+
hydra-check # check hydra(nix's build farm) for the build status of a package
47+
nix-index # A small utility to index nix store paths
48+
nix-init # generate nix derivation from url
49+
# https://github.com/nix-community/nix-melt
50+
nix-melt # A TUI flake.lock viewer
51+
# https://github.com/utdemir/nix-tree
52+
nix-tree # A TUI to visualize the dependency graph of a nix derivation
5653

54+
# productivity
55+
caddy # A webserver with automatic HTTPS via Let's Encrypt(replacement of nginx)
56+
croc # File transfer between computers securely and easily
57+
]
5758
# self-hosted nix cache server
58-
attic.packages.${pkgs.system}.attic-client
59-
];
59+
++ lib.optionals pkgs.stdenv.isLinux [attic.packages.${pkgs.system}.attic-client];
6060

6161
programs = {
6262
# A modern replacement for ‘ls’

0 commit comments

Comments
 (0)