From 57717e5efa43bb2ed828b99e9585de4d7f5b2ace Mon Sep 17 00:00:00 2001 From: chayleaf Date: Sun, 16 Apr 2023 23:59:24 +0700 Subject: [PATCH] move impermanence to separate module; add C-X nvim binding --- home/common/nvim.nix | 6 +++ system/flake.nix | 7 +-- system/hosts/nixmsi.nix | 59 ++++++------------------- system/modules/impermanence.nix | 78 +++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 49 deletions(-) create mode 100644 system/modules/impermanence.nix diff --git a/home/common/nvim.nix b/home/common/nvim.nix index d652dc2..fced672 100644 --- a/home/common/nvim.nix +++ b/home/common/nvim.nix @@ -113,6 +113,12 @@ vimdiffAlias = true; extraLuaConfig = (compile' "main" [ + kmSetNs { + "" = { + rhs = DEFUN (vim.fn.system [ "chmod" "+x" (vim.fn.expand "%") ]); + desc = "chmod +x %"; + }; + } _ SET (vimg "vimsyn_embed") "l" _ LET (vim.api.nvim_create_augroup "nvimrc" { clear = true; }) (group: lib.mapAttrsToList (k: v: vim.api.nvim_create_autocmd k { inherit group; callback = v; }) { diff --git a/system/flake.nix b/system/flake.nix index 45308fb..e0e2435 100644 --- a/system/flake.nix +++ b/system/flake.nix @@ -21,13 +21,14 @@ let hw = nixos-hardware.nixosModules; # IRL-related stuff I'd rather not put into git - priv = if builtins.pathExists ./private.nix then (import ./private.nix) else {}; - getPriv = (hostname: with builtins; if hasAttr hostname priv then getAttr hostname priv 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 { }); in utils.lib.mkFlake { inherit self inputs; hostDefaults.modules = [ ./modules/vfio.nix ./modules/ccache.nix + ./modules/impermanence.nix { # make this flake's nixpkgs available to the whole system nix = { @@ -35,7 +36,7 @@ generateRegistryFromInputs = true; linkInputs = true; }; - nixpkgs.overlays = [(self: super: import ./pkgs { pkgs = super; })]; + nixpkgs.overlays = [ (self: super: import ./pkgs { pkgs = super; }) ]; } ]; hosts = { diff --git a/system/hosts/nixmsi.nix b/system/hosts/nixmsi.nix index e4673ed..a15ae93 100644 --- a/system/hosts/nixmsi.nix +++ b/system/hosts/nixmsi.nix @@ -46,7 +46,6 @@ in { "fbcon=font:TER16x32" "consoleblank=60" ]; - cleanTmpDir = true; loader = { grub = { enable = true; @@ -153,41 +152,9 @@ in { options = [ discard compress ]; }; }; - environment.persistence."/persist" = { - hideMounts = true; - directories = [ - # 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" - ]; + impermanence = { + enable = true; + path = /persist; }; swapDevices = [ { device = "/swap/swapfile"; } ]; @@ -293,7 +260,8 @@ in { # from nix-gaming lowLatency = { 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; rate = 48000; }; @@ -303,10 +271,10 @@ in { programs.fish = { enable = true; }; - programs.zsh = { + /*programs.zsh = { enable = true; enableBashCompletion = true; - }; + };*/ programs.fuse.userAllowOther = true; @@ -358,15 +326,14 @@ in { # autologin once after boot # --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) - services.getty.extraArgs = ["--skip-login"]; - services.getty.loginProgram = with pkgs; writeScript "login-once" '' - #! ${bash}/bin/bash - LOCKFILE=/tmp/login-once.lock - if [ -f $LOCKFILE ] - then + services.getty.extraArgs = [ "--skip-login" ]; + services.getty.loginProgram = let + lockfile = "/tmp/login-once.lock"; + in with pkgs; writeShellScript "login-once" '' + if [ -f '${lockfile}' ]; then exec ${shadow}/bin/login $@ else - ${coreutils}/bin/touch $LOCKFILE + ${coreutils}/bin/touch '${lockfile}' exec ${shadow}/bin/login -f user fi ''; diff --git a/system/modules/impermanence.nix b/system/modules/impermanence.nix new file mode 100644 index 0000000..e4a59dd --- /dev/null +++ b/system/modules/impermanence.nix @@ -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); + }; + }; +}