From a3139051b14005f1e4c96091e8b3c4cd0e320b0d Mon Sep 17 00:00:00 2001 From: DerGrumpf Date: Wed, 24 Jun 2026 19:07:40 +0200 Subject: [PATCH] WIP: Groundwork for impermanence setup for nixos and home --- flake.nix | 1 + home/impermanence.nix | 13 +++++++++++++ home/neovim/conform.nix | 37 +++++++++++++++++++++++++++++++++++-- home/neovim/lsp.nix | 2 ++ nixos/default.nix | 1 + nixos/impermanence.nix | 18 ++++++++++++++++++ 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 home/impermanence.nix create mode 100644 nixos/impermanence.nix diff --git a/flake.nix b/flake.nix index 2e874be..c7d6c0a 100644 --- a/flake.nix +++ b/flake.nix @@ -210,6 +210,7 @@ [ { nixpkgs.hostPlatform = system; } ./nixos + inputs.impermanence.nixosModules.impermanence ]; in diff --git a/home/impermanence.nix b/home/impermanence.nix new file mode 100644 index 0000000..804e3d9 --- /dev/null +++ b/home/impermanence.nix @@ -0,0 +1,13 @@ +{ primaryUser, ... }: +{ + home.persistence."/persist/home/${primaryUser}" = { + hideMounts = true; + directories = [ + ".config/nix" + ".local/share/zoxide" + ]; + files = [ + ".local/share/fish/fish_history" + ]; + }; +} diff --git a/home/neovim/conform.nix b/home/neovim/conform.nix index f915b04..aab32dc 100644 --- a/home/neovim/conform.nix +++ b/home/neovim/conform.nix @@ -5,7 +5,6 @@ programs.nixvim = { plugins.conform-nvim = { enable = true; - settings = { formatters_by_ft = { lua = [ "stylua" ]; @@ -13,6 +12,40 @@ python = [ "black" ]; rust = [ "rustfmt" ]; rasi = [ "prettierd" ]; + c = [ "clang_format" ]; + cpp = [ "clang_format" ]; + }; + + formatters.clang_format = { + # If the file has a project .clang-format (walking up from the + # file itself, not nvim's cwd), use it - this is how a real + # kernel checkout, or any other C/C++ project's own style, + # gets respected automatically. Otherwise fall back to an + # inline approximation of kernel style instead of plain LLVM, + # since that's the sane default for one-off C files. + prepend_args = { + __raw = '' + function(self, ctx) + local found = vim.fs.find( + { ".clang-format", "_clang-format" }, + { path = ctx.filename, upward = true } + )[1] + if found then + return { "-style=file" } + end + return { + "-style={BasedOnStyle: LLVM, IndentWidth: 8, UseTab: Always, " + .. "TabWidth: 8, BreakBeforeBraces: Linux, ColumnLimit: 80, " + .. "IndentCaseLabels: false, PointerAlignment: Right, " + .. "DerivePointerAlignment: false, SpaceBeforeParens: ControlStatements, " + .. "SpacesInParentheses: false, SpaceAfterCStyleCast: false, " + .. "AllowShortIfStatementsOnASingleLine: false, AllowShortBlocksOnASingleLine: false, " + .. "AllowShortFunctionsOnASingleLine: None, AllowShortLoopsOnASingleLine: false, " + .. "ReflowComments: false}" + } + end + ''; + }; }; format_on_save = { @@ -21,7 +54,6 @@ }; }; }; - # Install formatters extraPackages = with pkgs; [ stylua @@ -29,6 +61,7 @@ black rustfmt prettierd + clang-tools # provides clang-format ]; }; } diff --git a/home/neovim/lsp.nix b/home/neovim/lsp.nix index 678dc15..7e78df7 100644 --- a/home/neovim/lsp.nix +++ b/home/neovim/lsp.nix @@ -29,6 +29,7 @@ installRustc = true; }; pylsp.enable = true; # Python language server + clangd.enable = true; }; # Keymaps for LSP actions @@ -85,6 +86,7 @@ lua-language-server nil rust-analyzer + clang-tools ]; }; } diff --git a/nixos/default.nix b/nixos/default.nix index fcec4c6..43e0e53 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -13,6 +13,7 @@ ./locale.nix ./tailscale.nix ./ssh.nix + ./impermanence.nix ] ++ lib.optionals (!isServer) [ ./regreet.nix diff --git a/nixos/impermanence.nix b/nixos/impermanence.nix new file mode 100644 index 0000000..5837af4 --- /dev/null +++ b/nixos/impermanence.nix @@ -0,0 +1,18 @@ +_: { + environment.persistence."/persist" = { + hideMounts = true; + files = [ + "/etc/machine-id" + "/etc/ssh/ssh_host_ed25519_key" + "/etc/ssh/ssh_host_ed25519_key.pub" + "/etc/ssh/ssh_host_rsa_key" + "/etc/ssh/ssh_host_rsa_key.pub" + ]; + directories = [ + "/var/lib/nixos" + "/var/lib/systemd" + "/var/log" + "/var/lib/tailscale" + ]; + }; +}