update with hwtr-prince, everything looks fine

nix-components
pegasust 2022-12-08 02:04:20 -07:00
commit 42c2413ce0
51 changed files with 226 additions and 153 deletions

View File

@ -395,7 +395,7 @@ remap('n', '<leader>gs', function() require('neogit').open({}) end);
-- LSP settings
-- This function gets run when an LSP connects to a particular buffer.
require("inlay-hints").setup {
only_current_line = true,
only_current_line = false,
eol = {
right_align = true,
}
@ -440,10 +440,11 @@ local on_attach = function(client, bufnr)
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
-- enable inlay hints if available
require('inlay-hints').on_attach(client, bufnr)
end, '[W]orkspace [L]ist Folders')
-- enable inlay hints if available
require('inlay-hints').on_attach(client, bufnr)
end
-- nvim-cmp
local cmp = require 'cmp'
@ -521,6 +522,7 @@ cmp.setup {
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
{ name = "conjure" },
-- { name = 'cmp_tabnine' },
},
}
@ -540,6 +542,7 @@ local capabilities = require('cmp_nvim_lsp').default_capabilities()
local servers = {
'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', 'cmake', 'tailwindcss', 'prismals',
'rnix', 'eslint', 'terraformls', 'tflint', 'svelte', 'astro', 'clojure_lsp', "bashls", 'yamlls', "pylsp",
"jsonls", "denols"
}
require("mason").setup({
ui = {
@ -549,12 +552,18 @@ require("mason").setup({
package_uninstalled = ""
},
check_outdated_packages_on_open = true,
}
},
-- 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
PATH = "append";
})
require('mason-lspconfig').setup({
ensure_installed = servers,
automatic_installation = true
})
local inlay_hint_tsjs = {
includeInlayEnumMemberValueHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
@ -606,15 +615,25 @@ require('mason-lspconfig').setup_handlers({
require('lspconfig').tsserver.setup {
on_attach = on_attach,
capabilities = capabilities,
-- TODO: Have to figure out an alternative config for monorepo to prevent
-- Deno from injecting TS projects.
-- Monorepo support: spawn one instance of lsp within the git
-- repos.
root_dir = require('lspconfig.util').root_pattern('.git'),
-- root_dir = require('lspconfig.util').root_pattern('.git'),
root_dir = require('lspconfig.util').root_pattern('package.json'),
settings = {
javascript = inlay_hint_tsjs,
typescript = inlay_hint_tsjs,
}
}
end,
["denols"] = function()
require('lspconfig').denols.setup {
on_attach = on_attach,
capabilities = capabilities,
root_dir = require('lspconfig.util').root_pattern("deno.json", "deno.jsonc"),
}
end,
-- ["rust_analyzer"] = function()
-- require('lspconfig').rust_analyzer.setup {
-- on_attach = on_attach,
@ -660,7 +679,7 @@ require("rust-tools").setup {
inlay_hints = {
-- automatically set inlay hints (type hints)
-- default: true
auto = true,
auto = false,
-- Only show inlay hints for the current line
only_current_line = false,
@ -853,6 +872,7 @@ require('zk.commands').add("ZkOrphans", function(options)
-- zk.edit opens notes picker
require('zk').edit(options, { title = "Zk Orphans (unlinked notes)" })
end)
--
-- ZkGrep: opens file picker
-- In the case where `match_ctor` is falsy, create a prompt.
-- This is so that we distinguish between ZkGrep and ZkNotes
@ -920,6 +940,3 @@ require('lualine').setup {
require('nvim-surround').setup {}
vim.cmd([[
let g:conjure#mapping#doc_word = v:false
]])

View File

@ -28,7 +28,10 @@
system = "x86_64-linux";
overlays = [ nixgl.overlay rust-overlay.overlays.default ];
# pkgs = nixpkgs.legacyPackages.${system}.appendOverlays overlays;
pkgs = import nixpkgs { inherit system overlays; };
pkgs = import nixpkgs {
inherit system overlays;
config = { allowUnfree = true; };
};
lib = (import ../lib-nix { inherit pkgs from-yaml; lib = pkgs.lib; });
in
{
@ -74,22 +77,24 @@
};
};
};
# NOTE: This is never actually tested
"ubuntu_admin" = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home.nix
];
extraSpecialArgs = {
myLib = lib;
myHome = {
username = "ubuntu_admin";
homeDirectory = "/home/ubuntu_admin";
shellInitExtra = ''
'' + x11_wsl;
};
};
};
# NOTE: This is never actually tested. This is for Ubuntu@Felia
# "ubuntu_admin" = home-manager.lib.homeManagerConfiguration {
# inherit pkgs;
# modules = [
# ./home.nix
# ];
# extraSpecialArgs = {
# myLib = lib;
# myHome = {
# username = "ubuntu_admin";
# homeDirectory = "/home/ubuntu_admin";
# shellInitExtra = ''
# '' + x11_wsl;
# };
# };
# };
# Personal laptop
hwtr = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
@ -100,9 +105,9 @@
myHome = {
username = "hwtr";
homeDirectory = "/home/hwtr";
packages = [
pkgs.nixgl.nixGLIntel
# pkgs.postman
packages = [
pkgs.nixgl.nixGLIntel
pkgs.postman
];
shellAliases = {
nixGL = "nixGLIntel";

View File

@ -1,30 +1,48 @@
# myHome is injected from extraSpecialArgs in flake.nix
{ config
, pkgs
, pkgs # This is by default just ``= import <nixpkgs>{}`
, myHome
, ...
}:
let nvim_pkgs = [
# Yes, I desperately want neovim to work out-of-the-box without flake.nix for now
# I want at least python LSP to work everywhere because it's basically
# an alternative to bash script when I move to OpenColo
pkgs.neovim
pkgs.gccStdenv
pkgs.gcc
pkgs.tree-sitter
pkgs.ripgrep
pkgs.fzf
pkgs.sumneko-lua-language-server
pkgs.ripgrep
pkgs.zk
pkgs.fd
# Python3 as alternative to bash scripts :^)
(pkgs.python310Full.withPackages (pypkgs: [
# pypkgs.python-lsp-server # python-lsp. Now we'll have to tell mason to look for this
pypkgs.pynvim # nvim provider
pypkgs.ujson # pylsp seems to rely on this. satisfy it lol
]))
]; in
let
nvim_pkgs = [
# Yes, I desperately want neovim to work out-of-the-box without flake.nix for now
# I want at least python LSP to work everywhere because it's basically
# an alternative to bash script when I move to OpenColo
pkgs.gccStdenv
pkgs.gcc
pkgs.tree-sitter
pkgs.ripgrep
pkgs.fzf
# pkgs.sumneko-lua-language-server
pkgs.ripgrep
pkgs.zk
pkgs.fd
pkgs.stdenv.cc.cc.lib
# Python3 as alternative to bash scripts :^)
# (pkgs.python310Full.withPackages (pypkgs: [
# # python-lsp-server's dependencies is absolutely astronomous
# # pypkgs.python-lsp-server # python-lsp. Now we'll have to tell mason to look for this
# pypkgs.pynvim # nvim provider
# pypkgs.ujson # pylsp seems to rely on this. satisfy it lol
# ]))
];
proj_root = builtins.toString ./../..;
# TODO: put this in a seperate library
# callPackage supports both PATH and function as first param!
yamlToJsonDrv = yamlContent: outputPath: pkgs.callPackage
({ runCommand }:
# runCommand source: https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/trivial-builders.nix#L33
runCommand outputPath { inherit yamlContent; nativeBuildInputs = [ pkgs.yq ]; }
# run yq which outputs '.' (no filter) on file at yamlPath
# note that $out is passed onto the bash/sh script for execution
''
echo "$yamlContent" | yq >$out
'')
{ };
# fromYamlPath = yamlPath: builtins.fromJSON (builtins.readFile (yamlToJsonDrv yamlPath "any-output.json"));
fromYaml = yamlContent: builtins.fromJSON (builtins.readFile (yamlToJsonDrv yamlContent "any_output.json"));
in
{
home = {
username = myHome.username;
@ -32,6 +50,7 @@ let nvim_pkgs = [
stateVersion = myHome.stateVersion or "22.05";
};
home.packages = pkgs.lib.unique ([
pkgs.ncdu
pkgs.htop
pkgs.ripgrep
pkgs.unzip
@ -50,19 +69,16 @@ let nvim_pkgs = [
pkgs.lynx # Web browser at your local terminal
# pkgs.tailscale # VPC;; This should be installed in system-nix
# pkgs.python310 # dev packages should be in jk
pkgs.python310 # dev packages should be in jk
# pkgs.python310.numpy
# pkgs.python310Packages.tensorflow
# pkgs.python310Packages.scikit-learn
] ++ (myHome.packages or [ ]) ++ nvim_pkgs);
## Configs ##
# neovim
xdg.configFile."nvim/init.lua".text = builtins.readFile ../neovim/init.lua;
# starship sh
xdg.configFile."starship.toml".text = builtins.readFile ../starship/starship.toml;
# zk
xdg.configFile."config.toml".text = builtins.readFile ../zk/config.toml;
xdg.configFile."nvim/init.lua".source = "${proj_root}//neovim/init.lua";
xdg.configFile."starship.toml".source = "${proj_root}//starship/starship.toml";
xdg.configFile."zk/config.toml".source = "${proj_root}//zk/config.toml";
## Programs ##
programs.jq = {
@ -70,7 +86,8 @@ let nvim_pkgs = [
};
programs.alacritty = myHome.programs.alacritty or {
enable = true;
# settings = myLib.fromYaml (builtins.readFile ../alacritty/alacritty.yml);
# settings = myLib.fromYaml (builtins.readFile "${proj_root}/alacritty/alacritty.yml");
settings = fromYaml (builtins.readFile "${proj_root}//alacritty/alacritty.yml");
};
# nix: Propagates the environment with packages and vars when enter (children of)
# a directory with shell.nix-compatible and .envrc
@ -86,7 +103,7 @@ let nvim_pkgs = [
};
programs.tmux = {
enable = true;
extraConfig = builtins.readFile ../tmux/tmux.conf;
extraConfig = builtins.readFile "${proj_root}/tmux/tmux.conf";
};
programs.exa = {
enable = true;
@ -98,17 +115,22 @@ let nvim_pkgs = [
};
programs.home-manager.enable = true;
programs.fzf.enable = true;
# programs.neovim = {
# enable = true;
# viAlias = true;
# vimAlias = true;
# withPython3 = true;
# withNodeJs = true;
# # I use vim-plug, so I probably don't require packaging
# # extraConfig actually writes to init-home-manager.vim (not lua)
# # https://github.com/nix-community/home-manager/pull/3287
# # extraConfig = builtins.readFile ../neovim/init.lua;
# };
programs.neovim = {
enable = true;
viAlias = true;
vimAlias = true;
withPython3 = true;
withNodeJs = true;
extraPackages = nvim_pkgs;
# extraPython3Packages = (pypkgs: [
# # pypkgs.python-lsp-server
# pypkgs.ujson
# ]);
# I use vim-plug, so I probably don't require packaging
# extraConfig actually writes to init-home-manager.vim (not lua)
# https://github.com/nix-community/home-manager/pull/3287
# extraConfig = builtins.readFile "${proj_root}/neovim/init.lua";
};
programs.bash = {
enable = true;
enableCompletion = true;
@ -138,11 +160,13 @@ let nvim_pkgs = [
aliases = {
a = "add";
c = "commit";
ca = "commit --ammend";
ca = "commit --amend";
cm = "commit -m";
lol = "log --graph --decorate --pretty=oneline --abbrev-commit";
lola = "log --graph --decorate --pretty=oneline --abbrev-commit --all";
sts = "status";
co = "checkout";
b = "branch";
};
# No idea why this is not appearing in home-manager search
# It's in source code, though
@ -158,8 +182,8 @@ let nvim_pkgs = [
".direnv"
];
extraConfig = {
# cache credential for 10 minutes.
credential.helper = "cache --timeout=600";
# cache credential for 50 minutes (a pomodoro session)
credential.helper = "cache --timeout=3000";
};
# why is this no longer valid?
# pull = { rebase=true; };
@ -167,6 +191,6 @@ let nvim_pkgs = [
programs.ssh = {
enable = true;
forwardAgent = true;
extraConfig = builtins.readFile ../ssh/config;
extraConfig = builtins.readFile "${proj_root}/ssh/config";
};
}

View File

@ -0,0 +1,5 @@
# This module aims to be merge (not inject/override) with top-level pkgs to provide
# personalized/custom packages
{ pkgs, lib, ... }@pkgs_input: {
dot-hwtr = import "./dot-hwtr" pkgs_input;
}

View File

@ -0,0 +1,4 @@
{ pkgs, lib, ... }@pkgs_input: pkgs.stdenv.mkDerivation {
name = "dot-hwtr";
native
}

View File

@ -6,6 +6,7 @@ let
_boot = specialArgs._boot or { };
_services = specialArgs._services or { };
includeHardware = specialArgs.includeHardware or true;
proj_root = builtins.toString ./../..;
in
with lib;
{
@ -16,6 +17,9 @@ with lib;
];
boot = _boot;
# prune old builds
nix.settings.auto-optimise-store = true;
system.stateVersion = "22.05";
# users.users.<defaultUser>.uid = 1000;
# networking.hostName = "nixos";
@ -33,7 +37,7 @@ with lib;
};
users.users.root = {
# openssh runs in root, no? This is because port < 1024 requires root.
openssh.authorizedKeys.keys = lib.strings.splitString "\n" (builtins.readFile ../ssh/authorized_keys);
openssh.authorizedKeys.keys = lib.strings.splitString "\n" (builtins.readFile "${proj_root}/ssh/authorized_keys");
};
# Some basic programs

View File

@ -1,8 +1,6 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, ... }:
@ -36,10 +34,11 @@
prefixLength = 24;
}];
firewall = {
enable = false;
enable = true;
allowedTCPPorts = [ 80 443 22 ];
};
useDHCP = false;
# required so that we get IP address from linode
interfaces.eth0.useDHCP = true;
};
_boot.loader.grub.enable = true;
@ -59,6 +58,7 @@
};
};
};
# Highly suspect that thanks to nginx, ipv6 is disabled?
_services.nginx = {
enable = true;
clientMaxBodySize = "100m"; # Allow big file transfers over git :^)
@ -94,76 +94,7 @@
allowedTCPPorts = [ 80 443 22 ];
};
useDHCP = false;
interfaces.eth0.useDHCP = true;
};
_boot.loader.grub.enable = true;
_boot.loader.grub.version = 2;
_services.openssh = {
permitRootLogin = "no";
enable = true;
};
_services.gitea = {
enable = true;
stateDir = "/gitea";
rootUrl = "https://git.pegasust.com";
settings = {
repository = {
"ENABLE_PUSH_CREATE_USER" = true;
"ENABLE_PUSH_CREATE_ORG" = true;
};
};
};
_services.nginx = {
enable = true;
clientMaxBodySize = "100m"; # Allow big file transfers over git :^)
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
virtualHosts."git.pegasust.com" = {
# Gitea hostname
sslCertificate = "/var/lib/acme/git.pegasust.com/fullchain.pem";
sslCertificateKey = "/var/lib/acme/git.pegasust.com/key.pem";
forceSSL = true; # Runs on port 80 and 443
locations."/".proxyPass = "http://localhost:3000/"; # Proxy to Gitea
};
};
};
};
nixosConfigurations.lester = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
];
specialArgs = {
hostname = "lester";
_networking = {
firewall.enable = true;
useDHCP = false;
interfaces.eth0.useDHCP = true;
};
_boot.loader.grub.enable = true;
_boot.loader.grub.version = 2;
_services.openssh = {
permitRootLogin = "no";
enable = true;
};
};
};
nixosConfigurations.homeless = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
];
specialArgs = {
hostname = "homeless";
_networking = {
firewall = {
enable = false;
allowedTCPPorts = [ 80 443 ];
};
useDHCP = false;
interfaces.eth0.useDHCP = true;
# interfaces.eth0.useDHCP = true;
};
_boot.loader.grub.enable = true;
_boot.loader.grub.version = 2;
@ -207,6 +138,7 @@
specialArgs = {
hostname = "nyx";
_networking = {
enableIPv6 = false;
interfaces.eth1.ipv4.addresses = [{
address = "71.0.0.2";
prefixLength = 24;

31
nixops/simple_hydra.nix Normal file
View File

@ -0,0 +1,31 @@
{
my-hydra = { config, pkgs, ... }: {
# send email
services.postfix = {
enable = true;
setSendmail = true;
};
# postgresql as a build queue (optimization possible?)
services.postgresql = {
enable = true;
package = pkgs.postgresql;
identMap = ''
hydra-users hydra hydra
hydra-users hydra-queue-runner hydra
hydra-users hydra-www hydra
hydra-users root postgres
hydra-users postgres postgres
'';
};
services.hydra = {
enable = true;
useSubstitutes = true;
# hydraURL =
};
networking = {
firewall = {
allowedTCPPorts = [ config.services.hydra.port ];
};
};
};
}

View File

@ -0,0 +1,25 @@
# guide: https://qfpl.io/posts/nix/starting-simple-hydra/
{
my-hydra = { config, pkgs, ... }: {
deployment = {
targetEnv = "virtualbox";
virtualbox.memorySize = 1024; # 1 GB``
virtualbox.vcpu = 2; # 2 vcpus :/ very limited on Linode, sorry
virtualbox.headless = true; # no gui pls
};
services = {
nixosManual.showManual = false; # save space, just no manual on our nix installation
ntp.enable = true; # time daemon
openssh = {
allowSFTP = false; # Prefer using SCP because connection is less verbose (?)
# we are going to generate rsa public key pair to machine
passwordAuthentication = false; # client-pubkey/server-prikey or dig yourself
};
};
users = {
mutableUsers = false; # Remember Trien's Windows freeze function? this is it.
# Yo, allow trusted users through ok?
users.root.openssh.authorizedKeys.keyFiles = [ "ssh/authorizedKeys" ];
};
};
}

View File

@ -1,23 +1,30 @@
#!/usr/bin/env sh
## Configures a new nixos system to this repository
## Blame: Hung Tran (Pegasust) <pegasucksgg@gmail.com>
set -xv
HOSTNAME=${1}
if [ -z $HOSTNAME ]; then
echo "Missing hostname as first param" 1>&2
exit 1
current_hostname=$(hostname)
echo "Missing hostname as first param."
echo "Type the hostname you want to be here"
read -p "[${current_hostname}] > " HOSTNAME
HOSTNAME=${HOSTNAME:-${current_hostname}}
read -p "Using hostname: ${HOSTNAME}. Press ENTER to continue." _WHATEVER_
fi
# Where is this script located
SCRIPT_DIR=$(realpath $(dirname $0))
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
SYSNIX_DIR="${SCRIPT_DIR}/../system-nix"
SYSNIX_DIR="${SCRIPT_DIR}/../nix-conf/system"
# Copy hardware-configuration of existing machine onto our version control
SYSNIX_PROF="${SYSNIX_DIR}/profiles/${HOSTNAME}"
HARDWARE_CONF="${SYSNIX_PROF}/hardware-configuration.nix"
if [ ! -f "${HARDWARE_CONF}" ]; then;
if [ ! -f "${HARDWARE_CONF}" ]; then
mkdir "$SYSNIX_PROF"
sudo cp /etc/nixos/hardware-configuration.nix ${HARDWARE_CONF}
fi

19
scripts/hm-switch.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env sh
# NOTE: Untested on case of no home-manager
set -xv
# Where this script located
SCRIPT_DIR=$(realpath $(dirname $0))
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
HOME_MANAGER_DIR="${SCRIPT_DIR}/../nix-conf/home-manager"
# test if we have home-manager, if not, attempt to use nix to put home-manager to
# our environment
if [ $(home-manager &>/dev/null) ]; then
nix-shell -p home-manager --run "home-manager switch --flake $HOME_MANAGER_DIR"
else
home-manager switch --flake "$HOME_MANAGER_DIR"
fi

0
scripts/sys-switch.sh Executable file
View File