feat(hm): cpu usage now works on tmux

std
Hung 2023-05-02 09:28:34 -07:00
parent 1f511b052c
commit 3c483aeb89
13 changed files with 1587 additions and 1217 deletions

111
c_.nix
View File

@ -1,111 +0,0 @@
# a small helper that only builds on top of builtins functions
_: (builtins // (
let
formatSecondsSinceEpoch = t:
let
rem = x: y: x - x / y * y;
days = t / 86400;
secondsInDay = rem t 86400;
hours = secondsInDay / 3600;
minutes = (rem secondsInDay 3600) / 60;
seconds = rem t 60;
# Courtesy of https://stackoverflow.com/a/32158604.
z = days + 719468;
era = (if z >= 0 then z else z - 146096) / 146097;
doe = z - era * 146097;
yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
y = yoe + era * 400;
doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
mp = (5 * doy + 2) / 153;
d = doy - (153 * mp + 2) / 5 + 1;
m = mp + (if mp < 10 then 3 else -9);
y' = y + (if m <= 2 then 1 else 0);
pad = s: if builtins.stringLength s < 2 then "0" + s else s;
in
"${toString y'}${pad (toString m)}${pad (toString d)}${pad (toString hours)}"
+ "${pad (toString minutes)}${pad (toString seconds)}";
fetchTree =
# this is the value of flake.lock#lock.nodes.${input_name}.locked
{ type
, host ? ""
, owner ? ""
, repo ? ""
, rev ? ""
, submodules ? ""
, path ? ""
, narHash ? null
, lastModified ? 0
, src ? ./.
}@info:
if info.type == "github" then
{
outPath =
fetchTarball
({
url = "https://api.${info.host or "github.com"}/repos/"
+ "${info.owner}/${info.repo}/tarball/${info.rev}";
}
// (if info ? narHash then { sha256 = info.narHash; } else { })
);
rev = info.rev;
shortRev = builtins.substring 0 7 info.rev;
lastModified = info.lastModified;
lastModifiedDate = formatSecondsSinceEpoch info.lastModified;
narHash = info.narHash;
}
else if info.type == "git" then
{
outPath =
builtins.fetchGit
({ url = info.url; }
// (if info ? rev then { inherit (info) rev; } else { })
// (if info ? ref then { inherit (info) ref; } else { })
// (if info ? submodules then { inherit (info) submodules; } else { })
);
lastModified = info.lastModified;
lastModifiedDate = formatSecondsSinceEpoch info.lastModified;
narHash = info.narHash;
} // (if info ? rev then {
rev = info.rev;
shortRev = builtins.substring 0 7 info.rev;
} else { })
else if info.type == "path" then
{
outPath = builtins.path {
path =
if builtins.substring 0 1 info.path != "/"
then src + ("/" + info.path) # make this absolute path by prepending ./
else info.path; # it's already an absolute path
};
narHash = info.narHash;
}
else if info.type == "tarball" then
{
outPath =
fetchTarball
({ inherit (info) url; }
// (if info ? narHash then { sha256 = info.narHash; } else { })
);
}
else if info.type == "gitlab" then
{
inherit (info) rev narHash lastModified;
outPath =
fetchTarball
({ url = "https://${info.host or "gitlab.com"}/api/v4/projects/${info.owner}%2F${info.repo}/repository/archive.tar.gz?sha=${info.rev}"; }
// (if info ? narHash then { sha256 = info.narHash; } else { })
);
shortRev = builtins.substring 0 7 info.rev;
}
else
# FIXME: add Mercurial, tarball inputs.
throw "flake input has unsupported input type '${info.type}'";
in
{
inherit fetchTree;
}
)) nil

1238
flake.lock

File diff suppressed because it is too large Load Diff

139
flake.nix
View File

@ -6,123 +6,36 @@
};
description = "My personal configuration in Nix (and some native configurations)";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
# continously merged & rebased lightweight .lib. Basically a huge extension to c_.
nixlib.url = "github:nix-community/nixpkgs.lib";
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
nixgl.url = "path:out-of-tree/nixGL";
rust-overlay.url = "github:oxalica/rust-overlay";
# Allows default.nix to call onto flake.nix. Useful for nix eval and automations
flake-compat = {
url = "path:out-of-tree/flake-compat";
flake = false;
};
kpcli-py = {
url = "github:rebkwok/kpcli";
flake = false;
};
neovim-nightly-overlay = {
url = "github:nix-community/neovim-nightly-overlay";
inputs.nixpkgs.url = "github:nixos/nixpkgs?rev=fad51abd42ca17a60fc1d4cb9382e2d79ae31836";
};
nix-index-database = {
url = "github:mic92/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
nickel.url = "github:tweag/nickel";
nix-boost.url = "git+https://git.pegasust.com/pegasust/nix-boost.git";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
deploy-rs.url = "github:serokell/deploy-rs";
std.url = "github:divnix/std";
hive.url = "github:divnix/hive";
};
outputs =
{ nixpkgs
, agenix
, home-manager
, flake-utils
, nixgl
, rust-overlay
, flake-compat
, neovim-nightly-overlay
, nix-index-database
, nixlib
, nickel
, ...
}@_inputs:
let
# config_fn:: system -> config
# this function should take simple exports of homeConfigurations.${profile},
# nixosConfigurations.${profile}, devShells.${profile}, packages.${profile}
# and correctly produce
supported_systems = flake-utils.lib.defaultSystems;
forEachSystem = nixpkgs.lib.genAttrs supported_systems;
in
let
proj_root =
let
path = builtins.toString ./.;
in
outputs = { std, hive, ... }@inputs: std.growOn
{
inherit path;
configs.path = "${path}/native_configs";
scripts.path = "${path}/scripts";
secrets.path = "${path}/secrets";
testdata.path = "${path}/tests";
modules.path = "${path}/modules";
hosts.path = "${path}/hosts";
users.path = "${path}/users";
};
overlays = forEachSystem (system: import ./overlays.nix (_inputs // { inherit system; }));
pkgs = forEachSystem (system: (import nixpkgs {
inherit system;
overlays = overlays.${system};
config = {
allowUnfree = true;
};
}));
lib = (builtins.foldl' (lhs: rhs: (nixpkgs.lib.recursiveUpdate lhs rhs)) { } [
nixpkgs.lib
nixlib.lib
]);
inputs_w_lib = forEachSystem (
system: lib.recursiveUpdate _inputs {
inherit system lib;
pkgs = pkgs.${system};
# boilerplate
inherit inputs;
# All cell blocks are under ./nix/cells/<cell>/<cellblock> as `<cellblock>.nix`
# or `<cellblock/default.nix`
cellsFrom = ./nix/cells;
modules = ./nix/modules;
cellBlocks =
let
inherit (std.blockTypes) devShells;
inherit (hive.blockTypes) nixosConfigurations homeConfigurations;
in
[
(devShells "devshells")
(nixosConfigurations "host_profile")
(homeConfigurations "home_profile")
];
}
);
modules = (import ./modules inputs_w_lib);
hosts = (import ./hosts inputs_w_lib);
users = (import ./users inputs_w_lib);
# {nixpkgs, agenix, home-manager, flake-utils, nixgl, rust-overlay, flake-compat
# ,pkgs, lib (extended), proj_root}
final_inputs = inputs_w_lib;
in
{
inherit (hosts) nixosConfigurations;
inherit (users) homeConfigurations;
inherit lib proj_root;
devShells = forEachSystem (system:
{default = (import ./dev-shell.nix final_inputs.${system});}
);
templates = forEachSystem (system: import ./templates final_inputs.${system});
secrets = {
pubKeys = {
hosts = hosts.pubKeys;
users = users.pubKeys;
};
};
debug = {
inherit final_inputs hosts users modules lib inputs_w_lib pkgs nixpkgs nixlib;
};
# formatter."${system}" = pkgs.nixpkgs-fmt;
devShells = std.harvest [ [ "dotfiles" "devshells" ] ];
nixosConfigurations = std.harvest [ [ "dotfiles" "nixos" ] ];
homeConfigurations = std.harvest [ [ "dotfiles" "home" ] ];
};
}

View File

@ -152,8 +152,8 @@ vim.opt.background = "dark";
vim.api.nvim_create_user_command('Dark', function(opts)
-- opts: {name, args: str, fargs: Splited<str>, range, ...}
---@type string
local contrast = (opts.arg;
vim.g.gruvbox_contrast_dark = contrast;
local contrast = (opts.args and string.len(opts.args) > 0) and opts.args or vim.g.gruvbox_contrast_light;
= contrast;
vim.opt.background = "dark";
end,
{ nargs = "?", })
@ -616,7 +616,7 @@ require("mason").setup({
},
check_outdated_packages_on_open = true,
},
-- The default settings is "prepend" https://github.com/williamboman/mason.nvim#default-configuration
-- NOTE: The default settings is "prepend" https://github.com/williamboman/mason.nvim#default-configuration
-- Which means Mason's installed path is prioritized against our local install
-- see: https://git.pegasust.com/pegasust/aoc/commit/b45dc32c74d84c9f787ebce7a174c9aa1d411fc2
-- This introduces some pitfalls, so we'll take the approach of trusting user's local installation

View File

@ -88,6 +88,11 @@ Host dev0
User htran
Port 22
Host dev2
HostName 10.100.200.210
User htran
Port 22
Host dev1
HostName 10.100.200.220
User htran

View File

@ -18,7 +18,6 @@ set-option -g renumber-windows on
# set -g status-interval 60
# set -g status-right-style 'bg=#333333 fg=#5eacd3'
# set -g status-right-length 50
set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M '
# set -g status-left " "
# Keybinds

View File

@ -42,6 +42,7 @@ let
pkgs.nodePackages.pyright
pkgs.python3Packages.pylint
pkgs.python3Packages.flake8
# FIXME: installing ansible from here just doesn't work :/
# pkgs.ansible-lint
# pkgs.python38Packages.ansible
# pkgs.ansible-language-server
@ -51,7 +52,10 @@ let
# pkgs.rust-analyzer
# rust_pkgs
# pkgs.evcxr # Rust REPL for Conjure!
];
] ++ lib.optionals (pkgs.stdenv.isDarwin) (let
inherit (pkgs.darwin.apple_sdk.frameworks) System CoreFoundation; in [
System CoreFoundation pkgs.cc
]);
in
{
options.base.neovim = {

View File

@ -54,8 +54,11 @@ in
enable = true;
# extraConfigBeforePlugin = builtins.readFile "${proj_root.config.path}/tmux/tmux.conf";
plugins = let inherit (pkgs.tmuxPlugins) cpu net-speed; in [ cpu net-speed ];
extraConfig = (builtins.readFile "${proj_root.config.path}/tmux/tmux.conf");
};
xdg.configFile."tmux/tmux.conf".text = myLib.mkOrder 600 (builtins.readFile "${proj_root.config.path}/tmux/tmux.conf");
xdg.configFile."tmux/tmux.conf".text = myLib.mkOrder 600 ''
set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M '
'';
programs.exa = {
enable = true;
enableAliases = true;

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@
neovim-nightly-overlay = {
url = "github:nix-community/neovim-nightly-overlay";
# Pin to a nixpkgs revision that doesn't have NixOS/nixpkgs#208103 yet
inputs.nixpkgs.url = "github:nixos/nixpkgs?rev=fad51abd42ca17a60fc1d4cb9382e2d79ae31836";
# inputs.nixpkgs.url = "github:nixos/nixpkgs?rev=fad51abd42ca17a60fc1d4cb9382e2d79ae31836";
};
nix-index-database = {
url = "github:mic92/nix-index-database";

View File

@ -37,7 +37,7 @@ in
# pkgs.xorg.xclock # TODO: only include if have gui # For testing GL installation
# pkgs.logseq # TODO: only include if have GL # Obsidian alt
pkgs.mosh # Parsec for SSH
pkgs.nixops_unstable # nixops v2 # insecure for now
# pkgs.nixops_unstable # nixops v2 # insecure for now
pkgs.lynx # Web browser at your local terminal
pkgs.zk

View File

View File

@ -0,0 +1,8 @@
{inputs, cells}: let
inherit (inputs) std nixpkgs;
in {
default = std.lib.dev.mkShell {
name = nixpkgs.lib.
};
}