move impermanence to separate module; add C-X nvim binding

This commit is contained in:
chayleaf 2023-04-16 23:59:24 +07:00
parent d1c41443c2
commit 57717e5efa
4 changed files with 101 additions and 49 deletions

View file

@ -113,6 +113,12 @@
vimdiffAlias = true; vimdiffAlias = true;
extraLuaConfig = (compile' "main" [ extraLuaConfig = (compile' "main" [
kmSetNs {
"<C-X>" = {
rhs = DEFUN (vim.fn.system [ "chmod" "+x" (vim.fn.expand "%") ]);
desc = "chmod +x %";
};
} _
SET (vimg "vimsyn_embed") "l" _ SET (vimg "vimsyn_embed") "l" _
LET (vim.api.nvim_create_augroup "nvimrc" { clear = true; }) (group: LET (vim.api.nvim_create_augroup "nvimrc" { clear = true; }) (group:
lib.mapAttrsToList (k: v: vim.api.nvim_create_autocmd k { inherit group; callback = v; }) { lib.mapAttrsToList (k: v: vim.api.nvim_create_autocmd k { inherit group; callback = v; }) {

View file

@ -21,13 +21,14 @@
let let
hw = nixos-hardware.nixosModules; hw = nixos-hardware.nixosModules;
# IRL-related stuff I'd rather not put into git # IRL-related stuff I'd rather not put into git
priv = if builtins.pathExists ./private.nix then (import ./private.nix) else {}; priv = if builtins.pathExists ./private.nix then (import ./private.nix) else { };
getPriv = (hostname: with builtins; if hasAttr hostname priv then getAttr hostname priv else {}); getPriv = (hostname: with builtins; if hasAttr hostname priv then getAttr hostname priv else { });
in utils.lib.mkFlake { in utils.lib.mkFlake {
inherit self inputs; inherit self inputs;
hostDefaults.modules = [ hostDefaults.modules = [
./modules/vfio.nix ./modules/vfio.nix
./modules/ccache.nix ./modules/ccache.nix
./modules/impermanence.nix
{ {
# make this flake's nixpkgs available to the whole system # make this flake's nixpkgs available to the whole system
nix = { nix = {
@ -35,7 +36,7 @@
generateRegistryFromInputs = true; generateRegistryFromInputs = true;
linkInputs = true; linkInputs = true;
}; };
nixpkgs.overlays = [(self: super: import ./pkgs { pkgs = super; })]; nixpkgs.overlays = [ (self: super: import ./pkgs { pkgs = super; }) ];
} }
]; ];
hosts = { hosts = {

View file

@ -46,7 +46,6 @@ in {
"fbcon=font:TER16x32" "fbcon=font:TER16x32"
"consoleblank=60" "consoleblank=60"
]; ];
cleanTmpDir = true;
loader = { loader = {
grub = { grub = {
enable = true; enable = true;
@ -153,41 +152,9 @@ in {
options = [ discard compress ]; }; options = [ discard compress ]; };
}; };
environment.persistence."/persist" = { impermanence = {
hideMounts = true; enable = true;
directories = [ path = /persist;
# nixos files
"/etc/nixos"
"/var/lib/nixos"
# mullvad vpn
"/etc/mullvad-vpn"
"/var/cache/mullvad-vpn"
# as weird as it sounds, I won't use tmpfs for /tmp in case I'll have to put files over 2GB there
"/tmp"
# qemu/libvirt
"/var/cache/libvirt"
"/var/lib/libvirt"
"/var/lib/swtpm-localca"
# stored network info
"/var/lib/iwd"
"/var/db/dhcpcd"
# persist this since everything here is cleaned up by systemd-tmpfiles over time anyway
# ...or so I'd like to believe
"/var/lib/systemd"
"/var/db/sudo/lectured"
"/var/log"
];
files = [
# hardware-related
"/etc/adjtime"
"/etc/machine-id"
];
}; };
swapDevices = [ { device = "/swap/swapfile"; } ]; swapDevices = [ { device = "/swap/swapfile"; } ];
@ -293,7 +260,8 @@ in {
# from nix-gaming # from nix-gaming
lowLatency = { lowLatency = {
enable = true; enable = true;
# 96 is mostly fine but has just a little xruns # 96 is mostly fine but has some xruns
# 128 has xruns every now and then too, but is overall fine
quantum = 128; quantum = 128;
rate = 48000; rate = 48000;
}; };
@ -303,10 +271,10 @@ in {
programs.fish = { programs.fish = {
enable = true; enable = true;
}; };
programs.zsh = { /*programs.zsh = {
enable = true; enable = true;
enableBashCompletion = true; enableBashCompletion = true;
}; };*/
programs.fuse.userAllowOther = true; programs.fuse.userAllowOther = true;
@ -358,15 +326,14 @@ in {
# autologin once after boot # autologin once after boot
# --skip-login means directly call login instead of first asking for username # --skip-login means directly call login instead of first asking for username
# (normally login asks for username too, but getty prefers to do it by itself for whatever reason) # (normally login asks for username too, but getty prefers to do it by itself for whatever reason)
services.getty.extraArgs = ["--skip-login"]; services.getty.extraArgs = [ "--skip-login" ];
services.getty.loginProgram = with pkgs; writeScript "login-once" '' services.getty.loginProgram = let
#! ${bash}/bin/bash lockfile = "/tmp/login-once.lock";
LOCKFILE=/tmp/login-once.lock in with pkgs; writeShellScript "login-once" ''
if [ -f $LOCKFILE ] if [ -f '${lockfile}' ]; then
then
exec ${shadow}/bin/login $@ exec ${shadow}/bin/login $@
else else
${coreutils}/bin/touch $LOCKFILE ${coreutils}/bin/touch '${lockfile}'
exec ${shadow}/bin/login -f user exec ${shadow}/bin/login -f user
fi fi
''; '';

View file

@ -0,0 +1,78 @@
{ config, lib, pkgs, ... }:
let
cfg = config.impermanence;
in {
options.impermanence = with lib; mkOption {
type = types.submodule {
options = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable impermanence";
};
path = mkOption {
type = types.path;
description = "Default path for persistence";
};
directories = mkOption {
type = with types; listOf path;
default = [ ];
description = "Extra directories to persist";
};
files = mkOption {
type = with types; listOf path;
default = [ ];
description = "Extra files to persist";
};
persistTmp = mkOption {
type = types.bool;
default = true;
description = "Persist /tmp (and clean on boot)";
};
};
};
description = "Impermanence settings";
default = { };
};
config = lib.mkIf cfg.enable {
# as weird as it sounds, I won't use tmpfs for /tmp in case I'll have to put files over 2GB there
boot.cleanTmpDir = lib.mkIf cfg.persistTmp true;
environment.persistence.${toString cfg.path} = {
hideMounts = true;
directories = map toString ([
# nixos files
/etc/nixos
/var/lib/nixos
/var/log
# persist this since everything here is cleaned up by systemd-tmpfiles over time anyway
# ...or so I'd like to believe
/var/lib/systemd
/var/tmp
] ++ (lib.optionals cfg.persistTmp [
/tmp
]) ++ (lib.optionals config.services.mullvad-vpn.enable [
/etc/mullvad-vpn
/var/cache/mullvad-vpn
]) ++ (lib.optionals config.virtualisation.libvirtd.enable ([
/var/cache/libvirt
/var/lib/libvirt
] ++ (lib.optionals config.virtualisation.libvirtd.qemu.swtpm.enable [
/var/lib/swtpm-localca
]))) ++ (lib.optionals config.networking.wireless.iwd.enable [
/var/lib/iwd
]) ++ (lib.optionals (builtins.any (x: x.useDHCP) (builtins.attrValues config.networking.interfaces) || config.networking.useDHCP) [
/var/db/dhcpcd
]) ++ (lib.optionals config.security.sudo.enable [
/var/db/sudo/lectured
]) ++ cfg.directories);
files = map toString ([
# hardware-related
/etc/adjtime
/etc/machine-id
] ++ cfg.files);
};
};
}