Disable home impermanence
This commit is contained in:
@@ -7,10 +7,34 @@ let
|
||||
in {
|
||||
options = {
|
||||
sydnix.impermanence = {
|
||||
enable = mkOption {
|
||||
description = "Enable Impermanence";
|
||||
type = types.bool;
|
||||
default = false;
|
||||
enable = mkEnableOption "impermanence";
|
||||
|
||||
mutableDotfiles = {
|
||||
enable = mkEnableOption "dotfiles under impermanence";
|
||||
|
||||
# storeAt = mkOption {
|
||||
# default = "dots/config";
|
||||
# type = types.str;
|
||||
# # type = with types;
|
||||
# # addCheck
|
||||
# # path
|
||||
# # (x: cfg.mutableDotfiles.enable
|
||||
# # -> ! (elem x cfg.mutableDotfiles.directories));
|
||||
# };
|
||||
|
||||
files = mkOption {
|
||||
default = [];
|
||||
# FIXME: Inaccurate type.
|
||||
type = with types;
|
||||
listOf anything;
|
||||
};
|
||||
|
||||
directories = mkOption {
|
||||
default = [];
|
||||
# FIXME: Inaccurate type.
|
||||
type = with types;
|
||||
listOf anything;
|
||||
};
|
||||
};
|
||||
|
||||
directories = mkOption {
|
||||
@@ -28,10 +52,22 @@ in {
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.persistence."/persist/home/${config.home.username}" = {
|
||||
allowOther = true;
|
||||
directories = cfg.directories;
|
||||
files = cfg.files;
|
||||
};
|
||||
home.persistence = {
|
||||
"/persist/home/${config.home.username}" = {
|
||||
allowOther = true;
|
||||
directories = cfg.directories;
|
||||
files = cfg.files;
|
||||
};
|
||||
} // (if ! cfg.mutableDotfiles.enable
|
||||
then {}
|
||||
else {
|
||||
"/persist/dots/users/${config.home.username}/dots/" = {
|
||||
removePrefixDirectory = true;
|
||||
directories = cfg.mutableDotfiles.directories;
|
||||
files = cfg.mutableDotfiles.files;
|
||||
allowOther = true;
|
||||
};
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#!/usr/bin/env bb
|
||||
|
||||
;;; TODO: rewrite with fewer assumptions about the filesystem structure.
|
||||
;; TODO: rewrite with fewer assumptions about the filesystem structure. Perhaps
|
||||
;; we can achieve near-atomicity by doing to bulk of the work with a function
|
||||
;; `erase-home-darlings : FileSystem -> Maybe FileSystem`, which will not do any
|
||||
;; IO.
|
||||
|
||||
;;; TODO: option to either move OR copy
|
||||
;; TODO: option to either move OR copy
|
||||
|
||||
(require '[clojure.core.match :refer [match]]
|
||||
'[babashka.cli :as cli]
|
||||
'[clojure.pprint :as pp]
|
||||
'[clojure.tools.logging :as l]
|
||||
'[babashka.process :refer [shell check process] :as p])
|
||||
|
||||
(defn get-files [{:keys [rollback-to dataset]}]
|
||||
;; (prn rollback-to)
|
||||
;; (prn dataset)
|
||||
(let [snapshot (str dataset "@" rollback-to)
|
||||
diff (:out (shell {:out :string}
|
||||
"zfs diff -HF"
|
||||
@@ -139,9 +141,27 @@ More precisely,
|
||||
(defn -main [opts]
|
||||
(pp/pprint opts)
|
||||
(with-echoed-shell-commands
|
||||
(shell "mount" (:dataset opts) "/home")
|
||||
(let [files (get-files opts)]
|
||||
(archive-files opts files)
|
||||
(cycle-archives opts)
|
||||
(do-rollback opts))))
|
||||
|
||||
#_
|
||||
(def fs-ops
|
||||
{:zfs {:get-files zfs-get-files
|
||||
:rollback zfs-rollback}})
|
||||
|
||||
#_
|
||||
(defn -main [opts]
|
||||
(let [test-bin (fn [x]
|
||||
(printf "%s: %s\n"
|
||||
x (map str (fs/which-all x))))]
|
||||
(test-bin "mount")
|
||||
(test-bin "findmnt")
|
||||
(test-bin "zfs"))
|
||||
|
||||
(shell "mount")
|
||||
(shell "ls -la /home"))
|
||||
|
||||
(-main (cli/parse-opts *command-line-args* cli-spec))
|
||||
|
||||
@@ -20,6 +20,11 @@ in {
|
||||
default = [];
|
||||
};
|
||||
|
||||
persistGroupName = mkOption {
|
||||
default = "persist";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
files = mkOption {
|
||||
description = "";
|
||||
|
||||
@@ -45,10 +50,28 @@ in {
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
users.groups.${cfg.persistGroupName} = {
|
||||
name = cfg.persistGroupName;
|
||||
};
|
||||
|
||||
systemd.tmpfiles.settings = {
|
||||
"10-persist" = {
|
||||
"/persist" = {
|
||||
z = {
|
||||
group = cfg.persistGroupName;
|
||||
mode = "2775";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
boot.initrd.systemd.initrdBin = with pkgs; [
|
||||
zfs
|
||||
];
|
||||
|
||||
# TODO: Move this somewhere else.
|
||||
programs.fuse.userAllowOther = true;
|
||||
|
||||
boot.initrd.systemd.services.erase-darlings =
|
||||
let service = {
|
||||
description = "Rollback filesystem to a blank state on boot";
|
||||
@@ -77,28 +100,35 @@ in {
|
||||
then service
|
||||
else throw "sydnix.impermanence currently requires config.boot.initrd.systemd.enable'!";
|
||||
|
||||
systemd.services.erase-home-darlings = {
|
||||
description = "Rollback home to a blank state on boot";
|
||||
wantedBy = [
|
||||
"multi-user.target"
|
||||
];
|
||||
after = [
|
||||
"home.mount"
|
||||
];
|
||||
path = [ pkgs.zfs pkgs.babashka ];
|
||||
# unitConfig.DefaultDependencies = "no";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStart =
|
||||
let script = ./erase-home-darlings.clj;
|
||||
in ''${pkgs.babashka}/bin/bb "${script}" -n "${toString cfg.archiveLimit}" --dataset "${cfg.dataset}" --rollback-to "${cfg.rollbackTo}"'';
|
||||
systemd.services =
|
||||
let erase-home-darlings = {
|
||||
description = "Rollback home to a blank state on boot";
|
||||
wantedBy = [
|
||||
"local-fs-pre.target"
|
||||
"zfs-mount.service"
|
||||
];
|
||||
before = [
|
||||
"local-fs.target"
|
||||
"local-fs-pre.target"
|
||||
"zfs-mount.service"
|
||||
];
|
||||
path = [ pkgs.zfs pkgs.babashka pkgs.util-linux ];
|
||||
unitConfig.DefaultDependencies = "no";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStart =
|
||||
let script = ./erase-home-darlings.clj;
|
||||
in ''${pkgs.babashka}/bin/bb "${script}" -n "${toString cfg.archiveLimit}" --dataset "${cfg.dataset}" --rollback-to "${cfg.rollbackTo}"'';
|
||||
};
|
||||
stopIfChanged = false;
|
||||
restartIfChanged = false;
|
||||
};
|
||||
in {
|
||||
# inherit erase-home-darlings;
|
||||
};
|
||||
stopIfChanged = false;
|
||||
restartIfChanged = false;
|
||||
};
|
||||
|
||||
environment.persistence."/persist" = {
|
||||
environment.persistence."/persist/root" = {
|
||||
directories = cfg.directories;
|
||||
files = cfg.files;
|
||||
};
|
||||
|
||||
51
modules/nixos/niri.nix
Normal file
51
modules/nixos/niri.nix
Normal file
@@ -0,0 +1,51 @@
|
||||
{ config, lib, pkgs, niri, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.sydnix.niri;
|
||||
in {
|
||||
options = {
|
||||
sydnix.niri = {
|
||||
enable = mkEnableOption "Niri";
|
||||
};
|
||||
};
|
||||
|
||||
imports = [
|
||||
niri.nixosModules.niri
|
||||
];
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
programs.niri = {
|
||||
enable = true;
|
||||
};
|
||||
|
||||
services.pipewire.enable = true;
|
||||
|
||||
# programs.niri.enable = true;
|
||||
|
||||
# hardware = {
|
||||
# graphics = {
|
||||
# enable = true;
|
||||
# extraPackages = with pkgs; [
|
||||
# intel-media-sdk
|
||||
# mesa
|
||||
# ];
|
||||
# enable32Bit = true;
|
||||
# };
|
||||
# nvidia = {
|
||||
# open = false;
|
||||
# modesetting.enable = true;
|
||||
# };
|
||||
# };
|
||||
|
||||
# environment.systemPackages = with pkgs; [
|
||||
# fuzzel
|
||||
# ];
|
||||
|
||||
# services.xserver.videoDrivers = [ "qxl" "nvidia" ];
|
||||
# services.qemuGuest.enable = true;
|
||||
# services.spice-vdagentd.enable = true;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user