Compare commits

..

No commits in common. "3c483aeb893880e599bebe5824a2b09d4827c430" and "bbcc5a14b71c2bb0ad416ca0fd405f9bdb52bbb1" have entirely different histories.

18 changed files with 1083 additions and 1919 deletions

111
c_.nix Normal file
View File

@ -0,0 +1,111 @@
# 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

View File

@ -15,8 +15,6 @@
pkgs.rust4cargo
pkgs.sops
pkgs.ssh-to-age
pkgs.go
pkgs.gopls
];
shellHook = ''

1094
flake.lock

File diff suppressed because it is too large Load Diff

139
flake.nix
View File

@ -6,36 +6,123 @@
};
description = "My personal configuration in Nix (and some native configurations)";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
deploy-rs.url = "github:serokell/deploy-rs";
std.url = "github:divnix/std";
hive.url = "github:divnix/hive";
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";
};
outputs = { std, hive, ... }@inputs: std.growOn
{
# 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 =
outputs =
{ nixpkgs
, agenix
, home-manager
, flake-utils
, nixgl
, rust-overlay
, flake-compat
, neovim-nightly-overlay
, nix-index-database
, nixlib
, nickel
, ...
}@_inputs:
let
inherit (std.blockTypes) devShells;
inherit (hive.blockTypes) nixosConfigurations homeConfigurations;
# 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
[
(devShells "devshells")
(nixosConfigurations "host_profile")
(homeConfigurations "home_profile")
];
}
{
devShells = std.harvest [ [ "dotfiles" "devshells" ] ];
nixosConfigurations = std.harvest [ [ "dotfiles" "nixos" ] ];
homeConfigurations = std.harvest [ [ "dotfiles" "home" ] ];
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};
}
);
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;
};
}

View File

@ -147,13 +147,13 @@ vim.opt.scrolloff = 30;
vim.opt.signcolumn = "yes";
vim.opt.colorcolumn = "80";
vim.opt.background = "dark";
vim.opt.background = "light";
vim.api.nvim_create_user_command('Dark', function(opts)
-- opts: {name, args: str, fargs: Splited<str>, range, ...}
---@type string
local contrast = (opts.args and string.len(opts.args) > 0) and opts.args or vim.g.gruvbox_contrast_light;
= contrast;
local contrast = (opts.args and string.len(opts.args) > 0) and opts.args or vim.g.gruvbox_contrast_dark;
vim.g.gruvbox_contrast_dark = contrast;
vim.opt.background = "dark";
end,
{ nargs = "?", })
@ -616,7 +616,7 @@ require("mason").setup({
},
check_outdated_packages_on_open = true,
},
-- NOTE: The default settings is "prepend" https://github.com/williamboman/mason.nvim#default-configuration
-- 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,11 +88,6 @@ 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,6 +18,7 @@ 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,7 +42,6 @@ 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
@ -52,10 +51,7 @@ 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

@ -52,13 +52,11 @@ in
};
programs.tmux = {
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");
configBeforePlugin = builtins.readFile "${proj_root.config.path}/tmux/tmux.conf";
plugins =
let inherit (pkgs.tmuxPlugins) cpu net-speed;
in [ cpu net-speed ];
};
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

@ -16,7 +16,7 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
url = "github:Pegasust/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
@ -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";
@ -202,7 +202,6 @@
];
}
nerd_font_module
{ base.keepass.enable = pkgs.lib.mkForce false; }
];
extraSpecialArgs = mkModuleArgs {
inherit pkgs;

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

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

View File

@ -1,81 +1,65 @@
#!/usr/bin/env python3
# execution: fetch.py >nvidia_versions.json
import http.client
import urllib3
import json
import sys
NV_FREE_X86_URL = "download.nvidia.com"
POTENTIAL_SHA256_EXTS = [".sha256sum", ".sha256"]
RIGHT_PAD = " " * 20
http = urllib3.PoolManager()
dl_dir = http.request("GET", "https://download.nvidia.com/XFree86/Linux-x86_64/")
conn = http.client.HTTPSConnection(NV_FREE_X86_URL)
conn.request("GET", "/XFree86/Linux-x86_64/")
response = conn.getresponse()
dir_html = response.read()
# print(f"{dl_dir.status=}\n{dl_dir.data=}")
assert (response.status < 400), "Error occurred fetching for source from"
assert (dl_dir.status < 400), "Error probably occurred"
def scrape_driver_versions(dir_html: bytes):
# The idea is to recursively follows all interesting `src` from `<a href={src}>`
def _rec(dir_html: bytes, href_url_start: int = 0, so_far: list[str] = []) -> list[str]:
def find_versions(dir_html: bytes) -> list[str]:
# this algorithm obviously need recursion because we need to discover the items
def _rec(dir_html: bytes, start: int = 0, so_far: list[str] = []) -> list[str]:
MATCH_START = b"<span class=\'dir\'><a href=\'"
href_url_start = dir_html.find(MATCH_START, href_url_start)
if href_url_start == -1: # EOF
potential_start = dir_html.find(MATCH_START, start)
if potential_start == -1:
return so_far
# version href should start with a number
potential_version_start = href_url_start + len(MATCH_START)
# check that it starts with a number
potential_version_start = potential_start + len(MATCH_START)
p = potential_version_start
if not (dir_html[p: p+1].decode().isnumeric()):
return _rec(dir_html, potential_version_start, so_far)
# this thing matches, add to so_far and continue
version_end = dir_html.find(b"/", potential_version_start)
assert version_end != -1, "Should have end-signaling /"
assert version_end != -1, "There should be matching /"
so_far.append(dir_html[potential_version_start:version_end].decode())
return _rec(dir_html, version_end, so_far)
return _rec(dir_html, 0, [])
versions = _rec(dir_html, 0, [])
num_versions = len(versions)
for i, version in enumerate(versions):
print(f"[{i+1}/{num_versions}] Processing version {version}{RIGHT_PAD}", end="\r", file=sys.stderr)
yield version
print()
versions = find_versions(dl_dir.data)
# print("\n".join(versions))
versions = scrape_driver_versions(dir_html)
download_urls = lambda ver: [f"https://download.nvidia.com/XFree86/Linux-x86_64/{ver}/NVIDIA-Linux-x86_64-{ver}.run"]
sha256_urls = lambda ver: [f"{url}{dl_ext}" for dl_ext in [".sha256sum", ".sha256"] for url in download_urls(ver)]
def req_monad(url: str, err_fn, then_fn):
res = http.request("GET", url)
if res.status >= 400:
return err_fn(res.status)
return then_fn(res.data)
download_urls_of = lambda ver: [f"/XFree86/Linux-x86_64/{ver}/NVIDIA-Linux-x86_64-{ver}.run"]
sha256_urls_of = lambda ver: [
f"{url}{dl_ext}"
for dl_ext in POTENTIAL_SHA256_EXTS
for url in download_urls_of(ver)
]
identity = lambda e: e
none_id = lambda _: None
def sha256_of(version: str) -> str | None:
if int(version.split(".")[0]) < 256:
# Has 3 different packages that we should probably not bother
def get_sha256(version: str) -> str | None:
for url in sha256_urls(version):
res = http.request("GET", url)
# print(f"attempting: {url}")
if res.status < 400:
return res.data.decode().split()[0]
return None
for url in sha256_urls_of(version):
conn = http.client.HTTPSConnection(NV_FREE_X86_URL)
conn.request("GET", url)
response = conn.getresponse()
if response.status < 400:
return response.read().decode().split()[0]
print(f"No sha256 for {version}{RIGHT_PAD}", file=sys.stderr)
return None
def fetch(version: str):
dl_url = download_urls_of(version)[0]
sha256 = sha256_of(version)
return (version, dl_url, sha256)
fetch_data = [fetch(v) for v in versions]
fetch_data = [(v, download_urls(v)[0], get_sha256(v)) for v in versions]
fetch_data.append(("latest", *fetch_data[-1][1:]))
# print(fetch_data)
# now print the JSON object
print(json.dumps({
version: {
"url": f"https://{NV_FREE_X86_URL}{dl_url}",
"url": dl_url,
"sha256": sha256
} for (version, dl_url, sha256) in fetch_data if sha256 is not None}, indent=4))
# execution: fetch.py >nvidia_versions.json

View File

@ -27,7 +27,6 @@
nixGLIntel = pkgs.nixGLIntel;
nixVulkanNvidia = pkgs.auto.nixVulkanNvidia;
nixVulkanIntel = pkgs.nixVulkanIntel;
};
# deprecated attributes for retro compatibility

View File

@ -1,4 +1,3 @@
{
"256.25": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/256.25/NVIDIA-Linux-x86_64-256.25.run",
@ -540,10 +539,6 @@
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/470.161.03/NVIDIA-Linux-x86_64-470.161.03.run",
"sha256": "5da82a7f8c76e781e7d7f0be7b798db4d344f26bd4facf9abcf3c71c71fe7640"
},
"470.182.03": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/470.182.03/NVIDIA-Linux-x86_64-470.182.03.run",
"sha256": "3dbc1408fc48b865d3ddacefc45f4a3fc13b90b83a628ee546b0082ab2c3fc79"
},
"510.108.03": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/510.108.03/NVIDIA-Linux-x86_64-510.108.03.run",
"sha256": "410a515e78df29c2cba4ac0b497889ce0ff1b04cfc711ff889e2dfc80f0da0d8"
@ -552,10 +547,6 @@
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/515.86.01/NVIDIA-Linux-x86_64-515.86.01.run",
"sha256": "141777e1ca2f11e97d8d33260213f1be327eb73922ae22f4ddab404bb2ef4664"
},
"515.105.01": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/515.105.01/NVIDIA-Linux-x86_64-515.105.01.run",
"sha256": "9dd2221f26c847c864dfe80cc8533f322c5f4dfaa2939cf54a934b8f7a2f6a0d"
},
"525.53": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.53/NVIDIA-Linux-x86_64-525.53.run",
"sha256": "74bb0971f04f1dddd3c4641c891706fb96e8de52e22f6079e50de76d3a51687f"
@ -572,28 +563,8 @@
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.78.01/NVIDIA-Linux-x86_64-525.78.01.run",
"sha256": "43da42d2bf69bc37ea9c7c0fa02f52db0dcc483c272f52edacad89a5cb495a93"
},
"525.85.05": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.85.05/NVIDIA-Linux-x86_64-525.85.05.run",
"sha256": "ea63b4253403b224bb7313a8977a920dfe9d203d661dd5f6fc26585a70179140"
},
"525.89.02": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.89.02/NVIDIA-Linux-x86_64-525.89.02.run",
"sha256": "0e412c88c5bd98f842a839a6f64614f20e4c0950ef7cffb12b158a71633593e9"
},
"525.105.17": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.105.17/NVIDIA-Linux-x86_64-525.105.17.run",
"sha256": "c635a21a282c9b53485f19ebb64a0f4b536a968b94d4d97629e0bc547a58142a"
},
"530.30.02": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/530.30.02/NVIDIA-Linux-x86_64-530.30.02.run",
"sha256": "47fddbbd7a22ba661923dbce6e7f51eec54df68050c406cc0490c3bfbede7963"
},
"530.41.03": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/530.41.03/NVIDIA-Linux-x86_64-530.41.03.run",
"sha256": "ae27a16a968c85503f5d161dda343c1602612b025f4aee15f92e2ea0acb784b1"
},
"latest": {
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/530.41.03/NVIDIA-Linux-x86_64-530.41.03.run",
"sha256": "ae27a16a968c85503f5d161dda343c1602612b025f4aee15f92e2ea0acb784b1"
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.78.01/NVIDIA-Linux-x86_64-525.78.01.run",
"sha256": "43da42d2bf69bc37ea9c7c0fa02f52db0dcc483c272f52edacad89a5cb495a93"
}
}

View File

@ -6,8 +6,7 @@ flake_input@{ kpcli-py
, nickel
, nix-boost
, ...
}:
let
}: let
kpcli-py = (final: prev: {
# use python3.9, which works because of cython somehow?
kpcli-py = final.poetry2nix.mkPoetryApplication {
@ -23,6 +22,7 @@ let
);
kpcli = super.kpcli.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [self.setuptools];
src = old.src;
});
# ubersmith = super.ubersmith.overridePythonAttrs (old: {
@ -53,8 +53,7 @@ let
# https://rust-lang.github.io/rustup/concepts/profiles.html
rust-default-components = [ "rust-docs" "rustfmt" "clippy" ];
rust-dev-components = rust-default-components ++ [ "rust-src" "rust-analyzer" "miri" ];
in
{
in {
rust4devs = nightlyRustWithExts rust-dev-components;
rust4cargo = nightlyRustWithExts [ ];
rust4normi = nightlyRustWithExts rust-default-components;
@ -64,8 +63,7 @@ let
inherit (flake_input.nickel.packages.${system})
lsp-nls nickel nickelWasm;
});
in
[
in [
nix-boost.overlays.default
nixgl.overlays.default
rust-overlay.overlays.default