Rewrite to use Home manager for configuration.

This commit is contained in:
Dmitry Voronin 2024-06-30 03:56:48 +03:00
parent 2fe64aecce
commit 772e0ec65c
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
275 changed files with 908 additions and 960 deletions

View file

@ -23,9 +23,10 @@ live:
.PHONY: android
android:
nix-on-droid switch --flake $(flake); \
cp ~/.termux/_font.ttf ~/.termux/font.ttf; \
nix-on-droid switch --flake $(flake)
cp ~/.termux/_font.ttf ~/.termux/font.ttf
cp ~/.termux/_colors.properties ~/.termux/colors.properties
cp ~/.bashrc ~/.bash_profile
.PHONY: check
check:

View file

@ -1,18 +0,0 @@
{ pkgs, ... }: {
variables = {
# Default text editor.
EDITOR = "nvim";
# App to use for man pages.
MANPAGER = "nvim +Man!";
# Allow unfree packages in shell.
NIXPKGS_ALLOW_UNFREE = "1";
# Current system architecture.
NIX_CURRENT_SYSTEM = "${pkgs.stdenv.system}";
# Terminal settings.
TERM = "xterm-256color";
};
}

View file

@ -1,37 +0,0 @@
{ pkgs, ... }: {
list = with pkgs; [
android-tools # Android adb tool. Can be used to connect to itself via wireless debugging.
binwalk # Can analyze files for other files inside them.
curl # CLI http client.
exiftool # Image info.
ffmpeg # Video/audio converter.
file # Get general info about a file.
gdu # TUI storage analyzer.
git # Version control system.
gnutar gzip xz # Archive and compression tools.
imagemagick # Image converter and transformation tool.
inetutils # Things like FTP.
jq # Json parser.
lsof # Find current file users.
man # App to read manuals.
gcc # C compiler.
nmap # Network analyzer.
openssh # Ssh client.
parallel # Run programs in parallel.
pv # IO progress bar.
radare2 # Hex editor.
ripgrep # Grep for file search.
rsync # File copy tool.
sqlite # Serverless file-based database engine.
tmux # Terminal multiplexor.
tree # Show directory stricture as a tree.
wget # CLI http download tool.
wireguard-tools # Tools to work with Wireguard.
yazi chafa # CLI file manager.
yt-dlp # Video downloader.
zip unzip # Zip archive/unarchive tools.
coreutils dnsutils diffutils findutils utillinux # Common utilities.
gawk gnused gnugrep gnumake ripgrep # Common Gnu utils.
];
}

View file

@ -1,89 +0,0 @@
{ pkgs
, inputs
, const
, lib
, util
, config
, secret
, ... } @args: let
# Path where Termux stores user data.
homePath = "/data/data/com.termux.nix/files/home";
# Android modules.
environment = import ./Environment.nix args;
git = import ./Git.nix args;
package = import ./Package.nix args;
termux = import ./Termux.nix args;
# External modules.
bash = import ../module/common/bash args;
nvim = import ../module/common/nvim args;
ssh = import ../module/common/ssh args;
stylix = import ../module/common/Stylix.nix args;
tmux = import ../module/common/tmux args;
yazi = import ../user/common/yazi args;
in {
# Configure system.
time.timeZone = const.timeZone;
nix.extraOptions = "experimental-features = nix-command flakes";
# Install packages.
environment.packages = package.list;
# Home manager config.
home-manager.config = stylix // {
imports = [
inputs.stylix.homeManagerModules.stylix
];
home = {
# Release version.
stateVersion = const.droidStateVersion;
# Environment variables.
sessionVariables = environment.variables;
# Where to put config files.
file = {
".dotfiles".source = inputs.self;
".ssh/config".text = ssh.config;
".termux/_font.ttf".source = termux.font;
".termux/_colors.properties".text = termux.colors;
".config/yazi/init.lua".source = yazi.init;
".config/yazi/keymap.toml".source = yazi.keymap;
".config/yazi/theme.toml".source = yazi.theme;
".config/yazi/yazi.toml".source = yazi.yazi;
};
};
# Special app configuration.
programs = {
home-manager.enable = true;
bash = {
enable = true;
bashrcExtra = bash.config + termux.initScript;
};
tmux = {
enable = true;
extraConfig = tmux.config;
};
git = {
enable = true;
extraConfig = git.config;
};
neovim = {
enable = true;
extraConfig = nvim.config;
};
gpg = {
enable = true;
inherit (secret.crypto) publicKeys;
};
};
};
}

View file

@ -1,7 +1,7 @@
{ pkgs, config, ... }: {
{ pkgs, config, __findFile, ... }: {
stylix = {
enable = true;
image = config.module.common.wallpaper.path;
image = config.module.wallpaper.path;
autoEnable = true;
polarity = "dark";
opacity = {
@ -17,7 +17,7 @@
};
fonts = let
serif = {
package = (pkgs.callPackage ./applefont {});
package = (pkgs.callPackage <package/applefont> {});
name = "SF Pro Display";
};
in {
@ -38,7 +38,7 @@
name = "Noto Color Emoji";
};
};
override = if config.module.common.wallpaper.forceContrastText then {
override = if config.module.wallpaper.forceContrastText then {
base04 = "000000";
base05 = "ffffff";
base06 = "ffffff";

View file

@ -4,7 +4,7 @@
forceContrastText = false;
in {
options = {
module.common.wallpaper = {
module.wallpaper = {
forceContrastText = mkOption {
default = forceContrastText;
type = types.bool;

122
flake.nix
View file

@ -137,14 +137,18 @@
url = "https://git.voronind.com/voronind/nixos.git";
};
nixosConfigurations = let
# List all files in a dir.
lsFiles = path: map (f: "${path}/${f}") (
builtins.filter (i: builtins.readFileType "${path}/${i}" == "regular") (
builtins.attrNames (builtins.readDir path)
)
);
# Hack to use <container/Change.nix> in other files.
# Need to add __findFile to args tho.
__findFile = _: p: ./${p};
# List all files in a dir.
lsFiles = path: map (f: "${path}/${f}") (
builtins.filter (i: builtins.readFileType "${path}/${i}" == "regular") (
builtins.attrNames (builtins.readDir path)
)
);
nixosConfigurations = let
# Function to create a host. It does basic setup, like adding common modules.
mkHost = { system, hostname, modules } @args: nixpkgs.lib.nixosSystem {
# `Inherit` is just an alias for `system = system;`, which means that
@ -164,12 +168,11 @@
# Add modules.
{ imports =
(lsFiles ./container) ++
(lsFiles ./module) ++
(lsFiles ./module/common) ++
(lsFiles ./module/desktop) ++
(lsFiles ./overlay) ++
(lsFiles ./user);
(self.lsFiles ./config) ++
(self.lsFiles ./container) ++
(self.lsFiles ./module) ++
(self.lsFiles ./overlay) ++
[ ./home/NixOs.nix ];
}
# Add Home Manager module.
@ -184,23 +187,20 @@
pkgs = nixpkgs.legacyPackages.${system}.pkgs;
lib = nixpkgs.lib;
config = self.nixosConfigurations.${hostname}.config;
in {
inherit inputs self;
inherit (self) const __findFile;
pkgsJobber = nixpkgsJobber.legacyPackages.${system}.pkgs;
pkgsStable = nixpkgsJobber.legacyPackages.${system}.pkgs;
pkgsMaster = nixpkgsJobber.legacyPackages.${system}.pkgs;
pkgsStable = nixpkgsStable.legacyPackages.${system}.pkgs;
pkgsMaster = nixpkgsMaster.legacyPackages.${system}.pkgs;
secret = import ./secret {}; # Secrets (public keys).
container = import ./lib/Container.nix { inherit lib pkgs config; inherit (self) const; }; # Container utils.
util = import ./lib/Util.nix { inherit lib; }; # Util functions.
in {
inherit secret container util inputs;
inherit (self) const;
# Stable and Master pkgs.
inherit pkgsStable pkgsMaster;
# Stuff for Jobber container, skip this part.
inherit poetry2nixJobber pkgsJobber;
inherit poetry2nixJobber;
};
};
@ -221,10 +221,10 @@
{ services.openssh.settings.PermitRootLogin = nixpkgs.lib.mkForce "yes"; }
# Disable auto-updates as they are not possible for Live ISO.
{ module.common.autoupdate.enable = false; }
{ module.autoupdate.enable = false; }
# Base Live images also require the LTS kernel.
{ module.common.kernel.latest = false; }
{ module.kernel.latest = false; }
];
x86System = hostname: mkSystem hostname "x86_64-linux" [];
@ -245,6 +245,58 @@
(x86LiveSystem "live")
];
# Home manager (distro-independent).
# Install nix: sh <(curl -L https://nixos.org/nix/install) --no-daemon
# Or with --daemon for multi-user (as root).
# $ nix run home-manager/master -- init --switch
# $ nix shell '<home-manager>' -A install
# Add to /etc/nix/nix.conf > experimental-features = nix-command flakes
# And then # systemctl restart nix-daemon.service
# $ home-manager switch --flake ~/hmconf
homeConfigurations = let
lib = nixpkgs.lib;
secret = import ./secret {};
util = import ./lib/Util.nix { inherit lib; };
mkCommonHome = username: homeDirectory: system: modules: let
pkgs = nixpkgs.legacyPackages.${system};
pkgsStable = nixpkgsStable.legacyPackages.${system};
pkgsMaster = nixpkgsMaster.legacyPackages.${system};
in {
${username} = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = {
inherit self inputs secret util pkgs pkgsStable pkgsMaster;
inherit (self) const __findFile;
};
modules = modules ++ (self.lsFiles ./config) ++ [
./home/HomeManager.nix
{ home.hm.enable = true; }
{ home.hm.username = username; }
{ home.hm.homeDirectory = homeDirectory; }
{ home.hm.packages.core.enable = true; }
{ nixpkgs.config.allowUnfree = true; }
{ nixpkgs.config.allowUnfreePredicate = (pkg: true); }
{ nix.package = pkgs.nix; }
{ nix.settings.experimental-features = [ "nix-command " "flakes" ]; }
inputs.stylix.homeManagerModules.stylix
];
};
};
x86LinuxHome = username: modules: mkCommonHome username "/home/${username}" "x86_64-linux" modules;
x86LinuxRoot = mkCommonHome "root" "/root" "x86_64-linux" [];
in nixpkgs.lib.foldl' (acc: h: acc // h) {} [
x86LinuxRoot
(x86LinuxHome "voronind" [
{ home.hm.packages.common.enable = true; }
])
];
# Android.
nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
modules = let
@ -255,12 +307,18 @@
{ system.stateVersion = self.const.droidStateVersion; }
# I put all my Android configuration there.
./android
./home/Android.nix
{ home.android.enable = true; }
# { nixpkgs.config.allowUnfree = true; }
# { nixpkgs.config.allowUnfreePredicate = (pkg: true); }
{ nix.extraOptions = "experimental-features = nix-command flakes"; }
{ home-manager.config.stylix.autoEnable = lib.mkForce false; }
# Some common modules.
./module/common/Setting.nix
./module/common/Wallpaper.nix
(import ./module/common/Style.nix { inherit lib; inherit (config.home-manager) config; })
./config/Setting.nix
./config/Wallpaper.nix
(import ./config/Style.nix { inherit lib; inherit (config.home-manager) config; })
];
# SpecialArgs allows you to pass objects down to other configuration.
@ -269,11 +327,11 @@
pkgs = nixpkgs.legacyPackages."aarch64-linux".pkgs;
lib = nixpkgs.lib;
in {
inherit inputs;
inherit (self) const;
inherit inputs self;
inherit (self) const __findFile;
secret = import ./secret {}; # Secrets (public keys).
util = import ./lib/Util.nix { inherit lib; }; # Util functions.
secret = import ./secret {}; # Secrets (public keys).
util = import ./lib/Util.nix { inherit lib; }; # Util functions.
};
};
};

40
home/Android.nix Normal file
View file

@ -0,0 +1,40 @@
# This is a common user configuration.
{ const
, pkgs
, self
, config
, lib
, inputs
, pkgsStable
, pkgsMaster
, __findFile
, ... } @args: with lib; let
cfg = config.home.android;
stylix = import <config/Stylix.nix> args;
android = import ./android args;
package = import <package> args;
# homePath = "/data/data/com.termux.nix/files/home";
in {
options = {
home.android = {
enable = mkEnableOption "Android HM config.";
};
};
config = mkIf cfg.enable {
time.timeZone = const.timeZone;
environment.packages = package.core;
home-manager.config = stylix // {
imports = [ inputs.stylix.homeManagerModules.stylix ];
home = {
stateVersion = const.droidStateVersion;
sessionVariables = import ./variable args;
file = (import ./config args) // {
".termux/_font.ttf".source = android.font;
".termux/_colors.properties".text = android.colors;
};
};
programs = import ./program args;
};
};
}

59
home/HomeManager.nix Normal file
View file

@ -0,0 +1,59 @@
# This is a common user configuration.
{ const
, util
, config
, lib
, __findFile
, ... } @args: with lib; let
cfg = config.home.hm;
package = import <package> args;
in {
options = {
home.hm = {
enable = mkEnableOption "Home-Manager standalone config.";
username = mkOption {
default = null;
type = types.str;
};
homeDirectory = mkOption {
default = "/home/${cfg.username}";
type = types.str;
};
packages = mkOption {
default = {};
type = types.submodule {
options = {
core.enable = mkEnableOption "Core apps.";
common.enable = mkEnableOption "Common apps.";
desktop.enable = mkEnableOption "Desktop apps.";
gaming.enable = mkEnableOption "Gaming apps.";
creative.enable = mkEnableOption "Creative apps.";
dev.enable = mkEnableOption "Dev apps.";
extra.enable = mkEnableOption "Extra apps.";
};
};
};
};
};
config = mkIf cfg.enable (mkMerge [
{
home = {
inherit (cfg) username homeDirectory;
inherit (const) stateVersion;
file = import ./config args;
sessionVariables = import ./variable args;
};
xdg = import ./xdg { inherit (cfg) homeDirectory; };
programs = import ./program args;
dconf.settings = util.catSet (util.ls ./config/dconf) args;
}
(mkIf cfg.packages.core.enable { home.packages = package.core; })
(mkIf cfg.packages.common.enable { home.packages = package.common; })
(mkIf cfg.packages.desktop.enable { home.packages = package.desktop; })
(mkIf cfg.packages.gaming.enable { home.packages = package.gaming; })
(mkIf cfg.packages.creative.enable { home.packages = package.creative; })
(mkIf cfg.packages.dev.enable { home.packages = package.dev; })
(mkIf cfg.packages.extra.enable { home.packages = package.extra; })
]);
}

41
home/NixOs.nix Normal file
View file

@ -0,0 +1,41 @@
# This is a common user configuration.
{ const
, config
, util
, lib
, pkgs
, ... } @args: with lib; let
cfg = config.home.nixos;
in {
imports = (util.ls ./user);
options = {
home.nixos = {
enable = mkEnableOption "NixOS user setup.";
users = mkOption {
default = [];
type = types.listOf types.attrs;
};
};
};
config = mkIf cfg.enable {
home-manager = {
users = builtins.foldl' (acc: user: acc // {
${user.username} = {
home = {
inherit (const) stateVersion;
inherit (user) username homeDirectory;
file = import ./config args;
sessionVariables = import ./variable args;
};
xdg = import ./xdg { inherit (user) homeDirectory; };
programs = import ./program args;
dconf.settings = util.catSet (util.ls ./config/dconf) args;
};
}) {} cfg.users;
backupFileExtension = "old";
};
};
}

View file

@ -1,4 +1,4 @@
{ pkgs, config, util, ... }: {
{ pkgs, util, config, ... }: {
font = pkgs.runCommandNoCC "font" {} ''
cp ${pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }}/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out
'';
@ -7,12 +7,4 @@
background=#${config.style.color.bg.dark}
foreground=#${config.style.color.fg.light}
'';
initScript = util.trimTabs ''
[[ -f ~/.termux/font.ttf ]] || {
cp ~/.termux/_font.ttf ~/.termux/font.ttf
cp ~/.termux/_colors.properties ~/.termux/colors.properties
_warn "Termux config installed, please restart."
};
'';
}

View file

@ -0,0 +1,38 @@
{ util, pkgs, ... } @args: let
modules = util.catText (util.ls ./module) args;
modulesFile = pkgs.writeText "BashModules" modules;
in {
inherit modules modulesFile;
bashrc = modules + util.trimTabs ''
# Find all functions.
function find_function() {
/usr/bin/env cat ${modulesFile} | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//"
}
# Export all functions.
export -f $(find_function | tr '\n' ' ')
export -f find_function
# Autostart Sway.
if [[ -z $DISPLAY ]] && [[ "$(tty)" = "/dev/tty1" ]]; then
exec sway
fi
'';
bash_profile = util.trimTabs ''
# Home manager.
[ -e ~/.nix-profile/etc/profile.d/nix.sh ] && source ~/.nix-profile/etc/profile.d/nix.sh
# Bashrc.
[ -f ~/.bashrc ] && source ~/.bashrc
# Profile.
[ -f ~/.profile ] && source ~/.profile
'';
profile = util.trimTabs ''
# Load HM vars.
[ -e ~/.nix-profile/etc/profile.d/hm-session-vars.sh ] && source ~/.nix-profile/etc/profile.d/hm-session-vars.sh
'';
}

View file

@ -21,7 +21,7 @@
};
# Cut full paths.
target="''${target##*/}"
[[ "''${target##*/}" = "" ]] || target="''${target##*/}"
local date=$(_archive_date)
@ -62,7 +62,7 @@
};
# Cut full paths.
target="''${target##*/}"
[[ "''${target##*/}" = "" ]] || target="''${target##*/}"
# Start timestamp.
local date=$(_archive_date)

48
home/config/default.nix Normal file
View file

@ -0,0 +1,48 @@
{ self, config, ... } @args: let
bash = import ./bash args;
btop = import ./top/btop args;
editor = import ./editorconfig args;
foot = import ./foot args;
fuzzel = import ./fuzzel args;
git = import ./git args;
gtk3 = import ./gtk/3 args;
htop = import ./top/htop args;
keyd = import ./keyd args;
mako = import ./mako args;
mangohud = import ./mangohud args;
nvim = import ./nvim args;
ssh = import ./ssh args;
sway = import ./sway args;
tmux = import ./tmux args;
waybar = import ./waybar args;
yazi = import ./yazi args;
in {
".bashrc".text = bash.bashrc;
".bash_profile".text = bash.bash_profile;
".profile".text = bash.profile;
".config/MangoHud/MangoHud.conf".text = mangohud.config;
".config/MangoHud/presets.conf".text = mangohud.presets;
".config/btop/btop.conf".text = btop.text;
".config/foot/foot.ini".source = foot.file;
".config/fuzzel/fuzzel.ini".source = fuzzel.file;
".config/gtk-3.0/bookmarks".text = gtk3.bookmarks;
".config/htop/htoprc".text = htop.text;
".config/keyd/app.conf".text = keyd.text;
".config/mako/config".source = mako.file;
".config/nvim/init.vim".text = nvim.text;
".config/sway/config".text = sway.text;
".config/tmux/tmux.conf".text = tmux.text;
".config/waybar/config".source = waybar.config;
".config/waybar/style.css".source = waybar.style;
".config/yazi/init.lua".source = yazi.init;
".config/yazi/keymap.toml".source = yazi.keymap;
".config/yazi/theme.toml".source = yazi.theme;
".config/yazi/yazi.toml".source = yazi.yazi;
".editorconfig".source = editor.file;
".gitconfig".source = git.file;
".nixos".source = self;
".parallel/will-cite".text = "";
".ssh/config".text = ssh.text;
".wallpaper".source = config.module.wallpaper.path;
"media/template".source = ./template;
}

View file

@ -1,5 +1,5 @@
{ secret, ... }: {
config = {
{ secret, pkgs, ... }: {
file = (pkgs.formats.gitIni { listsAsDuplicateKeys = true; }).generate "GitConfig" {
credential.helper = "store";
gpg.format = secret.crypto.sign.git.format;
gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed;
@ -7,6 +7,7 @@
pull.rebase = true;
push.autoSetupRemote = true;
rebase.autoStash = true;
safe.directory = "*";
user.signingkey = builtins.readFile secret.crypto.sign.git.key;
};
}

Some files were not shown because too many files have changed in this diff Show more