Skip to content

Commit

Permalink
host: Changed preservation configuration to use commonMountOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
aftix committed Feb 14, 2025
1 parent d3b78ea commit d56cbad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 64 deletions.
81 changes: 27 additions & 54 deletions host/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
...
}: let
inherit (lib) mkDefault mkForce;
inherit (lib.attrsets) optionalAttrs;
inherit (lib.options) mkOption mkEnableOption;
in {
imports = [
Expand Down Expand Up @@ -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 <nixpkgs> {};
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 <nixpkgs> {};
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.
Expand Down
4 changes: 2 additions & 2 deletions host/common/root.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
};
Expand Down
11 changes: 6 additions & 5 deletions host/hamilton.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
...
}: let
inherit (lib.strings) optionalString;
inherit (config.my.lib.preservation) mkDirs mkFiles;
in {
imports = [
../hardware/hamilton.nix
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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"
];
Expand Down
6 changes: 3 additions & 3 deletions host/opt/aftix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit d56cbad

Please sign in to comment.