From d56cbad81003d4957929090b493db2a73ad6fcb5 Mon Sep 17 00:00:00 2001 From: aftix Date: Fri, 14 Feb 2025 16:52:29 -0600 Subject: [PATCH] host: Changed preservation configuration to use `commonMountOptions` --- host/common/default.nix | 81 ++++++++++++++--------------------------- host/common/root.nix | 4 +- host/hamilton.nix | 11 +++--- host/opt/aftix.nix | 6 +-- 4 files changed, 38 insertions(+), 64 deletions(-) diff --git a/host/common/default.nix b/host/common/default.nix index 3233629..e9ee6d6 100644 --- a/host/common/default.nix +++ b/host/common/default.nix @@ -5,7 +5,6 @@ ... }: let inherit (lib) mkDefault mkForce; - inherit (lib.attrsets) optionalAttrs; inherit (lib.options) mkOption mkEnableOption; in { imports = [ @@ -164,59 +163,33 @@ in { optimise.automatic = true; }; - my = { - lib.preservation = { - mkDirs = builtins.map (d: - if builtins.isString d - then { - directory = d; - mountOptions = ["x-gvfs-hide"]; - } - else - d - // optionalAttrs (! (d ? how && d.how == "symlink")) { - mountOptions = (d.mountOptions or []) ++ ["x-gvfs-hide"]; - }); - mkFiles = builtins.map (f: - if builtins.isString f - then { - file = f; - mountOptions = ["x-gvfs-hide"]; - } - else - f - // optionalAttrs (! (f ? how && f.how == "symlink")) { - mountOptions = (f.mountOptions or []) ++ ["x-gvfs-hide"]; - }); - }; - # Set the host-specific things in the nixd configuration - development.nixdConfig.options = lib.mkIf ((config.my.flake or "") != "") { - nixos.expr = "(builtins.getFlake \"${config.my.flake}\").nixosConfigurations.${config.networking.hostName}.options"; - home-manager.expr = - /* - nix - */ - '' - let - flake = builtins.getFlake "${config.my.flake}"; - nixosCfg = flake.nixosConfigurations.${config.networking.hostName}.config; - pkgs = import {}; - inherit (pkgs) lib; - inherit (flake.extra) extraSpecialArgs nixosHomeOptions hmInjectNixosHomeOptions; - mkHmCfg = flake.inputs.home-manager.lib.homeManagerConfiguration; - nixosOpts = nixosHomeOptions lib; - modules = nixosCfg.dep-inject.commonHmModules ++ [ - nixosOpts - ({pkgs, ...}: { nix.package = pkgs.nix;}) - (hmInjectNixosHomeOptions nixosCfg) - (import "${config.my.flake}/home/aftix.nix") - ]; - in - (mkHmCfg { - inherit pkgs lib extraSpecialArgs modules; - }).options - ''; - }; + # Set the host-specific things in the nixd configuration + my.development.nixdConfig.options = lib.mkIf ((config.my.flake or "") != "") { + nixos.expr = "(builtins.getFlake \"${config.my.flake}\").nixosConfigurations.${config.networking.hostName}.options"; + home-manager.expr = + /* + nix + */ + '' + let + flake = builtins.getFlake "${config.my.flake}"; + nixosCfg = flake.nixosConfigurations.${config.networking.hostName}.config; + pkgs = import {}; + inherit (pkgs) lib; + inherit (flake.extra) extraSpecialArgs nixosHomeOptions hmInjectNixosHomeOptions; + mkHmCfg = flake.inputs.home-manager.lib.homeManagerConfiguration; + nixosOpts = nixosHomeOptions lib; + modules = nixosCfg.dep-inject.commonHmModules ++ [ + nixosOpts + ({pkgs, ...}: { nix.package = pkgs.nix;}) + (hmInjectNixosHomeOptions nixosCfg) + (import "${config.my.flake}/home/aftix.nix") + ]; + in + (mkHmCfg { + inherit pkgs lib extraSpecialArgs modules; + }).options + ''; }; # Use the systemd-boot EFI boot loader. diff --git a/host/common/root.nix b/host/common/root.nix index dd2fd00..630ef9d 100644 --- a/host/common/root.nix +++ b/host/common/root.nix @@ -6,13 +6,13 @@ }: let inherit (lib) mkDefault mkOverride; inherit (lib.lists) optional; - inherit (config.my.lib.preservation) mkDirs; in { environment.systemPackages = let inherit (config.users.users.root) shell; in optional (!builtins.isString shell) shell; preservation.preserveAt."${config.users.users.root.home}/.local/persist".users.root = { home = "/root"; - directories = mkDirs [ + commonMountOptions = ["x-gvfs-hide"]; + directories = [ ".config/sops" ]; }; diff --git a/host/hamilton.nix b/host/hamilton.nix index f1045bf..619f84e 100644 --- a/host/hamilton.nix +++ b/host/hamilton.nix @@ -5,7 +5,6 @@ ... }: let inherit (lib.strings) optionalString; - inherit (config.my.lib.preservation) mkDirs mkFiles; in { imports = [ ../hardware/hamilton.nix @@ -97,13 +96,14 @@ in { preserveAt = { # /persist is backed up (btrfs subvolume under safe/) "/persist" = { - directories = mkDirs [ + commonMountOptions = ["x-gvfs-hide"]; + directories = [ "/var/lib/nixos" "/etc/mullvad-vpn" "/etc/secureboot" "/var/cache/mullvad-vpn" ]; - files = mkFiles [ + files = [ { file = "/etc/machine-id"; inInitrd = true; @@ -118,7 +118,8 @@ in { }; # /state is not backup up (btrfs subvolume under local) "/state" = { - directories = mkDirs [ + commonMountOptions = ["x-gvfs-hide"]; + directories = [ { directory = "/var/log"; inInitrd = true; @@ -128,7 +129,7 @@ in { "/var/lib/systemd/timers" "/root/.config/rclone" ]; - files = mkFiles [ + files = [ "/var/lib/cups/printers.conf" "/var/lib/cups/subscriptions.conf" ]; diff --git a/host/opt/aftix.nix b/host/opt/aftix.nix index 4963e76..338bc03 100644 --- a/host/opt/aftix.nix +++ b/host/opt/aftix.nix @@ -7,7 +7,6 @@ inherit (lib.options) mkOption; inherit (lib) mkIf mkDefault mkOverride; inherit (lib.lists) optionals; - inherit (config.my.lib.preservation) mkDirs mkFiles; myCfg = config.my.users.aftix; cfg = config.users.users.aftix; in { @@ -35,7 +34,8 @@ in { security.polkit.adminIdentities = ["unix-user:aftix"]; preservation.preserveAt."${config.users.users.aftix.home}/.local/persist".users.aftix = { - directories = mkDirs [ + commonMountOptions = ["x-gvfs-hide"]; + directories = [ ".config/attic" ".config/ario" ".config/Element" @@ -48,7 +48,7 @@ in { ".config/transmission/resume" ".config/Yubico" ]; - files = mkFiles [ + files = [ ".config/nushell/history.sqlite3" ".config/nushell/history.sqlite3-shm" ".config/nushell/history.sqlite3-wal"