refac(nix): organize nix config with modules

This commit is contained in:
Dmitriy Pleshevskiy 2022-04-27 01:17:51 +03:00
parent 46d9a0c039
commit 0176ec8edc
11 changed files with 381 additions and 163 deletions

3
.gitignore vendored
View File

@ -4,6 +4,9 @@
!/nix
/nix/*
!/nix/wm
!/nix/shell
!/nix/progs
!/nix/home.nix
!/nix/*.example.nix

View File

@ -4,16 +4,15 @@ let
secrets = import ./secrets.nix;
in
{
nixpkgs.overlays = [
(self: super: {
haskellPackages = super.haskellPackages.override {
overrides = hself: hsuper: {
xmonad = hsuper.xmonad_0_17_0;
xmonad-contrib = hsuper.xmonad-contrib_0_17_0;
xmonad-extras = hsuper.xmonad-extras_0_17_0;
};
};
})
imports = [
./wm/xmonad.nix
./shell/zsh.nix
./progs/git.nix
./progs/pass.nix
./progs/himalaya.nix
./progs/nvim.nix
./progs/exa.nix
./progs/zoxide.nix
];
targets.genericLinux.enable = true;
@ -30,27 +29,13 @@ in
options = ["grp:win_space_toggle"];
};
# This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage
# when a new Home Manager release introduces backwards
# incompatible changes.
#
# You can update Home Manager without changing this value. See
# the Home Manager release notes for a list of state version
# changes in each release.
home.stateVersion = "21.11";
home.packages = with pkgs; [
# system
xclip # access x clipboard from a console
dmenu # menu for x window system
flameshot # powerful yet simple to use screenshot software
# TODO: move packages to separate modules
# tools
xh # friendly and fast tool for sending HTTP requests
fd # a simple, fast and user-friendly alternative to find
bat # a cat clone with syntax highlighting and git integration
pass # cli password manager
# haskell
stylish-haskell # formatter
@ -62,38 +47,43 @@ in
librewolf # a fork of firefox, focused on privacy, security and freedom
];
home.sessionVariables =
let
pass_data_dir = "${config.home.sessionVariables.XDG_DATA_HOME}/pass";
in
{
EDITOR = "nvim";
# for 'pass' tool
PASSWORD_STORE_DIR = "${pass_data_dir}/store";
PASSWORD_STORE_EXTENSIONS_DIR = "${pass_data_dir}/extensions";
# window manager
wm.xmonad.enable = true;
# shell
shell.zsh.enable = true;
# programs
progs = {
git = with secrets.git; {
enable = true;
inherit userName;
inherit userEmail;
};
# password manager
pass.enable = true;
# email manager
himalaya.enable = true;
# editor
nvim = {
enable = true;
default = true;
};
# tools
exa.enable = true;
zoxide.enable = true;
};
accounts.email = {
# TODO: add module for email account
accounts = secrets.emailAccounts;
};
programs.himalaya = {
enable = true;
settings = {
default-page-size = 10;
downloads-dir = "${config.home.homeDirectory}/downloads/email";
};
};
xsession = {
enable = true;
windowManager.xmonad = {
enable = true;
enableContribAndExtras = true;
};
};
# TODO: add module for lock screen
services.screen-locker = {
enable = true;
@ -102,112 +92,6 @@ in
inactiveInterval = 5;
};
services.gpg-agent.enable = true;
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
# used for pass
programs.gpg.enable = true;
# enable z shell
programs.zsh = {
enable = true;
enableAutosuggestions = true;
defaultKeymap = "viins";
dotDir = ".config/zsh";
history = {
path = "${config.xdg.dataHome}/zsh/zsh_history";
expireDuplicatesFirst = true;
ignorePatterns = [
"rm *"
"kill *"
];
};
oh-my-zsh = {
enable = true;
theme = "robbyrussell";
};
initExtraFirst = ''
# nix
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then
source $HOME/.nix-profile/etc/profile.d/nix.sh;
fi
source $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
export NIX_PATH=$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}
# ghcup
if [ -f "$HOME/.ghcup/env" ]; then
source "$HOME/.ghcup/env"
fi
'';
shellAliases =
let
exa = "${pkgs.exa}/bin/exa";
in {
# exa
ls = "${exa} -1";
ll = "${exa} -l";
lt = "${exa} --tree";
# nvim
vi = "nvim";
vim = "nvim";
# himalaya
himp = "himalaya -a personal";
himf = "himalaya -a family";
himw = "himalaya -a work";
};
};
# enable git VCS
programs.git = {
enable = true;
userName = secrets.git.name;
userEmail = secrets.git.email;
extraConfig = {
init.defaultBranch = "main";
pull.rebase = true;
};
aliases = {
co = "checkout";
cob = "checkout -b";
cobf = "checkout -B";
st = "status -sb";
d = "diff";
dc = "diff --cached";
aa = "add .";
ai = "add -i";
c = "commit";
cm = "commit -m";
ca = "commit --amend";
cam = "commit --amend -m";
can = "commit --amend --no-edit";
p = "push";
po = "push origin";
pf = "push --force-with-lease";
pfo = "push --force-with-lease origin";
pl = "pull";
plo = "pull origin";
rb = "rebase";
rbi = "rebase -i";
};
};
# replacement for 'ls' written in rust
programs.exa.enable = true;
# a fast cd command that learns your habbits
programs.zoxide = {
enable = true;
enableZshIntegration = true;
};
home.file = {
"scripts" = {
source = ../scripts;
@ -226,11 +110,19 @@ in
# add config for alacritty terminal
"alacritty/alacritty.yml".source = ../programs/alacritty/alacritty.yml;
# add config for xmonad window manager
# "xmonad/xmonad.hs".source = ../programs/xmonad/xmonad.hs;
# "xmobar/xmobar.hs".source = ../programs/xmonad/xmobar.hs;
"stylish-haskell/config.yaml".source = ../programs/stylish-haskell/config.yml;
};
};
# This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage
# when a new Home Manager release introduces backwards
# incompatible changes.
#
# You can update Home Manager without changing this value. See
# the Home Manager release notes for a list of state version
# changes in each release.
home.stateVersion = "21.11";
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}

28
nix/progs/exa.nix Normal file
View File

@ -0,0 +1,28 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.progs.exa;
bin = "${pkgs.exa}/bin/exa";
in
{
options.progs.exa = {
enable = mkOption {
type = types.bool;
default = false;
description = "Add and configure exa, a modern replacement for ls";
};
};
config = mkIf cfg.enable {
programs.exa.enable = true;
programs.zsh.shellAliases = mkIf config.shell.zsh.enable {
ls = "${bin} -1";
ll = "${bin} -l";
lt = "${bin} --tree";
};
};
}

61
nix/progs/git.nix Normal file
View File

@ -0,0 +1,61 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.progs.git;
in
{
options.progs.git = {
enable = mkOption {
type = types.bool;
default = false;
description = "Add git with my personal settings";
};
userName = mkOption {
type = types.str;
description = "Set your global name";
};
userEmail = mkOption {
type = types.str;
description = "Set your global email";
};
};
config = mkIf cfg.enable {
programs.git = {
enable = true;
userName = cfg.userName;
userEmail = cfg.userEmail;
extraConfig = {
init.defaultBranch = "main";
pull.rebase = true;
};
aliases = {
co = "checkout";
cob = "checkout -b";
cobf = "checkout -B";
st = "status -sb";
d = "diff";
dc = "diff --cached";
aa = "add .";
ai = "add -i";
c = "commit";
cm = "commit -m";
ca = "commit --amend";
cam = "commit --amend -m";
can = "commit --amend --no-edit";
p = "push";
po = "push origin";
pf = "push --force-with-lease";
pfo = "push --force-with-lease origin";
pl = "pull";
plo = "pull origin";
rb = "rebase";
rbi = "rebase -i";
};
};
};
}

35
nix/progs/himalaya.nix Normal file
View File

@ -0,0 +1,35 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.progs.himalaya;
bin = "${pkgs.himalaya}/bin/exa";
in
{
options.progs.himalaya = {
enable = mkOption {
type = types.bool;
default = false;
description = "Add himalaya with my personal configuration";
};
};
config = mkIf cfg.enable {
programs.himalaya = {
enable = true;
settings = {
default-page-size = 10;
downloads-dir = "${config.home.homeDirectory}/downloads/email";
};
};
programs.zsh.shellAliases = mkIf config.shell.zsh.enable {
him = bin;
himp = "${bin} -a personal";
himf = "${bin} -a family";
himw = "${bin} -a work";
};
};
}

37
nix/progs/nvim.nix Normal file
View File

@ -0,0 +1,37 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.progs.nvim;
bin = "nvim";
in
{
options.progs.nvim = {
enable = mkOption {
type = types.bool;
default = false;
description = "Add and configure exa, a modern replacement for ls";
};
default = mkOption {
type = types.bool;
default = false;
description = "Set neovim as default editor";
};
};
config = mkIf cfg.enable {
# TODO: install and configure neovim from home-manager
home.sessionVariables = mkIf cfg.default {
EDITOR = bin;
};
programs.zsh.shellAliases = mkIf config.shell.zsh.enable {
vi = bin;
vim = bin;
};
};
}

31
nix/progs/pass.nix Normal file
View File

@ -0,0 +1,31 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.progs.pass;
pass_data_dir = "${config.home.sessionVariables.XDG_DATA_HOME}/pass";
in
{
options.progs.pass = {
enable = mkOption {
type = types.bool;
default = false;
description = "Add and configure pass tool to manager your passwords";
};
};
config = mkIf cfg.enable {
home.packages = [pkgs.pass];
home.sessionVariables = {
PASSWORD_STORE_DIR = "${pass_data_dir}/store";
PASSWORD_STORE_EXTENSIONS_DIR = "${pass_data_dir}/extensions";
};
programs.gpg.enable = true;
services.gpg-agent.enable = true;
};
}

24
nix/progs/zoxide.nix Normal file
View File

@ -0,0 +1,24 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.progs.zoxide;
in
{
options.progs.zoxide = {
enable = mkOption {
type = types.bool;
default = false;
description = "Add zoxide, a modern replacement for cd";
};
};
config = mkIf cfg.enable {
programs.zoxide = {
enable = true;
enableZshIntegration = config.shell.zsh.enable;
};
};
}

View File

@ -5,7 +5,7 @@
};
git = {
name = "Bob Ross";
email = "bross@example.com";
userName = "Bob Ross";
userEmail = "bross@example.com";
};
}

56
nix/shell/zsh.nix Normal file
View File

@ -0,0 +1,56 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.shell.zsh;
in
{
options.shell.zsh = {
enable = mkOption {
type = types.bool;
default = false;
description = "Add z shell";
};
};
config = mkIf cfg.enable {
programs.zsh = {
enable = true;
enableAutosuggestions = true;
defaultKeymap = "viins";
dotDir = ".config/zsh";
history = {
path = "${config.xdg.dataHome}/zsh/zsh_history";
expireDuplicatesFirst = true;
ignorePatterns = [
"rm *"
"kill *"
];
};
oh-my-zsh = {
enable = true;
theme = "robbyrussell";
};
initExtraFirst = ''
# nix
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then
source $HOME/.nix-profile/etc/profile.d/nix.sh;
fi
source $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
export NIX_PATH=$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}
# ghcup
if [ -f "$HOME/.ghcup/env" ]; then
source "$HOME/.ghcup/env"
fi
'';
};
};
}

51
nix/wm/xmonad.nix Normal file
View File

@ -0,0 +1,51 @@
{ lib, config, pkgs, ...}:
with lib;
let
cfg = config.wm.xmonad;
in
{
options.wm.xmonad = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable xsessions and xmonad window manager";
};
};
config = mkIf cfg.enable {
nixpkgs.overlays = [
(self: super: {
haskellPackages = super.haskellPackages.override {
overrides = hself: hsuper: {
xmonad = hsuper.xmonad_0_17_0;
xmonad-contrib = hsuper.xmonad-contrib_0_17_0;
xmonad-extras = hsuper.xmonad-extras_0_17_0;
};
};
})
];
home.packages = with pkgs; [
xclip # access x clipboard from a console
dmenu # menu for x window system
flameshot # powerful yet simple to use screenshot software
];
xsession = {
enable = true;
windowManager.xmonad = {
enable = true;
enableContribAndExtras = true;
};
};
xdg.configFile = {
# add config for xmonad window manager
# "xmonad/xmonad.hs".source = ../programs/xmonad/xmonad.hs;
# "xmobar/xmobar.hs".source = ../programs/xmonad/xmobar.hs;
};
};
}