Add kpcli & fix template rust-monorepo bootstrap: corelib instead of core #3

Merged
pegasust merged 18 commits from top-level-wip into master 2022-12-31 10:23:16 +00:00
31 changed files with 1175 additions and 256 deletions

View File

@ -1,4 +1,7 @@
{ {
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.diagnostics.globals": [
"vim",
],
"Lua.workspace.checkThirdParty": false "Lua.workspace.checkThirdParty": false
} }

View File

@ -89,11 +89,11 @@
"utils": "utils" "utils": "utils"
}, },
"locked": { "locked": {
"lastModified": 1671966569, "lastModified": 1672349765,
"narHash": "sha256-jbLgfSnmLchARBNFRvCic63CFQ9LAyvlXnBpc2kwjQc=", "narHash": "sha256-Ul3lSGglgHXhgU3YNqsNeTlRH1pqxbR64h+2hM+HtnM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "c55fa26ce05fee8e063db22918d05a73d430b2ea", "rev": "dd99675ee81fef051809bc87d67eb07f5ba022e8",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -102,6 +102,22 @@
"type": "github" "type": "github"
} }
}, },
"kpcli-py": {
"flake": false,
"locked": {
"lastModified": 1619087457,
"narHash": "sha256-iRNLq5s2WJJHwB4beP5xQDKrBPWS/42s/ozLoSa5gAE=",
"owner": "rebkwok",
"repo": "kpcli",
"rev": "e4d699e3b3d28887f74185f8fa69d0aade111d84",
"type": "github"
},
"original": {
"owner": "rebkwok",
"repo": "kpcli",
"type": "github"
}
},
"nixgl": { "nixgl": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2", "flake-utils": "flake-utils_2",
@ -138,11 +154,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1671983799, "lastModified": 1672262501,
"narHash": "sha256-Z2Ro6hFPZHkBqkVXY5/aBUzxi5xizQGvuHQ9+T5B/ks=", "narHash": "sha256-ZNXqX9lwYo1tOFAqrVtKTLcJ2QMKCr3WuIvpN8emp7I=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "fad51abd42ca17a60fc1d4cb9382e2d79ae31836", "rev": "e182da8622a354d44c39b3d7a542dc12cd7baa5f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -173,6 +189,7 @@
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"home-manager": "home-manager", "home-manager": "home-manager",
"kpcli-py": "kpcli-py",
"nixgl": "nixgl", "nixgl": "nixgl",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
@ -184,11 +201,11 @@
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
"lastModified": 1672107670, "lastModified": 1672367043,
"narHash": "sha256-m4kP+8k46JwSXYDugykIVvRyoNofZDG7atjbi5+sLoU=", "narHash": "sha256-4/40kfJysfDEfSpXJ3inuMetn40czz5Mh73SjxsKTX0=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "f4827ef0518463f31a52ab2e5c500c80558fdd78", "rev": "e6b2214363f5e18576a3b2ca0e0483d8f42fe531",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -18,6 +18,10 @@
url = "github:edolstra/flake-compat"; url = "github:edolstra/flake-compat";
flake = false; flake = false;
}; };
kpcli-py = {
url = "github:rebkwok/kpcli";
flake = false;
};
}; };
outputs = { outputs = {
@ -29,6 +33,7 @@
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
overlays = import ./overlays.nix _inputs;
config = { config = {
allowUnfree = true; allowUnfree = true;
}; };
@ -89,7 +94,7 @@
unit_tests = lib.runTests unit_tests; unit_tests = lib.runTests unit_tests;
secrets = import ./secrets final_inputs; secrets = import ./secrets final_inputs;
debug = { debug = {
inherit final_inputs hosts users modules lib inputs_w_pkgs unit_tests; inherit final_inputs hosts users modules lib inputs_w_pkgs unit_tests pkgs;
}; };
}; };
} }

View File

@ -50,7 +50,7 @@ in {
}; };
mkHostFromPropagated = propagatedHostConfig@{nixosConfig,...}: nixpkgs.lib.nixosSystem nixosConfig; mkHostFromPropagated = propagatedHostConfig@{nixosConfig,...}: nixpkgs.lib.nixosSystem nixosConfig;
mkHost = hostConfig: (lib.pipe [propagate mkHostFromPropagated] hostConfig); mkHost = hostConfig: (lib.pipe [propagate mkHostFromPropagated] hostConfig);
trimNull = lib.filterAttrs (name: value: value != null); trimNull = lib.filterAttrsRecursive (name: value: value != null);
flattenPubkey = lib.mapAttrs (hostName: meta_config: meta_config.metadata.ssh_pubkey); flattenPubkey = lib.mapAttrs (hostName: meta_config: meta_config.metadata.ssh_pubkey);
in { in {
inherit config; inherit config;

View File

@ -836,6 +836,7 @@ key_bindings:
# (Windows, Linux, and BSD only) # (Windows, Linux, and BSD only)
- { key: V, mods: Control|Shift, mode: ~Vi, action: Paste } - { key: V, mods: Control|Shift, mode: ~Vi, action: Paste }
- { key: C, mods: Control|Shift, action: Copy } - { key: C, mods: Control|Shift, action: Copy }
- { key: Return, mods: Alt, action: ToggleFullscreen }
#- { key: F, mods: Control|Shift, mode: ~Search, action: SearchForward } #- { key: F, mods: Control|Shift, mode: ~Search, action: SearchForward }
#- { key: B, mods: Control|Shift, mode: ~Search, action: SearchBackward } #- { key: B, mods: Control|Shift, mode: ~Search, action: SearchBackward }
#- { key: C, mods: Control|Shift, mode: Vi|~Search, action: ClearSelection } #- { key: C, mods: Control|Shift, mode: Vi|~Search, action: ClearSelection }
@ -847,9 +848,6 @@ key_bindings:
#- { key: Minus, mods: Control, action: DecreaseFontSize } #- { key: Minus, mods: Control, action: DecreaseFontSize }
#- { key: NumpadSubtract, mods: Control, action: DecreaseFontSize } #- { key: NumpadSubtract, mods: Control, action: DecreaseFontSize }
# (Windows only)
#- { key: Return, mods: Alt, action: ToggleFullscreen }
# (macOS only) # (macOS only)
#- { key: K, mods: Command, mode: ~Vi|~Search, chars: "\x0c" } #- { key: K, mods: Command, mode: ~Vi|~Search, chars: "\x0c" }
#- { key: K, mods: Command, mode: ~Vi|~Search, action: ClearHistory } #- { key: K, mods: Command, mode: ~Vi|~Search, action: ClearHistory }

View File

@ -94,6 +94,25 @@ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
endif endif
]]) ]])
-- special terminals, place them at 4..=7 for ergonomics
vim.api.nvim_create_autocmd({"VimEnter"}, {
callback = function()
local function named_term(term_idx, term_name)
require('harpoon.term').gotoTerminal(term_idx)
vim.cmd([[:exe ":file ]]..term_name..[[" | :bfirst]])
end
-- term:ctl at 4
named_term(4, "term:ctl")
-- term:dev at 5
named_term(5, "term:dev")
-- term:repl at 7
named_term(7, "term:repl")
-- term:repl at 6
named_term(6, "term:repl2")
end
})
vim.cmd([[ vim.cmd([[
set ignorecase set ignorecase
set smartcase set smartcase
@ -129,9 +148,13 @@ vim.g.mapleader = ' '
vim.g.maplocalleader = ',' vim.g.maplocalleader = ','
-- basic keymaps -- basic keymaps
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) -- since we're using space for leader -- Since we use space for leader, we're asserting that this does nothing by itself
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>)') -- make :terminal escape out vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
vim.keymap.set({ 'n', 'i', 'v' }, '<c-l>', '<Cmd>:mode<Cr>') -- redraw on every mode -- make :terminal escape out. For zsh-vi-mode, just use Alt-Z or any keybind
-- that does not collide with vi-motion keybind. This is because
-- <Alt-x> -> ^[x; while <Esc> on the terminal is ^[
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>)')
vim.keymap.set({ 'n', 'i', 'v' }, '<c-l>', '<Cmd>mode<Cr>', {desc = ""}) -- redraw on every mode
-- diagnostics (errors/warnings to be shown) -- diagnostics (errors/warnings to be shown)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
@ -364,13 +387,15 @@ require('guess-indent').setup {
}, },
} }
-- harpoon: mark significant files & switch between them -- harpoon: O(1) buffer/terminal switching
remap('n', '<leader>m', function() require('harpoon.mark').add_file() end) remap('n', '<leader>m', function() require('harpoon.mark').add_file() end, { desc = "[H]arpoon [M]ark" })
local function harpoon_nav(key, nav_file_index, lead_keybind) local function harpoon_nav(key, nav_file_index, lead_keybind)
lead_keybind = lead_keybind or '<leader>h' lead_keybind = lead_keybind or '<leader>h'
assert(type(key) == "string", "expect key to be string(keybind)") assert(type(key) == "string", "expect key to be string(keybind)")
assert(type(nav_file_index) == "number" and nav_file_index >= 1, "expect 1-indexed number for file index") assert(type(nav_file_index) == "number" and nav_file_index >= 1, "expect 1-indexed number for file index")
return remap('n', lead_keybind .. key, function() require('harpoon.ui').nav_file(nav_file_index) end) return remap('n', lead_keybind .. key,
function() require('harpoon.ui').nav_file(nav_file_index) end,
{ desc = "[H]arpoon navigate " .. tostring(nav_file_index) })
end end
-- remap letters to index. Inspired by alternating number of Dvorak programmer -- remap letters to index. Inspired by alternating number of Dvorak programmer
@ -380,21 +405,18 @@ harpoon_nav('j', 2)
harpoon_nav('d', 3) harpoon_nav('d', 3)
harpoon_nav('k', 4) harpoon_nav('k', 4)
remap('n', '<leader>hh', function() require('harpoon.ui').toggle_quick_menu() end) remap('n', '<leader>hh', function() require('harpoon.ui').toggle_quick_menu() end)
-- harpoon: navigate by numbers for i = 1, 10 do
harpoon_nav('1', 1) -- harpoon: navigate files by numbers
harpoon_nav('2', 2) harpoon_nav(tostring(i % 10), i)
harpoon_nav('3', 3) -- harpoon: navigate terms by numbers
harpoon_nav('4', 4) remap('n', '<leader>t' .. tostring(i % 10), function()
harpoon_nav('5', 5) require('harpoon.term').gotoTerminal(i)
harpoon_nav('6', 6) end)
harpoon_nav('7', 7) end
harpoon_nav('8', 8)
harpoon_nav('9', 9)
harpoon_nav('0', 10)
-- neogit: easy-to-see git status. Provides only productivity on staging/unstage -- neogit: easy-to-see git status. Provides only productivity on staging/unstage
require('neogit').setup {} require('neogit').setup {}
remap('n', '<leader>gs', function() require('neogit').open({}) end); remap('n', '<leader>gs', function() require('neogit').open({}) end, { desc = "[G]it [S]tatus" });
-- LSP settings -- LSP settings
-- This function gets run when an LSP connects to a particular buffer. -- This function gets run when an LSP connects to a particular buffer.

View File

@ -0,0 +1,46 @@
{ pkgs, config, lib, ... }:
let
cfg = config.base.graphics;
cfgEnable = cfg.enable or cfg.useNixGLPackage != null;
types = lib.types;
in
{
imports = [ ./shells.nix ];
options.base.graphics = {
enable = lib.mkEnableOption "graphics";
_enable = lib.mkOption {
type = types.bool;
description = "Whether the graphics is implicitly enabled (final)";
internal = true;
default = false;
};
useNixGL = {
package = lib.mkPackageOption pkgs "nixGL package" {
default = [
"nixgl"
"auto"
"nixGLDefault"
];
};
defaultPackage = lib.mkOption {
type = types.nullOr (types.enum [ "nixGLIntel" "nixGLNvidia" "nixGLNvidiaBumblebee" ]);
description = "Which nixGL package to be aliased as `nixGL` on the shell";
default = null;
example = "nixGLIntel";
};
};
};
# importing shells does not mean we're enabling everything, if we do mkDefault false
# but the dilemma is, if the user import BOTH graphics.nix and shells.nix
# they will also need to do `config.base.shells.enable`
# generally, we want the behavior: import means enable
config = lib.mkIf cfgEnable {
base.graphics._enable = cfgEnable;
base.shells = {
shellAliases = lib.mkIf (cfg.useNixGL.defaultPackage != null) {
nixGL = cfg.useNixGL.defaultPackage;
};
};
home.packages = [ cfg.useNixGL.package ];
};
}

View File

@ -0,0 +1,64 @@
{ config, proj_root, pkgs, lib, ... }:
let
cfg = config.base.keepass;
trimNull = lib.filterAttrsRecursive (name: value: value != null);
in
{
imports = [ ./graphics.nix ];
options.base.keepass = {
enable = lib.mkEnableOption "keepass";
use_gui = lib.mkOption {
type = lib.types.bool;
description = "wheter to enable keepass GUI (the original one)";
default = false;
example = "true";
};
path = lib.mkOption {
type = lib.types.path;
description = "Path to kdbx file";
default = null;
example = "/media/homelab/f/PersistentHotStorage/keepass.kdbx";
};
keyfile_path = lib.mkOption {
type = lib.types.nullOr lib.types.path;
description = ''
Path to key file for the database
If null, then the field is unset
'';
default = null;
example = "/path/to/mykeyfile.key";
};
store_encrypted_password = lib.mkOption {
type = lib.types.bool;
description = "Whether to store encrypted password for 24 hrs before re-prompt";
default = true;
example = "false";
};
copy_timeout_secs = lib.mkOption {
type = lib.types.int;
description = "Timeout (seconds) before the password is expired from clipboard";
default = 12;
example = "60";
};
};
config = lib.mkIf cfg.enable {
home.packages = [
pkgs.kpcli-py # kp but is in cli
] ++ (if cfg.use_gui or config.base.graphics._enable then [
pkgs.keepass # Personal secret management
] else [ ]);
home.file.".kp/config.ini".text = lib.generators.toINI {} (trimNull {
default = {
KEEPASSDB = cfg.path;
KEEPASSDB_KEYFILE = cfg.keyfile_path;
STORE_ENCRYPTED_PASSWORD = cfg.store_encrypted_password;
KEEPASSDB_PASSWORD = null; # No good way yet to store the password
KEEPASSDB_TIMEOUT = cfg.copy_timeout_secs;
};
});
# xdg.dataFile."keepass.kdbx".path =
# base.shells.shellAliases = {
# kp = "kpcli --kdb=${cfg.path}";
# };
};
}

View File

@ -0,0 +1,94 @@
# TODO: vim-plug and Mason supports laziness. Probably worth it to explore
# incremental dependencies based on the project
#
# One thing to consider, though, /nix/store of `nix-shell` or `nix-develop`
# might be different from `home-manager`'s
{ pkgs, lib, config, proj_root, ... }:
let
# NOTE: Failure 1: buildInputs is pretty much ignored
# my_neovim = pkgs.neovim-unwrapped.overrideDerivation (old: {
# # TODO: is there a more beautiful way to override propagatedBuildInputs?
# name = "hungtr-" + old.name;
# buildInputs = (old.buildInputs or []) ++ [
# pkgs.tree-sitter # highlighting
# rust_pkgs # for potentially rust-analyzer
# pkgs.fzf
# pkgs.ripgrep
# pkgs.zk
# pkgs.fd
# ];
# NOTE: Failure 2: propagatedBuildInputs probably only concerns dyn libs
# });
# NOTE: Failure 3: must be unwrapped neovim because home-manager does the wrapping
# my_neovim = pkgs.neovim;
# NOTE: Add packages to nvim_pkgs instead, so that it's available at userspace
# and is added to the path after wrapping.
# check: nix repl `homeConfigurations.hungtr.config.programs.neovim.finalPackage.buildCommand`
# see: :/--suffix.*PATH
# there should be mentions of additional packages
my_neovim = pkgs.neovim-unwrapped;
rust_pkgs = (pkgs.rust-bin.selectLatestNightlyWith
(
toolchain:
toolchain.default.override {
extensions = [ "rust-src" ];
}
));
nvim_pkgs = [
# pkgs.gccStdenv
pkgs.gcc
pkgs.tree-sitter
pkgs.fzf # file name fuzzy search
pkgs.ripgrep # content fuzzy search
pkgs.zk # Zettelkasten (limited support)
pkgs.fd # Required by a Telescope plugin (?)
pkgs.stdenv.cc.cc.lib
# Language-specific stuffs
pkgs.sumneko-lua-language-server
pkgs.rust-analyzer
rust_pkgs
pkgs.evcxr # Rust REPL for Conjure!
# 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
# ]))
];
in
{
options.base.neovim = {
enable = lib.mkOption {
default = true;
description = "enable personalized neovim as default editor";
type = lib.types.bool;
example = false;
};
};
config = lib.mkIf config.base.neovim.enable {
programs.neovim = {
enable = true;
package = my_neovim;
viAlias = true;
vimAlias = true;
withPython3 = true;
withNodeJs = true;
extraPackages = nvim_pkgs;
# only for here for archive-documentation
# 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";
};
# home.packages = nvim_pkgs;
xdg.configFile."nvim/init.lua".source = "${proj_root.config.path}//neovim/init.lua";
};
}

View File

@ -3,6 +3,7 @@
{ config { config
, proj_root , proj_root
, myLib , myLib
, pkgs
, ... , ...
}: }:
let cfg = config.base.shells; let cfg = config.base.shells;
@ -81,9 +82,28 @@ in
}; };
oh-my-zsh = { oh-my-zsh = {
enable = true; enable = true;
plugins = [ "git" "sudo" "command-not-found" "gitignore" "ripgrep" "rust" ]; plugins = [
"git" # git command aliases: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git#aliases
# "sudo" # double-escape to prepend sudo # UPDATE: just use vi-mode lol
"command-not-found" # suggests which package to install; does not support nixos (we have solution already)
"gitignore" # `gi list` -> `gi java >>.gitignore`
"ripgrep" # adds completion for `rg`
"rust" # compe for rustc/cargo
# "vi-mode" # edit promps with vi motions :)
];
}; };
initExtra = cfg.shellInitExtra or ""; sessionVariables = {
# VI_MODE_RESET_PROMPT_ON_MODE_CHANGE = true;
# VI_MODE_SET_CURSOR = true;
# ZVM_VI_ESCAPE_BINDKEY = "";
ZVM_READKEY_ENGINE="$ZVM_READKEY_ENGINE_NEX";
ZVM_KEYTIMEOUT=0.004; # 40ms, or subtly around 25 FPS. I'm a gamer :)
ZVM_ESCAPE_KEYTIMEOUT=0.004; # 40ms, or subtly around 25 FPS. I'm a gamer :)
};
initExtra = (cfg.shellInitExtra or "") + ''
source ${pkgs.zsh-vi-mode}/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
'';
}; };
}; };
} }

View File

@ -69,11 +69,11 @@
"utils": "utils" "utils": "utils"
}, },
"locked": { "locked": {
"lastModified": 1670970889, "lastModified": 1672349765,
"narHash": "sha256-TWJo3/X3Q3r+HeX16QN4FE6ddBpGtAboymSEF+4Nnc0=", "narHash": "sha256-Ul3lSGglgHXhgU3YNqsNeTlRH1pqxbR64h+2hM+HtnM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "e412025fffdcd6219ddd21c65d9a1b90005ce508", "rev": "dd99675ee81fef051809bc87d67eb07f5ba022e8",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -82,23 +82,36 @@
"type": "github" "type": "github"
} }
}, },
"kpcli-py": {
"flake": false,
"locked": {
"lastModified": 1619087457,
"narHash": "sha256-iRNLq5s2WJJHwB4beP5xQDKrBPWS/42s/ozLoSa5gAE=",
"owner": "rebkwok",
"repo": "kpcli",
"rev": "e4d699e3b3d28887f74185f8fa69d0aade111d84",
"type": "github"
},
"original": {
"owner": "rebkwok",
"repo": "kpcli",
"type": "github"
}
},
"nixgl": { "nixgl": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2", "flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1661367362, "lastModified": 1,
"narHash": "sha256-Qc8MXcV+YCPREu8kk6oggk23ZBKLqeQRAIsLbHEviPE=", "narHash": "sha256-KP+2qdZlhmRkrafuuEofg7YnNdVmGV95ipvpuqmJneI=",
"owner": "guibou", "path": "/nix/store/qcm4676fqkcdrizjkn4j0796ybddwlxm-source/out-of-tree/nixGL",
"repo": "nixGL", "type": "path"
"rev": "7165ffbccbd2cf4379b6cd6d2edd1620a427e5ae",
"type": "github"
}, },
"original": { "original": {
"owner": "guibou", "path": "/nix/store/qcm4676fqkcdrizjkn4j0796ybddwlxm-source/out-of-tree/nixGL",
"repo": "nixGL", "type": "path"
"type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
@ -118,11 +131,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1670929434, "lastModified": 1672262501,
"narHash": "sha256-n5UBO6XBV4h3TB7FYu2yAuNQMEYOrQyKeODUwKe06ow=", "narHash": "sha256-ZNXqX9lwYo1tOFAqrVtKTLcJ2QMKCr3WuIvpN8emp7I=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "1710ed1f6f8ceb75cf7d1cf55ee0cc21760e1c7a", "rev": "e182da8622a354d44c39b3d7a542dc12cd7baa5f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -153,6 +166,7 @@
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"home-manager": "home-manager", "home-manager": "home-manager",
"kpcli-py": "kpcli-py",
"nixgl": "nixgl", "nixgl": "nixgl",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
@ -164,11 +178,11 @@
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
"lastModified": 1671071423, "lastModified": 1672367043,
"narHash": "sha256-zUldhyWANdgko+lqQuB1Eee7TyYya1KiOS0SCd/Y268=", "narHash": "sha256-4/40kfJysfDEfSpXJ3inuMetn40czz5Mh73SjxsKTX0=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "684659b7ca903e512a421bc6ade689fb26e509b4", "rev": "e6b2214363f5e18576a3b2ca0e0483d8f42fe531",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -7,26 +7,31 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
nixgl.url = "github:guibou/nixGL"; nixgl.url = "./../../out-of-tree/nixGL";
rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.url = "github:oxalica/rust-overlay";
# Allows default.nix to call onto flake.nix. Useful for nix eval and automations # Allows default.nix to call onto flake.nix. Useful for nix eval and automations
flake-compat = { flake-compat = {
url = "github:edolstra/flake-compat"; url = "github:edolstra/flake-compat";
flake = false; flake = false;
}; };
kpcli-py = {
url = "github:rebkwok/kpcli";
flake = false;
};
}; };
outputs = outputs =
{ nixpkgs flake_inputs@{ nixpkgs
, home-manager , home-manager
, nixgl , nixgl
, rust-overlay , rust-overlay
, flake-utils , flake-utils
, kpcli-py
, ... , ...
}: }:
let let
system = "x86_64-linux"; system = "x86_64-linux";
overlays = [ nixgl.overlay rust-overlay.overlays.default ]; overlays = import ./../../overlays.nix flake_inputs;
# pkgs = nixpkgs.legacyPackages.${system}.appendOverlays overlays; # pkgs = nixpkgs.legacyPackages.${system}.appendOverlays overlays;
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system overlays; inherit system overlays;
@ -47,6 +52,9 @@
}; };
in in
{ {
debug = {
inherit overlays pkgs base;
};
homeConfigurations = homeConfigurations =
let x11_wsl = '' let x11_wsl = ''
# x11 output for WSL # x11 output for WSL
@ -133,22 +141,20 @@
inherit pkgs; inherit pkgs;
modules = base.modules ++ [ modules = base.modules ++ [
./home.nix ./home.nix
./base/graphics.nix
{ {
base.graphics.enable = true;
base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font"; base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font";
base.shells = { base.keepass.path = "/media/homelab/f/PersistentHotStorage/keepass.kdbx";
shellAliases = {
nixGL = "nixGLIntel";
};
};
} }
]; ];
extraSpecialArgs = mkModuleArgs { extraSpecialArgs = mkModuleArgs {
inherit pkgs; inherit pkgs;
myHome = { myHome = {
username = "hwtr"; username = "hwtr";
homeDirectory = "/home/hwtr"; homeDirectory = "/home/hwtr";
packages = [ packages = [
pkgs.nixgl.nixGLIntel
pkgs.postman pkgs.postman
]; ];
}; };

View File

@ -12,62 +12,13 @@
, ... , ...
}: }:
let 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.fzf # file name fuzzy search
pkgs.sumneko-lua-language-server
pkgs.ripgrep # content fuzzy search
pkgs.zk # Zettelkasten (limited support)
pkgs.fd # Required by a Telescope plugin (?)
pkgs.stdenv.cc.cc.lib
rust_pkgs
pkgs.rust-analyzer
# 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
# ]))
];
rust_pkgs = (pkgs.rust-bin.selectLatestNightlyWith
(
toolchain:
toolchain.default.override {
extensions = [ "rust-src" ];
}
));
# NOTE: Failure 1: buildInputs is pretty much ignored
# my_neovim = pkgs.neovim-unwrapped.overrideDerivation (old: {
# # TODO: is there a more beautiful way to override propagatedBuildInputs?
# name = "hungtr-" + old.name;
# buildInputs = (old.buildInputs or []) ++ [
# pkgs.tree-sitter # highlighting
# rust_pkgs # for potentially rust-analyzer
# pkgs.fzf
# pkgs.ripgrep
# pkgs.zk
# pkgs.fd
# ];
# NOTE: Failure 2: propagatedBuildInputs probably only concerns dyn libs
# });
# NOTE: Failure 3: must be unwrapped neovim because home-manager does the wrapping
# my_neovim = pkgs.neovim;
# NOTE: Add packages to nvim_pkgs instead, so that it's available at userspace
# and is added to the path after wrapping.
# check: nix repl `homeConfigurations.hungtr.config.programs.neovim.finalPackage.buildCommand`
# see: :/--suffix.*PATH
# there should be mentions of additional packages
my_neovim = pkgs.neovim-unwrapped;
inherit (myLib) fromYaml; inherit (myLib) fromYaml;
in in
{ {
imports = [
./base/neovim.nix
./base/keepass.nix
];
home = { home = {
username = myHome.username; username = myHome.username;
homeDirectory = myHome.homeDirectory; homeDirectory = myHome.homeDirectory;
@ -83,14 +34,12 @@ in
# cool utilities # cool utilities
pkgs.yq # Yaml adaptor for jq (only pretty print, little query) pkgs.yq # Yaml adaptor for jq (only pretty print, little query)
pkgs.xorg.xclock # TODO: only include if have GL # For testing GL installation pkgs.xorg.xclock # TODO: only include if have gui # For testing GL installation
pkgs.logseq # TODO: only include if have GL # Obsidian alt pkgs.logseq # TODO: only include if have GL # Obsidian alt
pkgs.mosh # Parsec for SSH 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.lynx # Web browser at your local terminal
pkgs.zk
# Personal management
pkgs.keepass # password manager. wish there is a keepass-query
# pkgs.tailscale # VPC;; This should be installed in system-nix # pkgs.tailscale # VPC;; This should be installed in system-nix
pkgs.python310 # dev packages should be in project pkgs.python310 # dev packages should be in project
@ -98,36 +47,15 @@ in
# pkgs.python310Packages.tensorflow # pkgs.python310Packages.tensorflow
# pkgs.python310Packages.scikit-learn # pkgs.python310Packages.scikit-learn
] ++ (myHome.packages or [ ]) ] ++ (myHome.packages or [ ])
# ++ nvim_pkgs
); );
## Configs ## ## Configs ##
xdg.configFile."nvim/init.lua".source = "${proj_root.config.path}//neovim/init.lua";
xdg.configFile."zk/config.toml".source = "${proj_root.config.path}//zk/config.toml"; xdg.configFile."zk/config.toml".source = "${proj_root.config.path}//zk/config.toml";
## Programs ## ## Programs ##
programs.jq = { programs.jq = {
enable = true; enable = true;
}; };
# TODO: override the original package, inject tree-sitter and stuffs
programs.neovim = {
enable = true;
package = my_neovim;
viAlias = true;
vimAlias = true;
withPython3 = true;
withNodeJs = true;
extraPackages = nvim_pkgs;
# only for here for archive-documentation
# 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";
};
# not exist in home-manager # not exist in home-manager
# have to do it at system level # have to do it at system level
# services.ntp.enable = true; # automatic time # services.ntp.enable = true; # automatic time
@ -136,4 +64,5 @@ in
enableBashIntegration = true; enableBashIntegration = true;
enableZshIntegration = true; enableZshIntegration = true;
}; };
base.keepass.enable = true;
} }

View File

@ -209,106 +209,7 @@
specialArgs.hostname = "bao"; specialArgs.hostname = "bao";
modules = base_modules ++ [ modules = base_modules ++ [
./configuration.nix ./configuration.nix
# automount using s3fs ./../../modules/storage.perso.sys.nix
({config, pkgs, lib, ...}: {
environment.systemPackages = [
pkgs.s3fs pkgs.cifs-utils pkgs.lm_sensors pkgs.hddtemp
]; # s3fs-fuse
# Sadly, autofs uses systemd, so we can't put it in home-manager
# HACK: need to store secret somewhere so that root can access this
# because autofs may run as root for now, we enforce putting the secret in this monorepo
# services.rpcbind.enable = true;
services.autofs = let
# confToBackendArg {lol="what"; empty=""; name_only=null;} -> "lol=what,empty=,name_only"
# TODO: change null -> true/false. This allows overriding & better self-documentation
confToBackendArg = conf: (lib.concatStringsSep ","
(lib.mapAttrsToList (name: value: "${name}${lib.optionalString (value != null) "=${value}"}") conf));
# mount_dest: path ("wow")
# backend_args: nix attrs representing the arguments to be passed to s3fs
# ({"-fstype" = "fuse"; "use_cache" = "/tmp";})
# bucket: bucket name (hungtr-hot)
# NOTE: s3 custom provider will be provided inside
# backend_args, so just put the bucket name here
#
#-> "${mount_dest} ${formatted_args} ${s3fs-bin}#${bucket}"
autofs-s3fs_entry = {
mount_dest,
backend_args? {"-fstype" = "fuse";},
bucket
}@inputs: let
s3fs-exec = "${pkgs.s3fs}/bin/s3fs";
in "${mount_dest} ${confToBackendArg backend_args} :${s3fs-exec}\#${bucket}";
personalStorage = [
# hungtr-hot @ phoenix is broken :)
# (autofs-s3fs_entry {
# mount_dest = "hot";
# backend_args = {
# "-fstype" = "fuse";
# use_cache = "/tmp";
# del_cache = null;
# allow_other = null;
# url = ''"https://f5i0.ph.idrivee2-32.com"'';
# # TODO: builtins.readFile requires a Git-controlled file
# passwd_file = config.age.secrets.s3fs.path;
# dbglevel = "debug"; # enable this for better debugging info in journalctl
# uid = "1000"; # default user
# gid = "100"; # users
# umask="003"; # others read only, fully shared for users group
# # _netdev = null; # ignored by s3fs (https://github.com/s3fs-fuse/s3fs-fuse/blob/master/src/s3fs.cpp#L4910)
# };
# bucket = "hungtr-hot";
# })
(autofs-s3fs_entry {
mount_dest = "garden";
backend_args = {
"-fstype" = "fuse";
use_cache = "/tmp";
del_cache = null;
allow_other = null;
url = "https://v5h5.la11.idrivee2-14.com";
passwd_file = config.age.secrets."s3fs.digital-garden".path;
dbglevel = "debug"; # enable this for better debugging info in journalctl
uid = "1000"; # default user
gid = "100"; # users
umask="003"; # others read only, fully shared for users group
};
bucket = "digital-garden";
})
(let args = {
"-fstype" = "cifs";
credentials = config.age.secrets._nhitrl_cred.path;
user = null;
uid = "1001";
gid = "100";
dir_mode = "0777";
file_mode = "0777";
};
in "felia_d ${confToBackendArg args} ://felia.coati-celsius.ts.net/d")
(let args = {
"-fstype" = "cifs";
credentials = config.age.secrets._nhitrl_cred.path;
user = null;
uid = "1001";
gid = "100";
dir_mode = "0777";
file_mode = "0777";
};
in "felia_f ${confToBackendArg args} ://felia.coati-celsius.ts.net/f")
];
persoConf = pkgs.writeText "auto.personal" (builtins.concatStringsSep "\n" personalStorage);
in {
enable = true;
# Creates /perso directory with every subdirectory declared by ${personalStorage}
# as of now (might be stale), /perso/hot is the only mount accessible
# that is also managed by s3fs
autoMaster = ''
/perso file:${persoConf}
'';
timeout = 30; # default: 600, 600 seconds (10 mins) of inactivity => unmount
# debug = true; # writes to more to journalctl
};
})
# GPU, sound, networking stuffs # GPU, sound, networking stuffs
({ config, pkgs, lib, ... }: ({ config, pkgs, lib, ... }:
let let

View File

@ -0,0 +1,19 @@
name: Test
on: [ push, pull_request ]
jobs:
test:
name: 'Test'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.2
- uses: cachix/install-nix-action@v17
- uses: cachix/cachix-action@v10
with:
name: guibou
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build all
run: nix-build all.nix

248
out-of-tree/nixGL/README.md Normal file
View File

@ -0,0 +1,248 @@
# NixGL
NixGL solve the "OpenGL" problem with [nix](https://nixos.org/nix/). It works with all mesa drivers (Intel cards and "free" version for Nvidia or AMD cards), Nvidia proprietary drivers, and even with hybrid configuration via bumblebee. It works for Vulkan programs too.
# Motivation
Using Nix on non-NixOS distros, it's common to see GL application errors:
```bash
$ program
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
```
NixGL provides a set of wrappers able to launch GL or Vulkan applications:
```bash
$ nixGL program
$ nixVulkan program
```
# Installation
## nix-channel (Recommended)
To get started,
```bash
$ nix-channel --add https://github.com/guibou/nixGL/archive/main.tar.gz nixgl && nix-channel --update
$ nix-env -iA nixgl.auto.nixGLDefault # or replace `nixGLDefault` with your desired wrapper
```
Many wrappers are available, depending on your hardware and the graphical API you want to use (i.e. Vulkan or OpenGL). You may want to install a few of them, for example if you want to support OpenGL and Vulkan on a laptop with an hybrid configuration.
OpenGL wrappers:
- `auto.nixGLDefault`: Tries to auto-detect and install Nvidia, if not, fallback to mesa. Recommended. Invoke with `nixGL program`.
- `auto.nixGLNvidia`: Proprietary Nvidia driver (auto detection of version)
- `auto.nixGLNvidiaBumblebee`: Proprietary Nvidia driver on hybrid hardware (auto detection).
- `nixGLIntel`: Mesa OpenGL implementation (intel, amd, nouveau, ...).
Vulkan wrappers:
- `auto.nixVulkanNvidia`: Proprietary Nvidia driver (auto detection).
- `nixVulkanIntel`: Mesa Vulkan implementation.
The Vulkan wrapper also sets `VK_LAYER_PATH` the validation layers in the nix store.
## Flakes
### Directly run nixGL
You need to specify the same version of `nixpkgs` that your `program` is using. For example, replace `nixos-21.11` with `nixos-21.05`.
```sh
nix run --override-input nixpkgs nixpkgs/nixos-21.11 --impure github:guibou/nixGL -- program
```
If you use the default `nixpkgs` channel (i.e. `nixpkgs-unstable`), you can ommit those arguments like so:
```sh
nix run --impure github:guibou/nixGL -- program
```
You can also specify which wrapper to use instead of using the default auto detection:
```sh
nix run github:guibou/nixGL#nixGLIntel -- program
```
This will result in a lighter download and execution time. Also, this evaluation is pure.
#### Error about experimental features
You can directly use:
```sh
nix --extra-experimental-features "nix-command flakes" run --impure github:guibou/nixGL -- program
```
Or set the appropriate conf in `~/.config/nix/nix.conf` / `/etc/nix/nix.conf` / `nix.extraOptions`.
#### Error with GLIBC version
if you get errors with messages similar to
```
/nix/store/g02b1lpbddhymmcjb923kf0l7s9nww58-glibc-2.33-123/lib/libc.so.6: version `GLIBC_2.34' not found (required by /nix/store/hrl51nkr7dszlwcs29wmyxq0jsqlaszn-libglvnd-1.4.0/lib/libGLX.so.0)
```
It means that there's a mismatch between the versions of `nixpkgs` used by `nixGL` and `program`.
### Use an overlay
Add nixGL as a flake input:
```Nix
{
inputs = {
nixgl.url = "github:guibou/nixGL";
};
outputs = { nixgl, ... }: { };
}
```
Then, use the flake's `overlay` attr:
```Nix
{
outputs = { nixgl, nixpkgs, ... }:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ nixgl.overlay ];
};
in
# You can now reference pkgs.nixgl.nixGLIntel, etc.
{ }
}
```
## Installation from source
```bash
$ git clone https://github.com/guibou/nixGL
$ cd nixGL
$ nix-env -f ./ -iA <your desired wrapper name>
```
# Usage
Just launch the program you want prefixed by the right wrapper.
For example, for OpenGL programs:
```bash
$ nixGL program args # For the `nixGLDefault` wrapper, recommended.
$ nixGLNvidia program args
$ nixGLIntel program args
$ nixGLNvidiaBumblebee program args
```
For Vulkan programs:
```bash
$ nixVulkanNvidia program args
$ nixVulkanIntel program args
```
# OpenGL - Hybrid Intel + Nvidia laptop
After installing `nixGLIntel` and `nixGLNvidiaBumblebee`.
```bash
$ nixGLIntel $(nix run nixpkgs.glxinfo -c glxinfo) | grep -i 'OpenGL version string'
OpenGL version string: 3.0 Mesa 17.3.3
$ nixGLNvidiaBumblebee $(nix run nixpkgs.glxinfo -c glxinfo) | grep -i 'OpenGL version string'
OpenGL version string: 4.6.0 NVIDIA 390.25
```
If the program you'd like to run is already installed by nix in your current environment, you can simply run it with the wrapper, for example:
```bash
$ nixGLIntel blender
```
# Vulkan - Intel GPU
After installing `nixVulkanIntel`.
```bash
$ sudo apt install mesa-vulkan-drivers
...
$ nixVulkanIntel $(nix-build '<nixpkgs>' --no-out-link -A vulkan-tools)/bin/vulkaninfo | grep VkPhysicalDeviceProperties -A 7
VkPhysicalDeviceProperties:
===========================
apiVersion = 0x400036 (1.0.54)
driverVersion = 71311368 (0x4402008)
vendorID = 0x8086
deviceID = 0x591b
deviceType = INTEGRATED_GPU
deviceName = Intel(R) HD Graphics 630 (Kaby Lake GT2)
```
# Troubleshooting
## Nvidia auto detection does not work
```bash
building '/nix/store/ijs5h6h07faai0k74diiy5b2xlxh891g-auto-detect-nvidia.drv'...
pcregrep: Failed to open /proc/driver/nvidia/version: No such file or directory
builder for '/nix/store/ijs5h6h07faai0k74diiy5b2xlxh891g-auto-detect-nvidia.drv' failed with exit code 2
error: build of '/nix/store/ijs5h6h07faai0k74diiy5b2xlxh891g-auto-detect-nvidia.drv' faile
```
You can run the Nvidia installer using an explicit version string instead of the automatic detection method:
```bash
nix-build -A auto.nixGLNvidia --argstr nvidiaVersion 440.82
```
(or `nixGLNvidiaBumblebee`, `nixVulkanNividia`)
The version of your driver can be found using `glxinfo` from your system default package manager, or `nvidia-settings`.
## On nixOS
`nixGL` can also be used on nixOS if the system is installed with a different
nixpkgs clone than the one your application are installed with. Override the
`pkgs` argument of the script with the correct nixpkgs clone:
```bash
nix-build ./default.nix -A nixGLIntel --arg pkgs "import path_to_your_nixpkgs {}".
```
## Old nvidia drivers
Users of Nvidia legacy driver should use the `backport/noGLVND` branch. This branch is not tested and may not work well, please open a bug report, it will be taken care of as soon as possible.
# `nixGLCommon`
`nixGLCommon nixGLXXX` can be used to get `nixGL` executable which fallback to `nixGLXXX`. It is a shorter name for people with only one OpenGL configuration.
For example:
```
nix-build -E "with import ./default.nix {}; nixGLCommon nixGLIntel"
```
# Limitations
`nixGL` is badly tested, mostly because it is difficult to test automatically in a continuous integration context because you need access to different type of hardware.
Some OpenGL configurations may not work, for example AMD proprietary drivers. There is no fundamental limitation, so if you want support for theses configurations, open an issue.
# Hacking
One great way to contribute to nixGL is to run the test suite. Just run
`./Test.hs` in the main directory and check that all the test relevant to your
hardware are green.

110
out-of-tree/nixGL/Test.hs Executable file
View File

@ -0,0 +1,110 @@
#!/usr/bin/env nix-shell
#!nix-shell -i runhaskell -p "haskellPackages.ghcWithPackages(p: with p; [hspec process])" -p nix
{-# LANGUAGE OverloadedStrings #-}
import Test.Hspec
import System.Process
import qualified Data.Text as Text
import Data.Text (Text)
import Control.Monad.IO.Class (liftIO)
import Data.List (find)
-- nixos-19-09 is used so hopefully it will have a different libc than
-- the current `<nixpkgs>` used in a current nixOS system, so it will trigger the
-- driver failure.
-- Run `./Test.hs --match "/Sanity/"` to ensure that non wrapped
-- binaries fails on NixOS.
currentChannel = "channel:nixos-19.09-small"
-- | Utils function: run a command and returns its output.
processOutput p args = Text.strip . Text.pack <$> readCreateProcess ((proc (Text.unpack p) (Text.unpack <$> args)) { std_err = Inherit }) ""
-- * OpenGL
-- | Returns the path to the nixGLXXX binary.
getNixGLBin version = (<>("/bin/"<>version)) <$> processOutput "nix-build" ["./", "-A", version, "-I", "nixpkgs=" <> currentChannel]
-- | Returns the vendor string associated with a glxinfo wrapped by a nixGL.
getVendorString io = do
output <- Text.lines <$> io
pure $ Text.unpack <$> find ("OpenGL version string"`Text.isPrefixOf`) output
-- | Checks that a nixGL wrapper works with glxinfo 32 & 64 bits.
checkOpenGL_32_64 glxinfo32 glxinfo64 vendorName nixGLName = do
beforeAll (getNixGLBin nixGLName) $ do
it "32 bits" $ \nixGLBin -> do
Just vendorString <- getVendorString (processOutput nixGLBin [glxinfo32, "-B"])
vendorString `shouldContain` vendorName
it "64 bits" $ \nixGLBin -> do
Just vendorString <- getVendorString (processOutput nixGLBin [glxinfo64, "-B"])
vendorString `shouldContain` vendorName
-- * Vulkan
-- | Heuristic to detect if vulkan work. `driverName` must appears in the output
checkVulkanIsWorking io = do
res <- io
res `shouldSatisfy` ("driverName"`Text.isInfixOf`)
-- | Checks that a nixGL wrapper works with glxinfo 32 & 64 bits.
checkVulkan_32_64 vulkaninfo32 vulkaninfo64 vendorName nixGLName = do
beforeAll (getNixGLBin nixGLName) $ do
it "32 bits" $ \nixGLBin -> do
checkVulkanIsWorking (processOutput nixGLBin [vulkaninfo32])
it "64 bits" $ \nixGLBin -> do
checkVulkanIsWorking (processOutput nixGLBin [vulkaninfo64])
main = do
putStrLn "Running tests for nixGL"
putStrLn "It can take a while, this will build and test all drivers in the background"
glxinfo64 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" [currentChannel, "-A", "glxinfo"]
glxinfo32 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" [currentChannel, "-A", "pkgsi686Linux.glxinfo"]
vulkaninfo64 <- (<>"/bin/vulkaninfo") <$> processOutput "nix-build" [currentChannel, "-A", "vulkan-tools"]
vulkaninfo32 <- (<>"/bin/vulkaninfo") <$> processOutput "nix-build" [currentChannel, "-A", "pkgsi686Linux.vulkan-tools"]
let checkOpenGL = checkOpenGL_32_64 glxinfo32 glxinfo64
checkVulkan = checkVulkan_32_64 vulkaninfo32 vulkaninfo64
hspec $ do
-- This category ensure that tests are failing if not run with nixGL
-- This allows testing on nixOS
describe "Sanity" $ do
describe "OpenGL" $ do
it "fails with unwrapped glxinfo64" $ do
vendorString <- getVendorString (processOutput glxinfo64 ["-B"])
vendorString `shouldBe` Nothing
it "fails with unwrapped glxinfo32" $ do
vendorString <- getVendorString (processOutput glxinfo32 ["-B"])
vendorString `shouldBe` Nothing
describe "Vulkan" $ do
it "fails with unwrapped vulkaninfo64" $ do
processOutput vulkaninfo64 [] `shouldThrow` anyIOException
it "fails with unwrapped vulkaninfo32" $ do
processOutput vulkaninfo32 [] `shouldThrow` anyIOException
describe "NixGL" $ do
describe "Mesa" $ do
describe "OpenGL" $ do
checkOpenGL "Mesa" "nixGLIntel"
describe "Vulkan" $ do
checkVulkan "Mesa" "nixVulkanIntel"
describe "Nvidia - Bumblebee" $ do
describe "OpenGL" $ do
checkOpenGL "NVIDIA" "nixGLNvidiaBumblebee"
xdescribe "Vulkan" $ do
-- Not tested: I don't have the hardware (@guibou)
checkVulkan "NVIDIA" "nixVulkanNvidiaBumblebee"
-- TODO: check Nvidia (I don't have this hardware)
describe "Nvidia" $ do
describe "OpenGL" $ do
checkOpenGL "NVIDIA" "nixGLNvidia"
describe "Vulkan" $ do
checkVulkan "NVIDIA" "nixVulkanNvidia"

25
out-of-tree/nixGL/all.nix Normal file
View File

@ -0,0 +1,25 @@
let
pkgs = import ./nixpkgs.nix { config = { allowUnfree = true; }; };
pure = pkgs.recurseIntoAttrs (pkgs.callPackage ./nixGL.nix {
nvidiaVersion = "440.82";
nvidiaHash = "edd415acf2f75a659e0f3b4f27c1fab770cf21614e84a18152d94f0d004a758e";
});
versionFile440 = (pkgs.callPackage ./nixGL.nix {
nvidiaVersionFile = pkgs.writeText "nvidia-version-440.82" ''
NVRM version: NVIDIA UNIX x86_64 Kernel Module 440.82 Wed Apr 1 20:04:33 UTC 2020
GCC version: gcc version 9.3.0 (Arch Linux 9.3.0-1)
'';
});
versionFile510 = (pkgs.callPackage ./nixGL.nix {
nvidiaVersionFile = pkgs.writeText "nvidia-version-510.54" ''
NVRM version: NVIDIA UNIX x86_64 Kernel Module 510.54 Wed Apr 1 20:04:33 UTC 2020
GCC version: gcc version 9.3.0 (Arch Linux 9.3.0-1)
'';
});
in
(with pure; [nixGLIntel nixVulkanNvidia nixGLNvidia nixVulkanIntel])
++ (with versionFile440.auto; [nixGLNvidia nixGLDefault nixVulkanNvidia])
++ (with versionFile510.auto; [nixGLNvidia nixGLDefault nixVulkanNvidia])

View File

@ -0,0 +1,35 @@
{ ## Nvidia informations.
# Version of the system kernel module. Let it to null to enable auto-detection.
nvidiaVersion ? null,
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here
# will be more reproducible and more efficient.
nvidiaHash ? null,
# Alternatively, you can pass a path that points to a nvidia version file
# and let nixGL extract the version from it. That file must be a copy of
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
# https://github.com/NixOS/nix/issues/3539 ).
nvidiaVersionFile ? null,
# Enable 32 bits driver
# This is on by default, you can switch it to off if you want to reduce a
# bit the size of nixGL closure.
enable32bits ? true,
# Make sure to enable config.allowUnfree to the instance of nixpkgs to be
# able to access the nvidia drivers.
pkgs ? import <nixpkgs> {
config = { allowUnfree = true; };
},
# Enable all Intel specific extensions which only works on x86_64
enableIntelX86Extensions ? true
}:
pkgs.callPackage ./nixGL.nix ({
inherit
nvidiaVersion
nvidiaVersionFile
nvidiaHash
enable32bits
;
} // (if enableIntelX86Extensions then {}
else {
intel-media-driver = null;
vaapiIntel = null;
}))

View File

@ -0,0 +1,42 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1660551188,
"narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View File

@ -0,0 +1,45 @@
{
description = "A wrapper tool for nix OpenGL applications";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:nixos/nixpkgs";
outputs = { self, nixpkgs, flake-utils }:
(flake-utils.lib.eachDefaultSystem (system:
let
isIntelX86Platform = system == "x86_64-linux";
pkgs = import ./default.nix {
pkgs = nixpkgs.legacyPackages.${system};
enable32bits = isIntelX86Platform;
enableIntelX86Extensions = isIntelX86Platform;
};
in rec {
packages = {
# makes it easy to use "nix run nixGL --impure -- program"
default = pkgs.auto.nixGLDefault;
nixGLDefault = pkgs.auto.nixGLDefault;
nixGLNvidia = pkgs.auto.nixGLNvidia;
nixGLNvidiaBumblebee = pkgs.auto.nixGLNvidiaBumblebee;
nixGLIntel = pkgs.nixGLIntel;
nixVulkanNvidia = pkgs.auto.nixVulkanNvidia;
nixVulkanIntel = pkgs.nixVulkanIntel;
};
# deprecated attributes for retro compatibility
defaultPackage = packages;
})) // rec {
# deprecated attributes for retro compatibility
overlay = overlays.default;
overlays.default = final: _:
let isIntelX86Platform = final.system == "x86_64-linux";
in {
nixgl = import ./default.nix {
pkgs = final;
enable32bits = isIntelX86Platform;
enableIntelX86Extensions = isIntelX86Platform;
};
};
};
}

248
out-of-tree/nixGL/nixGL.nix Normal file
View File

@ -0,0 +1,248 @@
{ # # Nvidia informations.
# Version of the system kernel module. Let it to null to enable auto-detection.
nvidiaVersion ? null,
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here
# will be more reproducible and more efficient.
nvidiaHash ? null,
# Alternatively, you can pass a path that points to a nvidia version file
# and let nixGL extract the version from it. That file must be a copy of
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
# https://github.com/NixOS/nix/issues/3539 ).
nvidiaVersionFile ? null,
# Enable 32 bits driver
# This is one by default, you can switch it to off if you want to reduce a
# bit the size of nixGL closure.
enable32bits ? true
, writeTextFile, shellcheck, pcre, runCommand, linuxPackages
, fetchurl, lib, runtimeShell, bumblebee, libglvnd, vulkan-validation-layers
, mesa, libvdpau-va-gl, intel-media-driver, vaapiIntel, pkgsi686Linux, driversi686Linux
, zlib, libdrm, xorg, wayland, gcc }:
let
writeExecutable = { name, text }:
writeTextFile {
inherit name text;
executable = true;
destination = "/bin/${name}";
checkPhase = ''
${shellcheck}/bin/shellcheck "$out/bin/${name}"
# Check that all the files listed in the output binary exists
for i in $(${pcre}/bin/pcregrep -o0 '/nix/store/.*?/[^ ":]+' $out/bin/${name})
do
ls $i > /dev/null || (echo "File $i, referenced in $out/bin/${name} does not exists."; exit -1)
done
'';
};
top = rec {
/*
It contains the builder for different nvidia configuration, parametrized by
the version of the driver and sha256 sum of the driver installer file.
*/
nvidiaPackages = { version, sha256 ? null }: rec {
nvidiaDrivers = (linuxPackages.nvidia_x11.override { }).overrideAttrs
(oldAttrs: rec {
pname = "nvidia";
name = "nvidia-x11-${version}-nixGL";
inherit version;
src = let
url =
"https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}.run";
in if sha256 != null then
fetchurl { inherit url sha256; }
else
builtins.fetchurl url;
useGLVND = true;
});
nvidiaLibsOnly = nvidiaDrivers.override {
libsOnly = true;
kernel = null;
};
nixGLNvidiaBumblebee = writeExecutable {
name = "nixGLNvidiaBumblebee-${version}";
text = ''
#!${runtimeShell}
export LD_LIBRARY_PATH=${
lib.makeLibraryPath [ nvidiaDrivers ]
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
${
bumblebee.override {
nvidia_x11 = nvidiaDrivers;
nvidia_x11_i686 = nvidiaDrivers.lib32;
}
}/bin/optirun --ldpath ${
lib.makeLibraryPath ([ libglvnd nvidiaDrivers ]
++ lib.optionals enable32bits [
nvidiaDrivers.lib32
pkgsi686Linux.libglvnd
])
} "$@"
'';
};
# TODO: 32bit version? Not tested.
nixNvidiaWrapper = api:
writeExecutable {
name = "nix${api}Nvidia-${version}";
text = ''
#!${runtimeShell}
${lib.optionalString (api == "Vulkan")
"export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d"}
NVIDIA_JSON=(${nvidiaLibsOnly}/share/glvnd/egl_vendor.d/*nvidia.json)
${lib.optionalString enable32bits "NVIDIA_JSON32=(${nvidiaLibsOnly.lib32}/share/glvnd/egl_vendor.d/*nvidia.json)"}
${''export __EGL_VENDOR_LIBRARY_FILENAMES=''${NVIDIA_JSON[*]}${
lib.optionalString enable32bits
'':''${NVIDIA_JSON32[*]}''
}"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"''
}
${
lib.optionalString (api == "Vulkan")
''export VK_ICD_FILENAMES=${nvidiaLibsOnly}/share/vulkan/icd.d/nvidia_icd.json${
lib.optionalString enable32bits
":${nvidiaLibsOnly.lib32}/share/vulkan/icd.d/nvidia_icd.json"
}"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}"''
}
export LD_LIBRARY_PATH=${
lib.makeLibraryPath ([ libglvnd nvidiaLibsOnly ]
++ lib.optional (api == "Vulkan") vulkan-validation-layers
++ lib.optionals enable32bits [
nvidiaLibsOnly.lib32
pkgsi686Linux.libglvnd
])
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$@"
'';
};
# TODO: 32bit version? Not tested.
nixGLNvidia = nixNvidiaWrapper "GL";
# TODO: 32bit version? Not tested.
nixVulkanNvidia = nixNvidiaWrapper "Vulkan";
};
nixGLIntel = writeExecutable {
name = "nixGLIntel";
# add the 32 bits drivers if needed
text = let
mesa-drivers = [ mesa.drivers ]
++ lib.optional enable32bits pkgsi686Linux.mesa.drivers;
intel-driver = [ intel-media-driver vaapiIntel ]
# Note: intel-media-driver is disabled for i686 until https://github.com/NixOS/nixpkgs/issues/140471 is fixed
++ lib.optionals enable32bits [ /* pkgsi686Linux.intel-media-driver */ driversi686Linux.vaapiIntel ];
libvdpau = [ libvdpau-va-gl ]
++ lib.optional enable32bits pkgsi686Linux.libvdpau-va-gl;
glxindirect = runCommand "mesa_glxindirect" { } (''
mkdir -p $out/lib
ln -s ${mesa.drivers}/lib/libGLX_mesa.so.0 $out/lib/libGLX_indirect.so.0
'');
in ''
#!${runtimeShell}
export LIBGL_DRIVERS_PATH=${lib.makeSearchPathOutput "lib" "lib/dri" mesa-drivers}
export LIBVA_DRIVERS_PATH=${lib.makeSearchPathOutput "out" "lib/dri" intel-driver}
${''export __EGL_VENDOR_LIBRARY_FILENAMES=${mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json${
lib.optionalString enable32bits
":${pkgsi686Linux.mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json"
}"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"''
}
export LD_LIBRARY_PATH=${lib.makeLibraryPath mesa-drivers}:${lib.makeSearchPathOutput "lib" "lib/vdpau" libvdpau}:${glxindirect}/lib:${lib.makeLibraryPath [libglvnd]}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$@"
'';
};
nixVulkanIntel = writeExecutable {
name = "nixVulkanIntel";
text = let
# generate a file with the listing of all the icd files
icd = runCommand "mesa_icd" { } (
# 64 bits icd
''
ls ${mesa.drivers}/share/vulkan/icd.d/*.json > f
''
# 32 bits ones
+ lib.optionalString enable32bits ''
ls ${pkgsi686Linux.mesa.drivers}/share/vulkan/icd.d/*.json >> f
''
# concat everything as a one line string with ":" as seperator
+ ''cat f | xargs | sed "s/ /:/g" > $out'');
in ''
#!${runtimeShell}
if [ -n "$LD_LIBRARY_PATH" ]; then
echo "Warning, nixVulkanIntel overwriting existing LD_LIBRARY_PATH" 1>&2
fi
export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d
ICDS=$(cat ${icd})
export VK_ICD_FILENAMES=$ICDS"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}"
export LD_LIBRARY_PATH=${
lib.makeLibraryPath [
zlib
libdrm
xorg.libX11
xorg.libxcb
xorg.libxshmfence
wayland
gcc.cc
]
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec "$@"
'';
};
nixGLCommon = nixGL:
runCommand "nixGL" { } ''
mkdir -p "$out/bin"
# star because nixGLNvidia... have version prefixed name
cp ${nixGL}/bin/* "$out/bin/nixGL";
'';
auto = let
_nvidiaVersionFile = if nvidiaVersionFile != null then
nvidiaVersionFile
else
# HACK: Get the version from /proc. It turns out that /proc is mounted
# inside of the build sandbox and varies from machine to machine.
#
# builtins.readFile is not able to read /proc files. See
# https://github.com/NixOS/nix/issues/3539.
runCommand "impure-nvidia-version-file" {
# To avoid sharing the build result over time or between machine,
# Add an impure parameter to force the rebuild on each access.
# time = builtins.currentTime;
preferLocalBuild = true;
allowSubstitutes = false;
} "cp /proc/driver/nvidia/version $out 2> /dev/null || touch $out";
# The nvidia version. Either fixed by the `nvidiaVersion` argument, or
# auto-detected. Auto-detection is impure.
nvidiaVersionAuto = if nvidiaVersion != null then
nvidiaVersion
else
# Get if from the nvidiaVersionFile
let
data = builtins.readFile _nvidiaVersionFile;
versionMatch = builtins.match ".*Module ([0-9.]+) .*" data;
in if versionMatch != null then builtins.head versionMatch else null;
autoNvidia = nvidiaPackages {version = nvidiaVersionAuto; };
in rec {
# The output derivation contains nixGL which point either to
# nixGLNvidia or nixGLIntel using an heuristic.
nixGLDefault = if nvidiaVersionAuto != null then
nixGLCommon autoNvidia.nixGLNvidia
else
nixGLCommon nixGLIntel;
} // autoNvidia;
};
in top // (if nvidiaVersion != null then
top.nvidiaPackages {
version = nvidiaVersion;
sha256 = nvidiaHash;
}
else
{ })

View File

@ -0,0 +1,6 @@
let
rev = "4f6d8095fd51";
in
import (fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz";
})

20
overlays.nix Normal file
View File

@ -0,0 +1,20 @@
flake_input@{ kpcli-py, nixgl, rust-overlay, ... }: [
nixgl.overlays.default
rust-overlay.overlays.default
(final: prev: {
# use python3.9, which works because of cython somehow?
kpcli-py = final.poetry2nix.mkPoetryApplication {
projectDir = kpcli-py;
python = final.python39;
overrides = final.poetry2nix.defaultPoetryOverrides.extend (self: super: {
# tableformatter requires setuptools
tableformatter = super.tableformatter.overridePythonAttrs (
old: {
buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools super.cython_3 ];
}
);
});
};
})
]

15
templates/rust-monorepo/.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
.direnv

View File

@ -1,14 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cli"
version = "0.1.0"
dependencies = [
"core",
]
[[package]]
name = "core"
version = "0.1.0"

View File

@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
core = { version = "0.1.0", path = "../../packages/core" } corelib = { version = "0.1.0", path = "../../packages/corelib" }

View File

@ -25,6 +25,7 @@
} }
)) ))
pkgs.rust-analyzer pkgs.rust-analyzer
pkgs.bacon # rust background code checker
]; ];
RUST_SRC_PATH = rustPlatform.rustLibSrc; RUST_SRC_PATH = rustPlatform.rustLibSrc;
shellHook = '' shellHook = ''

View File

@ -1,5 +1,5 @@
[package] [package]
name = "core" name = "corelib"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"