Large refactor

This commit is contained in:
Madeleine Sydney
2024-12-12 01:38:47 -07:00
parent 28b2aece65
commit 3f846d783a
5 changed files with 176 additions and 196 deletions

View File

@@ -21,60 +21,41 @@
};
};
outputs = { nixpkgs, ... }@inputs: {
nixosConfigurations = (
<<flake-outputs-nixos>>
);
};
}
#+end_src
outputs = { nixpkgs, ... }@inputs:
let list-nix-directory = dir:
builtins.attrNames
(nixpkgs.lib.filterAttrs
(k: _v: nixpkgs.lib.hasSuffix ".nix" k)
(builtins.readDir dir));
in {
# REVIEW: Why don't we put each module under nixosModules.<name>?
nixosModules.default =
let modules = list-nix-directory ./modules/nixos;
in { ... }: {
imports =
let x = builtins.map (m: ./modules/nixos/${m}) modules;
in x;
};
* Features
homeManagerModules.default =
let modules = list-nix-directory ./modules/home;
in { ... }: {
imports = builtins.map (m: ./modules/home/${m}) modules;
};
What are referred to as /features/ here largely correspond to Nix modules, but are
not limited to Nix modules.
nixosConfigurations = (
<<flake-outputs-nixos>>
);
** Impermanence
*** Flake input
#+begin_src nix :noweb-ref flake-inputs
impermanence.url = "github:nix-community/impermanence";
#+end_src
*** Top-level module
#+begin_src nix :tangle modules/system/impermanence.nix
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.sydnix.impermanence;
in {
options = {
sydnix.impermanence = {
<<sydnix-impermanence-options>>
homeConfigurations =
let users = builtins.readDir ./users;
mkUser = username: _v: import ./users/${username}/default.nix;
in
builtins.mapAttrs mkUser users;
};
};
config = mkIf cfg.enable (mkMerge [
]);
}
#+end_src
*** Options
**** =enable=
#+begin_src nix :noweb-ref sydnix-impermanence-options
enable = mkOption {
type = types.bool;
default = false;
};
#+end_src
* Machines
For every ~./hosts/NAME/configuration.nix~, define the system under the name ~NAME~.
@@ -85,8 +66,25 @@ let mkHost = k: v: nixpkgs.lib.nixosSystem {
system = import ./hosts/${k}/system.nix;
modules = [
./hosts/${k}/configuration.nix
inputs.self.nixosModules.default
inputs.disko.nixosModules.disko
# Directory name should always match host name.
({ ... }: { networking.hostName = k; })
# home-manager configuration.
inputs.home-manager.nixosModules.home-manager
({ config, lib, self, ... }: {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users =
lib.filterAttrs
(k: _v: builtins.elem k config.sydnix.users.users)
self.homeConfigurations;
})
];
};
in
@@ -101,94 +99,31 @@ builtins.mapAttrs mkHost (builtins.readDir ./hosts)
imports = [
./hardware-configuration.nix
./disko-config.nix
disko.nixosModules.disko
];
# boot.initrd.postDeviceCommands = ''
# if zfs list -t snapshot -H -o name \
# | grep -qE '^rpool/local/root@previous$'; then
# zfs destroy -r rpool/local/root@previous \
# && echo ">> >> previous previous snapshot destroyed << <<"
# else
# echo ">> >> no previous previous snapshot found << <<"
# fi
# zfs snapshot -r rpool/local/root@previous \
# && echo ">> >> pre-rollback snapshot taken << <<"
# zfs rollback -r rpool/local/root@blank \
# && echo ">> >> rollback complete << <<"
# '';
# boot.initrd.supportedFilesystems = [ "zfs" ];
# boot.supportedFilesystems = [ "zfs" ];
boot.initrd.enable = true;
boot.initrd.systemd.enable = true;
boot.initrd.systemd.initrdBin = with pkgs; [
zfs
coreutils
babashka
];
boot.initrd.systemd.services.erase-darlings = {
description = "Rollback filesystem to a blank state on boot";
wantedBy = [
"initrd.target"
sydnix = {
users.users = [
"crumb"
];
after = [
# "zfs-import.service"
"zfs-import-rpool.service"
];
before = [
"sysroot.mount"
];
path = [ pkgs.zfs ];
unitConfig.DefaultDependencies = "no";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = /* bash */ ''
zfs rollback -r rpool/local/root@blank \
&& echo ">> >> rollback complete << <<"
'';
};
systemd.services.erase-home-darlings = {
description = "Rollback home to a blank state on boot";
wantedBy = [
"multi-user.target"
];
before = [
# "basic.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}" 3'';
};
stopIfChanged = false;
restartIfChanged = false;
};
boot = {
initrd = {
enable = true;
systemd.enable = true;
# boot.loader.grub = {
# enable = true;
# device = "nodev";
# # device = "/dev/vda";
# efiSupport = true;
# efiInstallAsRemovable = true;
# };
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = false;
systemd.initrdBin = with pkgs; [
zfs
coreutils
babashka
];
};
loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = false;
};
};
# networking.hostName = "nixos-testbed";
networking.hostId = "238e9b1e"; # head -c 8 /etc/machine-id
@@ -196,6 +131,7 @@ builtins.mapAttrs mkHost (builtins.readDir ./hosts)
time.timeZone = "America/Denver";
i18n.defaultLocale = "en_US.UTF-8";
console = {
font = "Lat2-Terminus16";
# keyMap = "us";