From d7402ae170f40457d4b71847fa6581789a0f08f5 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 23 Feb 2024 14:57:20 +0000 Subject: [PATCH] persist: stores: make naming more consistent --- modules/persist/stores/crypt.nix | 18 +++++++++--------- modules/persist/stores/plaintext.nix | 10 ++++++---- modules/persist/stores/private.nix | 14 +++++++------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/modules/persist/stores/crypt.nix b/modules/persist/stores/crypt.nix index 2d36dad9..7877b104 100644 --- a/modules/persist/stores/crypt.nix +++ b/modules/persist/stores/crypt.nix @@ -2,9 +2,9 @@ let persist-base = "/nix/persist"; - device = config.sane.persist.stores."cryptClearOnBoot".origin; - key = "${device}.key"; - underlying = sane-lib.path.concat [ persist-base "crypt/clearedonboot" ]; + origin = config.sane.persist.stores."cryptClearOnBoot".origin; + key = "${origin}.key"; + backing = sane-lib.path.concat [ persist-base "crypt/clearedonboot" ]; in lib.mkIf config.sane.persist.enable { @@ -17,8 +17,8 @@ lib.mkIf config.sane.persist.enable }; - fileSystems."${device}" = { - device = underlying; + fileSystems."${origin}" = { + device = backing; fsType = "fuse.gocryptfs"; options = [ # "nodev" # "Unknown parameter 'nodev'". gocryptfs requires this be passed as `-ko nodev` @@ -30,18 +30,18 @@ lib.mkIf config.sane.persist.enable noCheck = true; }; # let sane.fs know about our fileSystem and automatically add the appropriate dependencies - sane.fs."${device}".mount = { + sane.fs."${origin}".mount = { # technically the dependency on the keyfile is extraneous because that *happens* to # be needed to init the store. depends = let - cryptfile = config.sane.fs."${underlying}/gocryptfs.conf"; + cryptfile = config.sane.fs."${backing}/gocryptfs.conf"; keyfile = config.sane.fs."${key}"; in [ keyfile.unit cryptfile.unit ]; }; # let sane.fs know how to initialize the gocryptfs store, # and that it MUST do so - sane.fs."${underlying}/gocryptfs.conf".generated = let + sane.fs."${backing}/gocryptfs.conf".generated = let script = pkgs.writeShellScript "init-gocryptfs-store" '' backing="$1" passfile="$2" @@ -54,7 +54,7 @@ lib.mkIf config.sane.persist.enable ${pkgs.gocryptfs}/bin/gocryptfs -quiet -passfile "$passfile" -init "$backing" ''; in { - command = [ "${script}" underlying key ]; + command = [ "${script}" backing key ]; # we need the key in order to initialize the store depends = [ config.sane.fs."${key}".unit ]; }; diff --git a/modules/persist/stores/plaintext.nix b/modules/persist/stores/plaintext.nix index 34bdeb61..7eeab53a 100644 --- a/modules/persist/stores/plaintext.nix +++ b/modules/persist/stores/plaintext.nix @@ -3,13 +3,15 @@ let # TODO: parameterize! persist-base = "/nix/persist"; - plaintext-dir = config.sane.persist.stores."plaintext".origin; - plaintext-backing-dir = persist-base; #< TODO: scope this! -in lib.mkIf config.sane.persist.enable { + origin = config.sane.persist.stores."plaintext".origin; + backing = persist-base; #< TODO: scope this! +in { sane.persist.stores."plaintext" = { origin = lib.mkDefault "/mnt/persist/plaintext"; }; # TODO: scope this! - sane.fs."${plaintext-dir}".mount.bind = plaintext-backing-dir; + sane.fs = lib.mkIf config.sane.persist.enable { + "${origin}".mount.bind = backing; + }; } diff --git a/modules/persist/stores/private.nix b/modules/persist/stores/private.nix index c584c15b..a4ac149d 100644 --- a/modules/persist/stores/private.nix +++ b/modules/persist/stores/private.nix @@ -3,9 +3,9 @@ let # TODO: parameterize! persist-base = "/nix/persist"; - private-dir = config.sane.persist.stores."private".origin; + origin = config.sane.persist.stores."private".origin; # TODO: remove the `prefix` part of this (will require data migration) - private-backing-dir = sane-lib.path.concat [ persist-base config.sane.persist.stores."private".prefix "private" ]; + backing = sane-lib.path.concat [ persist-base config.sane.persist.stores."private".prefix "private" ]; in lib.mkIf config.sane.persist.enable { @@ -17,7 +17,7 @@ lib.mkIf config.sane.persist.enable ''; origin = lib.mkDefault "/mnt/persist/private"; defaultOrdering = let - private-unit = config.sane.fs."${private-dir}".unit; + private-unit = config.sane.fs."${origin}".unit; in { # auto create only after the store is mounted wantedBy = [ private-unit ]; @@ -27,8 +27,8 @@ lib.mkIf config.sane.persist.enable defaultMethod = "symlink"; }; - fileSystems."${private-dir}" = { - device = private-backing-dir; + fileSystems."${origin}" = { + device = backing; fsType = "fuse.gocryptfs"; options = [ "noauto" # don't try to mount, until the user logs in! @@ -44,9 +44,9 @@ lib.mkIf config.sane.persist.enable }; # let sane.fs know about the mount - sane.fs."${private-dir}".mount = {}; + sane.fs."${origin}".mount = {}; # it also needs to know that the underlying device is an ordinary folder - sane.fs."${private-backing-dir}".dir = {}; + sane.fs."${backing}".dir = {}; # TODO: could add this *specifically* to the .mount file for the encrypted fs? system.fsPackages = [ pkgs.gocryptfs ]; # fuse needs to find gocryptfs