117 Commits
Author SHA1 Message Date
marc 64ae9acfe9 Merge branch 'custom' into custom-p 2023-12-15 19:36:19 +01:00
marc 4492652779 stdin 2023-12-15 19:36:05 +01:00
marc 898d2dadc1 Merge branch 'custom' into custom-p 2023-12-15 19:33:40 +01:00
marc 7bd70b4fe1 env 2023-12-15 19:33:30 +01:00
marc f8666e735e Merge branch 'custom' into custom-p 2023-12-15 18:27:38 +01:00
marc 631e7cdc33 40 2023-12-15 18:25:39 +01:00
marc ff3c3271bf Merge branch 'custom' into custom-p 2023-12-13 18:46:20 +01:00
marc d27f4791df abcd1234 2023-12-13 18:46:13 +01:00
marc bd294d5252 Merge branch 'custom' into custom-p 2023-12-12 19:13:26 +01:00
marc dc243f0d5a true 2023-12-12 19:13:07 +01:00
marc e9f1162c77 Merge branch 'custom' into custom-p 2023-12-12 19:04:20 +01:00
marc e6ed033165 install packages 2023-12-12 19:04:09 +01:00
marc ffacaf1e12 Merge branch 'custom' into custom-p 2023-12-12 19:02:16 +01:00
marc a5d847843e nixos no laptop 2023-12-12 19:02:11 +01:00
marc c7fbc2a853 Merge branch 'custom' into custom-p 2023-11-14 17:05:00 +08:00
marc e57c016891 wrx 2023-11-14 17:04:44 +08:00
marc 196ff1291e Merge branch 'custom' into custom-p 2023-11-14 16:59:26 +08:00
marc 4a1cc42ea8 break if not possible 2023-11-14 16:59:18 +08:00
marc 9551320771 Merge branch 'custom' into custom-p 2023-11-14 16:57:46 +08:00
marc 62c4a4eb3a dont sign 2023-11-14 16:57:41 +08:00
marc 9ef9a4b248 fix 2023-11-14 16:57:03 +08:00
marc cc29b97421 flake -> nixos-zfs-installer 2023-11-14 16:56:46 +08:00
marc 837a9181b4 Merge branch 'custom' into custom-p 2023-11-14 16:50:38 +08:00
marc f9f3e89f87 mkpasswd2 2023-11-14 16:50:20 +08:00
marc c2b92b213e fix 2023-11-14 16:46:53 +08:00
marc ad9f105731 with p 2023-11-14 16:46:20 +08:00
marc e16c9cc6eb Merge branch 'custom' into custom-p 2023-11-14 16:46:10 +08:00
marc 53b9aee230 no p 2023-11-14 16:46:05 +08:00
marc fbeab0dbc4 fix 2023-11-14 16:45:56 +08:00
marc 3e46ee3a7d fix 2023-11-14 16:45:22 +08:00
marc c5a68ae77d fix 2023-11-14 16:44:51 +08:00
marc 32b2405a2d fix 2023-11-14 16:44:44 +08:00
marc eeb540a7b4 Merge branch 'custom' into custom-p 2023-11-14 16:31:59 +08:00
marc 675f163e62 nixos-generate-config 2023-11-14 16:31:52 +08:00
marc 922b6efdfe Merge branch 'custom' into custom-p 2023-11-14 16:28:52 +08:00
marc 5a2a2dcc07 fix mountpoint 2023-11-14 16:28:42 +08:00
marc 09d0f341c1 Merge branch 'custom' into custom-p 2023-11-14 16:26:03 +08:00
marc 10b5fe70d7 tricky mountpoint 2023-11-14 16:25:53 +08:00
marc 424b88aec6 Merge branch 'custom' into custom-p 2023-11-14 16:19:47 +08:00
marc dc574712f4 disk 2023-11-14 16:19:36 +08:00
marc e587aa5781 Merge branch 'custom' into custom-p 2023-11-14 16:12:37 +08:00
marc a881642d0d echo 2023-11-14 16:12:34 +08:00
marc 5fd6591d19 Merge branch 'custom' into custom-p 2023-11-14 16:10:47 +08:00
marc 327b58fbed break 2023-11-14 16:10:43 +08:00
marc 6385c467b8 Merge branch 'custom' into custom-p 2023-11-14 16:09:12 +08:00
marc c564c50e36 mustberoot 2023-11-14 16:09:07 +08:00
marc 4a461b6237 Merge branch 'custom' into custom-p 2023-11-14 16:07:38 +08:00
marc 0d17d8316a fix 2023-11-14 16:07:27 +08:00
marc e3f5ab60f0 Merge branch 'custom' into custom-p 2023-11-14 16:06:54 +08:00
marc 450f5fff16 fix 2023-11-14 16:06:51 +08:00
marc 614e552eb9 fix 2023-11-14 16:05:15 +08:00
marc d8577a8938 you must be root 2023-11-14 16:05:01 +08:00
marc f1e4854d72 root and connectivity 2023-11-14 16:02:14 +08:00
marc aced56e287 root and connectivity 2023-11-14 16:01:44 +08:00
marc 7b4ff30ef9 Merge branch 'custom' into custom-p 2023-11-14 15:55:17 +08:00
marc 0ad37939f6 log first 2023-11-14 15:55:10 +08:00
marc 084877a661 fix 2023-11-14 15:54:36 +08:00
marc 793f015374 Merge branch 'custom' into custom-p 2023-11-14 15:54:27 +08:00
marc 76ce1aa6b6 zfs 2023-11-14 15:54:20 +08:00
marc 5a2dfdb13c Merge branch 'custom' into custom-p 2023-11-14 15:51:53 +08:00
marc 2f61558a1d loading zfs module first 2023-11-14 15:51:43 +08:00
marc 1f2133e0be custom with docker 2023-11-14 15:49:56 +08:00
marc 796fc7930c docker stuff 2023-11-14 15:47:01 +08:00
marc b03687fd1f fix p in install.sh 2023-11-14 15:29:54 +08:00
marc b78cedddcb p 2023-11-14 15:28:23 +08:00
marc ca11c1770b Merge squash openzfs-guide 2023-11-14 15:26:57 +08:00
marc 3ba50bb195 fix 1 to 4 2023-06-28 16:06:58 +00:00
marc 9428bb3263 disable boot pool encryption 2023-06-28 14:07:12 +00:00
marc 54c95c7a6f zpool destroy -f 2023-06-28 13:13:30 +00:00
marc 0733ee3106 Swapoff 2023-06-28 13:11:25 +00:00
marc 7f438f4451 Encrypt pools back and force import zfs pools 2023-06-28 13:09:14 +00:00
marc 5abb237b6c fix efi partition number 2023-06-27 23:08:29 +00:00
marc ab10481652 test without zpool encryption 2023-06-27 22:19:42 +00:00
marc 4d6c98e75b abcd1234 2023-06-27 11:18:48 +00:00
marc efb53cd066 networking nixos host 2023-06-27 11:07:15 +00:00
marc dafd939d12 nixos host in flake 2023-06-27 11:06:16 +00:00
marc bcaa17d9d2 sh -> bash 2023-06-27 11:01:47 +00:00
marc 165bbdf8d3 import nixos host 2023-06-27 11:00:58 +00:00
marc cd180ce627 forgot to enable flakes 2023-06-27 10:30:46 +00:00
marc 7278b18607 fix for 2023-06-27 10:29:33 +00:00
marc 92b956fb1c import destroy export 2023-06-27 10:28:36 +00:00
marc ae8fa6e247 zpool labelclear 2023-06-27 10:26:56 +00:00
marc 367e9c0e3e destroying pools just in case 2023-06-27 10:24:45 +00:00
marc e7bf496f7a Unmount filesystems first just in case 2023-06-27 10:10:53 +00:00
marc 4b6997de33 antislash 2023-06-27 10:08:37 +00:00
marc c00627a811 SWAPSIZEGIB 2023-06-27 10:05:52 +00:00
marc a370b53f1d SWAPSIZE + 1 2023-06-27 10:05:07 +00:00
marc e1aa52a77e reserve + 1 2023-06-27 09:53:07 +00:00
marc 7b89415746 reservergib 2023-06-27 09:51:03 +00:00
marc 903a969d76 password input 2023-06-27 09:47:37 +00:00
marc 7a1de01ef3 exampleHost -> nixos 2023-06-27 09:45:31 +00:00
marc 8068bb1d81 no exit 2023-06-27 09:43:31 +00:00
marc f7e9f335e4 fix it for real 2023-06-27 10:46:26 +02:00
marc 5580032733 fix link in readme.org 2023-06-27 10:45:46 +02:00
marc 1cd6bd6cfc readme.org 2023-06-27 10:44:27 +02:00
marc 58606b8306 fix readme again 2023-06-27 10:43:55 +02:00
marc 4605a97544 fix 2023-06-27 10:43:21 +02:00
marc c798df9b55 readme 2023-06-27 10:42:51 +02:00
marc 5a168dab3e nixos host instead of exampleHost 2023-06-27 10:35:43 +02:00
marc 04260a676b no part in boot module 2023-06-27 10:31:37 +02:00
marc 131f3820dd install script 2023-06-27 10:29:45 +02:00
Maurice Zhou 35bb9dbe17 upgrade to nixos-23.05 stable
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-06-01 08:53:30 +02:00
Maurice Zhou 93f9b65c03 rm grub version
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-05-16 19:52:43 +02:00
Maurice Zhou 06b5564bc1 update to 23.05
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-05-16 19:16:31 +02:00
Maurice Zhou acffac3adf add link to example
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-24 10:47:25 +02:00
Maurice Zhou 097da98b35 add custom module template
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-22 08:07:12 +02:00
Maurice Zhou 60a713eb95 use kernelModules placeholder
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-19 14:05:06 +02:00
Maurice Zhou 19f86677d5 show debug info while mirroring efi boot loader
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-11 10:37:05 +02:00
Maurice Zhou ec295de0f4 pin to known good version
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-10 23:48:39 +02:00
Maurice Zhou db3c673a5f removable efi can not be tested in vm
Revert "turn off removableefi"

This reverts commit d6efac769e.
2023-04-09 20:18:39 +02:00
Maurice Zhou d6efac769e turn off removableefi
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-09 20:08:53 +02:00
Maurice Zhou ae5bd60194 add warning for mkpasswd
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-09 15:13:53 +02:00
Maurice Zhou 95cc3f34dd use coreutils-full
Signed-off-by: Maurice Zhou <yuchen@apvc.uk>
2023-04-07 18:29:54 +02:00
Maurice Zhou e62b4436e5 explicitly enable DHCP
Signed-off-by: Maurice Zhou <jasper@apvc.uk>
2023-04-05 12:51:43 +02:00
Maurice Zhou 802103921e fix users.users attrset name
Signed-off-by: Maurice Zhou <jasper@apvc.uk>
2023-04-05 12:11:41 +02:00
Maurice Zhou aa0a76aed2 use upstream user settings
Signed-off-by: Maurice Zhou <jasper@apvc.uk>
2023-04-05 11:33:36 +02:00
Maurice Zhou 74a8c0cc40 init
Signed-off-by: Maurice Zhou <jasper@apvc.uk>
2023-04-04 18:38:55 +02:00
22 changed files with 559 additions and 762 deletions
+10
View File
@@ -0,0 +1,10 @@
FROM alpine
RUN apk update
RUN apk add mkpasswd zfs
COPY LICENSE configuration.nix flake.lock flake.nix install.sh ./
COPY hosts ./
COPY modules ./
ENTRYPOINT [ "./install.sh" ]
+15 -21
View File
@@ -1,24 +1,18 @@
* Minimal NixOS Root on ZFS configuration
This repo contains a minimal set of configuration needed for
installing NixOS on a computer with ZFS as root filesystem.
* Install NixOS with ZFS as root filesystem
This repo contains a minimal set of configuration for installing
NixOS, using ZFS as root filesystem.
#+begin_src text
.gitignore
LICENSE
configuration.nix <- configuration shared by all hosts
flake.lock
flake.nix
hosts/exampleHost/default.nix <- per-host configuration
hosts/exampleHost/sshUnlock.txt
modules/boot/default.nix
modules/default.nix
modules/fileSystems/default.nix
modules/networking/default.nix
modules/users/default.nix
#+end_src
ZFS is a modern filesystem with many features such as snapshot,
self-healing and pooled storage, see [[https://openzfs.org/wiki/Main_Page#Introduction_to_OpenZFS][Introduction]] for details.
Just enough to get you started.
For using this repo on your computer, see [[https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/Root%20on%20ZFS.html][Documentation]].
See [[https://github.com/ne9z/personal-dotfiles][my personal dotfiles repo]] for an example of how to configure
servers and desktop computers in the same git repository, based on
this template repo you are viewing now.
Upon initial installation, only the bootloader, mountpoints and root
password are configured.
- Refer to =man configuration.nix= for available options;
- Search for available packages with [[https://search.nixos.org/packages][Package Search]];
- Search for options with [[https://search.nixos.org/options][Option Search]].
[[https://codeberg.org/m0p/dotfiles][My personal dotfiles repo]] contains an example of desktop configuration
based on sway, tmux and Emacs.
+60 -396
View File
@@ -1,180 +1,37 @@
{
my-config, zfs-root, inputs, pkgs, lib, ...
}:
let
kubeMasterIP = "10.1.1.2";
kubeMasterHostname = "api.kube";
kubeMasterAPIServerPort = 6443;
# tokyo-night-sddm = pkgs.libsForQt5.callPackage ./themes/tokyo-night-sddm.nix { };
sddm-peace-color = pkgs.libsForQt5.callPackage ./themes/sddm-peace-color.nix { };
# sddm-apple = pkgs.libsForQt5.callPackage ./themes/sddm-apple.nix { };
unstable = import <nixpkgs-unstable> { config.allowUnfree = true; };
in
{
# load module config to top-level configuration
inherit my-config zfs-root;
# Let 'nixos-version --json' know about the Git revision
# of this flake.
system.configurationRevision = if (inputs.self ? rev) then
inputs.self.rev
else
throw "refuse to build: git tree is dirty";
system.stateVersion = "23.11";
# system.activationScripts = {
# enableLingering = ''
# # remove all existing lingering users
# rm -r /var/lib/systemd/linger
# mkdir /var/lib/systemd/linger
# # enable for the subset of declared users
# touch /var/lib/systemd/linger/marc
# '';
# };
# config.systemd.user.services.nixos-activation.unitConfig.ConditionUser = mkForce
# [
# "!@system"
# "!marc"
# ];
boot.zfs.forceImportRoot = lib.mkDefault false;
# boot.loader.systemd-boot.enable = true;
boot.initrd.systemd.enable = true;
# boot.loader.efi.canTouchEfiVariables = true;
boot.plymouth.enable = true;
boot.plymouth.theme = "breeze";
virtualisation.docker.enable = true;
# configuration in this file is shared by all hosts
{ pkgs, pkgs-unstable, inputs, ... }:
let inherit (inputs) self;
in {
# Enable NetworkManager for wireless networking,
# You can configure networking with "nmtui" command.
# networking.useDHCP = true;
networking.hostName = "tower";
networking.networkmanager.enable = true;
networking.wireless.iwd.enable = true;
networking.networkmanager.wifi.backend = "iwd";
services = {
# plex = {
# enable = true;
# dataDir = "/var/lib/plex";
# openFirewall = true;
# user = "plex";
# group = "plex";
# };
# hardware.pulseaudio.enable = true;
# services.transmission.settings = {
# download-dir = "${config.services.transmission.home}/Downloads";
# };
pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
jack.enable = true;
pulse.enable = true;
socketActivation = true;
};
# Enable the X11 windowing system.
xserver = {
enable = true;
layout = "us";
videoDrivers = [ "amdgpu" ];
# windowManager.i3.enable = true;
desktopManager.plasma5.enable = true;
desktopManager.xterm.enable = true;
displayManager = {
defaultSession = "hyprland";
# autoLogin = {
# enable = true;
# user = "marc";
# };
sddm = {
enable = false;
# wayland.enable = true;
# theme = "sddm-apple";
theme = "sddm-peace-color";
};
lightdm = {
enable = false;
# greeter.enable = true; fonts
};
gdm.enable = true;
session = [
# {
# manage = "desktop";
# name = "xterm";
# start = ''
# ${pkgs.xterm}/bin/xterm -ls &
# waitPID=$!
# '';
# }
{
manage = "desktop";
name = "firefox";
start = ''
${pkgs.firefox}/bin/firefox &
waitPID=$!
'';
}
];
};
};
openssh = {
enable = lib.mkDefault true;
settings = { PasswordAuthentication = lib.mkDefault true; };
};
};
hardware.bluetooth.enable = true;
# amd support with vulkan
hardware.opengl.driSupport = true;
hardware.opengl.extraPackages = with pkgs; [
rocm-opencl-icd
rocm-opencl-runtime
amdvlk
];
fonts.packages = with pkgs; [
noto-fonts
noto-fonts-cjk
noto-fonts-emoji
liberation_ttf
fira-code
fira-code-symbols
mplus-outline-fonts.githubRelease
dina-font
proggyfonts
source-code-pro
];
# services.xserver.enable = true;
# services.xserver.displayManager.gdm.enable = true;
programs.hyprland.enable = true;
programs.dconf.enable = true; # apply gtk themes in wayland apps
networking.useDHCP = true;
networking.networkmanager.enable = false;
users.users = {
root = {
isNormalUser = false;
shell = pkgs.zsh;
initialHashedPassword = "$6$0QAYnBqAJtqB12p3$2lb7rAS2sYw49GUJt0L0bAEpZJSv4HZARQjlbYPhexSmeRB71IRMBzXjf3b4rX6fuDxOuDLydP/Kni9uraS5j/";
openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDiUE73uIEgijfmSsDwBvZmecQnqjBUPRKlMDmevsThc1YJNWEHl57NNIUcx6XSCDPKu5azayImLqIBt8wT5xlqtNX20uCnikDfXZ8gFbGlMRTGZKutQZIRmUrUS5mz97S4dVVK+n5WU+OwOfEg/XKXPh4WbTVDpfTTg7RopRAXkma56HV2TJM0ndPRN8VLmBmtnwdQwEpJ0tRRY+KOHmTojsH65eaZ89+BHbto+Kg+lk6x8IH5VDCRQNHgTEccOpOGYBSHRpoZi1a5h3yajf/eGAQ9Cd38DOsfMtm84oFlii7oXPyxwXoM+uH1SDnvLXyheIrV/XLUurSbEb4aJni6Zu79Z9l8xHhUNmVNSZqWOWUvPbAHlDKUzsbxgk9Zs9OTvSDaRzGhViYl4e1Qc993yerGSW1HHIvYUKM7o5nSQqskSOvOI+ahL5fIbgdyVx4FeuURZIyZSxCz4jIJTK15/6pkT/miHKv+vmQhsoLCqgyXY4SG1p9ruzKkzBe03ZQVW5WeFDLYRjZ+Z4Q2IL2K3BmLgp8tInkPJizQ7v5UGSiajJmPxY0j+CqdH9ZlIBdf8GS+run/N4hpMC1/ayUZRbCY5jg4c8bev8dKEZYJKPs/Hq2zLRZe4YtxcKuiGhgIwQOzo/QrCvSM4pVDgo+d2DjEzIdapqE8hF6BHWDg/w== marc.partensky@gmail.com" ];
initialHashedPassword = "rootHash_placeholder";
openssh.authorizedKeys.keys = [ "sshKey_placeholder" ];
};
marc = {
isNormalUser = true;
home = "/home/marc";
description = "Marc Partensky";
extraGroups = ["wheel" "networkmanager" "docker" "seat" "kvm" "video"];
# openssh.authorizedKeys.keys =
shell = pkgs.zsh;
initialHashedPassword = "$6$0QAYnBqAJtqB12p3$2lb7rAS2sYw49GUJt0L0bAEpZJSv4HZARQjlbYPhexSmeRB71IRMBzXjf3b4rX6fuDxOuDLydP/Kni9uraS5j/";
openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDiUE73uIEgijfmSsDwBvZmecQnqjBUPRKlMDmevsThc1YJNWEHl57NNIUcx6XSCDPKu5azayImLqIBt8wT5xlqtNX20uCnikDfXZ8gFbGlMRTGZKutQZIRmUrUS5mz97S4dVVK+n5WU+OwOfEg/XKXPh4WbTVDpfTTg7RopRAXkma56HV2TJM0ndPRN8VLmBmtnwdQwEpJ0tRRY+KOHmTojsH65eaZ89+BHbto+Kg+lk6x8IH5VDCRQNHgTEccOpOGYBSHRpoZi1a5h3yajf/eGAQ9Cd38DOsfMtm84oFlii7oXPyxwXoM+uH1SDnvLXyheIrV/XLUurSbEb4aJni6Zu79Z9l8xHhUNmVNSZqWOWUvPbAHlDKUzsbxgk9Zs9OTvSDaRzGhViYl4e1Qc993yerGSW1HHIvYUKM7o5nSQqskSOvOI+ahL5fIbgdyVx4FeuURZIyZSxCz4jIJTK15/6pkT/miHKv+vmQhsoLCqgyXY4SG1p9ruzKkzBe03ZQVW5WeFDLYRjZ+Z4Q2IL2K3BmLgp8tInkPJizQ7v5UGSiajJmPxY0j+CqdH9ZlIBdf8GS+run/N4hpMC1/ayUZRbCY5jg4c8bev8dKEZYJKPs/Hq2zLRZe4YtxcKuiGhgIwQOzo/QrCvSM4pVDgo+d2DjEzIdapqE8hF6BHWDg/w== marc.partensky@gmail.com" ];
};
## enable GNOME desktop.
## You need to configure a normal, non-root user.
# services.xserver = {
# enable = true;
# desktopManager.gnome.enable = true;
# displayManager.gdm.enable = true;
# };
## enable ZFS auto snapshot on datasets
## You need to set the auto snapshot property to "true"
## on datasets for this to work, such as
# zfs set com.sun:auto-snapshot=true rpool/nixos/home
services.zfs = {
autoSnapshot = {
enable = false;
flags = "-k -p --utc";
monthly = 48;
};
};
@@ -184,243 +41,50 @@ in
vimAlias = true;
};
imports = [
"${inputs.nixpkgs}/nixos/modules/installer/scan/not-detected.nix"
# "${inputs.nixpkgs}/nixos/modules/profiles/qemu-guest.nix"
];
nixpkgs = {
config = {
allowUnfree = true;
packageOverrides = pkgs: {
unstable = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") {};
};
};
services.openssh = {
enable = true;
settings = { PasswordAuthentication = false; };
};
boot.zfs.forceImportRoot = false;
# kubernetes https://nixos.wiki/wiki/K3s
networking.firewall.allowedTCPPorts = [ 6443 5900 ];
# services.k3s = {
# enable = true;
# role = "server";
# # TODO describe how to enable zfs snapshotter in containerd
# extraFlags = toString [
# "--container-runtime-endpoint unix:///run/containerd/containerd.sock"
# ];
# };
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# kubernetes zfs support
# virtualisation.containerd = {
# enable = true;
# settings =
# let
# fullCNIPlugins = pkgs.buildEnv {
# name = "full-cni";
# paths = with pkgs;[
# cni-plugins
# cni-plugin-flannel
# ];
# };
# in {
# plugins."io.containerd.grpc.v1.cri".cni = {
# bin_dir = "${fullCNIPlugins}/bin";
# conf_dir = "/var/lib/rancher/k3s/agent/etc/cni/net.d/";
# };
# };
# };
# kubernetes support
# resolve master hostname
# networking.extraHosts = "${kubeMasterIP} ${kubeMasterHostname}";
# services.kubernetes = {
# roles = ["master" "node"];
# masterAddress = kubeMasterHostname;
# apiserverAddress = "https://${kubeMasterHostname}:${toString kubeMasterAPIServerPort}";
# easyCerts = true;
# apiserver = {
# securePort = kubeMasterAPIServerPort;
# advertiseAddress = kubeMasterIP;
# };
# # use coredns
# addons.dns.enable = true;
# # needed if you use swap
# kubelet.extraOpts = "--fail-swap-on=false";
# };
nix.settings.experimental-features = lib.mkDefault [ "nix-command" "flakes" ];
boot.initrd.systemd.enable = true;
programs.git.enable = true;
programs.zsh.enable = true;
security = {
doas.enable = lib.mkDefault true;
sudo.enable = lib.mkDefault false;
doas.enable = true;
sudo.enable = false;
};
nix = {
package = pkgs.nixFlakes;
extraOptions = ''
experimental-features = nix-command flakes
'';
};
# systemd.services.tunneltower = {
# enable = true;
# description = "Connect to my tower remotely";
# unitConfig = {
# # Type = "simple";
# };
# serviceConfig = {
# ExecStart = ''
# ${pkgs.autossh}/bin/autossh -M 0 \
# -o ServerAliveInterval=30 \
# -o ServerAliveCountMax=3 \
# -o PubkeyAuthentication=yes \
# -o PasswordAuthentication=no \
# -NR localhost:42070:localhost:22 \
# -p 42069 \
# -i ~/.ssh/id_rsa \
# marc@207.180.235.56
# '';
# };
# wantedBy = [ "multi-user.target" ];
# };
boot.kernelParams = [
"i915.enable_psr=0"
];
powerManagement.enable = false;
systemd.targets.sleep.enable = false;
systemd.targets.suspend.enable = false;
systemd.targets.hibernate.enable = false;
systemd.targets.hybrid-sleep.enable = false;
services.xserver.displayManager.gdm.autoSuspend = false;
environment.etc."systemd/sleep.conf".text = ''
[Sleep]
AllowSuspend=no
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no
#SuspendMode=
#SuspendState=mem standby freeze
#HibernateMode=platform shutdown
#HibernateState=disk
#HybridSleepMode=suspend platform shutdown
#HybridSleepState=disk
#HibernateDelaySec=180min
'';
systemd.timers.tunneltower = {
wantedBy = [ "timers.target" ];
timerConfig = {
# OnBootSec = "1d";
# OnUnitActiveSec = "1d";
Unit = "tunneltower";
Persistent = true;
# OnCalendar = "*-*-* 5:00:00";
OnBootSec="15min";
OnUnitActiveSec="1d";
};
};
#
# environment.systemPackages = builtins.attrValues {
# inherit (pkgs)
# k3s
# autossh
# jq # other programs
# neovim
# stow
# coreutils
# gnumake
# bat
# gnupg
# nome-manager
# htop
# kompose
# kubectl
# kubernetes
# killall
# seatd
# mcfly
# sddm
# # tokyo-night-sddm
# ;
# };
environment.systemPackages = with pkgs;
[
k3s
autossh
environment.systemPackages = builtins.attrValues {
inherit (pkgs)
mg # emacs-like editor
jq # other programs
neovim
stow
coreutils
gnumake
bat
gnupg
home-manager
htop
kompose
kubectl
kubernetes
killall
seatd
mcfly
sddm
sddm-peace-color
# sddm-apple
sddm-kcm
transmission-gtk
xterm
alacritty
p7zip
# unstable.alacritty
# plasma-desktop
# plasma-workspace
# plasma-workspace-wallpapers
# tokyo-night-sddm
# sddm-theme-dialog
# (callPackage ./themes/sddm-theme-dialog.nix {}).sddm-theme-dialog
];
i18n.defaultLocale = "fr_FR.UTF-8";
i18n.extraLocaleSettings = {
LC_ADDRESS = "fr_FR.UTF-8";
LC_IDENTIFICATION = "fr_FR.UTF-8";
LC_MEASUREMENT = "fr_FR.UTF-8";
LC_MONETARY = "fr_FR.UTF-8";
LC_NAME = "fr_FR.UTF-8";
LC_NUMERIC = "fr_FR.UTF-8";
LC_PAPER = "fr_FR.UTF-8";
LC_TELEPHONE = "fr_FR.UTF-8";
LC_TIME = "fr_FR.UTF-8";
;
# By default, the system will only use packages from the
# stable channel. i.e.
# inherit (pkg) my-favorite-stable-package;
# You can selectively install packages
# from the unstable channel. Such as
# inherit (pkgs-unstable) my-favorite-unstable-package;
# You can also add more
# channels to pin package version.
};
environment.sessionVariables = {
# POLKIT_AUTH_AGENT = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
# GSETTINGS_SCHEMA_DIR = "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}/glib-2.0/schemas";
# LIBVA_DRIVER_NAME = "nvidia";
# XDG_SESSION_TYPE = "wayland";
# GBM_BACKEND = "nvidia-drm";
# __GLX_VENDOR_LIBRARY_NAME = "nvidia";
# WLR_NO_HARDWARE_CURSORS = "1";
# NIXOS_OZONE_WL = "1";
# MOZ_ENABLE_WAYLAND = "1";
# SDL_VIDEODRIVER = "wayland";
# _JAVA_AWT_WM_NONREPARENTING = "1";
# CLUTTER_BACKEND = "wayland";
# WLR_RENDERER = "vulkan";
# XDG_CURRENT_DESKTOP = "Hyprland";
# XDG_SESSION_DESKTOP = "Hyprland";
# GTK_USE_PORTAL = "1";
# NIXOS_XDG_OPEN_USE_PORTAL = "1";
};
# Safety mechanism: refuse to build unless everything is
# tracked by git
system.configurationRevision = if (self ? rev) then
self.rev
else
throw "refuse to build: git tree is dirty";
system.stateVersion = "23.05";
# let nix commands follow system nixpkgs revision
nix.registry.nixpkgs.flake = inputs.nixpkgs;
# you can then test any package in a nix shell, such as
# $ nix shell nixpkgs#neovim
}
+5
View File
@@ -0,0 +1,5 @@
version: "3.9"
services:
nixos-zfs-installer:
image: marcpartensky/nixos-zfs-installer
build: .
Generated
+47 -10
View File
@@ -1,24 +1,61 @@
{
"nodes": {
"nixpkgs": {
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1714253743,
"narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994",
"lastModified": 1695108154,
"narHash": "sha256-gSg7UTVtls2yO9lKtP0yb66XBHT1Fx5qZSZbGMpSn2c=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "07682fff75d41f18327a871088d20af2710d4744",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"owner": "nix-community",
"ref": "release-23.05",
"repo": "home-manager",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1696983906,
"narHash": "sha256-L7GyeErguS7Pg4h8nK0wGlcUTbfUMDu+HMf1UcyP72k=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bd1cde45c77891214131cbbea5b1203e485a9d51",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-23.05",
"type": "indirect"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1697349934,
"narHash": "sha256-mSOXTIvCMA31nD/XEYmeSOebrXl0lFKirM14LK845e4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f320b0d46ee33f521f50d7c6885605714210e5c9",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "master",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"home-manager": "home-manager",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable"
}
}
},
+49 -15
View File
@@ -1,27 +1,61 @@
{
# inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
## after reboot, you can track rolling release by using
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
description = "Barebones NixOS on ZFS config";
outputs = { self, nixpkgs }@inputs:
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05";
nixpkgs-unstable.url = "nixpkgs/master";
home-manager = {
url = "github:nix-community/home-manager/release-23.05";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixpkgs-unstable, home-manager }@inputs:
let
lib = nixpkgs.lib;
mkHost = { my-config, zfs-root, pkgs, system, ... }:
lib.nixosSystem {
inherit system;
mkHost = hostName: system:
nixpkgs.lib.nixosSystem {
pkgs = import nixpkgs {
inherit system;
# settings to nixpkgs goes to here
# nixpkgs.pkgs.zathura.useMupdf = true;
# nixpkgs.config.allowUnfree = false;
};
specialArgs = {
# By default, the system will only use packages from the
# stable channel. You can selectively install packages
# from the unstable channel. You can also add more
# channels to pin package version.
pkgs-unstable = import nixpkgs-unstable {
inherit system;
# settings to nixpkgs-unstable goes to here
};
# make all inputs availabe in other nix files
inherit inputs;
};
modules = [
# Root on ZFS related configuration
./modules
(import ./configuration.nix {
inherit my-config zfs-root inputs pkgs lib;
})
# Configuration shared by all hosts
./configuration.nix
# Configuration per host
./hosts/${hostName}
# home-manager
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
};
in {
nixosConfigurations = {
tower = let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in mkHost (import ./hosts/tower { inherit system pkgs; });
nixos = mkHost "nixos" "x86_64-linux";
};
};
}
+39
View File
@@ -0,0 +1,39 @@
How to set hostname for a host.
You need to change the host name in three different places.
Place 1.
./flake.nix
Change
exampleHost = mkHost "exampleHost" "x86_64-linux";
to
myHost = mkHost "myHost" "x86_64-linux";
Place 2.
Move directory
./hosts/exampleHost
to
./hosts/myHost
Place 3.
./hosts/exampleHost/default.nix
Change
networking.hostName = "exampleHost";
to
networking.hostName = "myHost";
End.
+24
View File
@@ -0,0 +1,24 @@
{ config, pkgs, lib, inputs, modulesPath, ... }: {
zfs-root = {
boot = {
devNodes = "/dev/disk/by-id/";
bootDevices = [ "bootDevices_placeholder" ];
immutable.enable = false;
removableEfi = true;
luks.enable = true;
};
};
boot.initrd.availableKernelModules = [ "kernelModules_placeholder" ];
boot.kernelParams = [ ];
networking.hostId = "abcd1234";
# read changeHostName.txt file.
networking.hostName = "nixos";
time.timeZone = "Europe/Paris";
# import preconfigured profiles
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
# (modulesPath + "/profiles/hardened.nix")
# (modulesPath + "/profiles/qemu-guest.nix")
];
}
-45
View File
@@ -1,45 +0,0 @@
How to set hostname for a host.
This repo is structured in a way that allows managing multiple hosts
in a single repo. As a consequence of this, hostname appears in
several different places and should be updated together if needed.
The entry point of this repo is ``flake.nix'' file, which takes a
revision of the nixpkgs as input then gives an attribute set (attrset)
as output:
{
nixosConfigurations = {
exampleHost = { ... };
host2 = { ... };
host3 = { ... };
...
};
}
The hostname specified here inside nixosConfigurations attrset is used
when ``nix command'' is invoked, as in
nixos-install --flake ./#exampleHost
The hostname also appears in the filesystem path of the per-host
configuration file:
hosts/exampleHost/default.nix
hosts/host2/default.nix
...
Finally, the hostname is specified in the zfs-boot.networking.hostName
option inside per-host configuration file at
hosts/exampleHost/default.nix:
zfs-boot.networking.hostName = "exampleHost";
If the value of this option is identical to the name of
nixosConfigurations.<hostname> attrset, all subsequent invocations of
``nix command'' will default to this hostname, i.e. the command:
nixos-rebuild boot
will automatically append ``#hostName'' when evaluating the flake.
-37
View File
@@ -1,37 +0,0 @@
# #
##
## per-host configuration for exampleHost
##
##
{ system, pkgs, ... }: {
inherit pkgs system;
zfs-root = {
boot = {
devNodes = "/dev/";
bootDevices = [ "nvme0n1" ];
immutable = false;
availableKernelModules = [ "nvme" "xhci_pci" "usbhid" "usb_storage" "sd_mod" ];
removableEfi = true;
kernelParams = [ ];
sshUnlock = {
# read sshUnlock.txt file.
enable = false;
authorizedKeys = [ ];
};
};
networking = {
# read changeHostName.txt file.
hostName = "tower";
timeZone = "Europe/Paris";
hostId = "97a4a6a0";
};
};
# To add more options to per-host configuration, you can create a
# custom configuration module, then add it here.
my-config = {
# Enable custom gnome desktop on exampleHost
template.desktop.gnome.enable = false;
};
}
Executable
+271
View File
@@ -0,0 +1,271 @@
#!/usr/bin/env bash
log() { echo -e "\n\033[1m${@}\033[0m"; }
log Checking root
mustberoot() {
log You must be root
exit 1
}
whoami | grep root || mustberoot
log Checking connectivity
curl -s google.com > /dev/null || exit 1
log Loading zfs module first
modprobe zfs || exit 1
log Installing packages
nix-env -f '<nixpkgs>' -iA git jq parted fzf
echo ""
lsblk
echo ""
# read -p "disk: " DISK
DISK=`lsblk | grep disk | grep -v SWAP | awk '{print $1}' | fzf`
DISK=`echo /dev/$DISK`
log $disk
read -p "swapsize GiB: " SWAPSIZEGIB
read -p "reserve GiB: " RESERVEGIB
read -sp "password: " POOLPASS
EMAIL="marc@marcpartensky.com"
NAME="Marc Partensky"
RESERVE=$((RESERVEGIB * 1024))
SWAPSIZE=$((SWAPSIZEGIB * 1024))
MNT=$(mktemp -d)
log Destroying zfs pool rpool and bpool just in case
swapoff -a
zpool import -fa
for i in ${DISK}; do
zpool labelclear -f $i
done
zpool destroy -f bpool
zpool destroy -f rpool
zpool export -a
log Unmounting filesystems just in case
# ---
umount -Rl "${MNT}"
log Enabling Nix Flakes functionality
# ---
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
log Installing programs needed for system installation
log Partition the disks
# ---
partition_disk () {
local disk=$1
blkdiscard -f $disk || true
parted --script --align=optimal $disk -- \
mklabel gpt \
mkpart swap 1MiB $((SWAPSIZE + 1))MiB \
mkpart rpool $((SWAPSIZE + 1))MiB -$((RESERVE + 100))MiB \
mkpart bpool -$((RESERVE + 100))MiB -$((RESERVE + 40))MiB \
mkpart EFI -$((RESERVE + 40))MiB -$((RESERVE + 2))MiB \
mkpart BIOS -$((RESERVE + 2))MiB -$((RESERVE + 1))MiB \
set 4 esp on \
set 5 bios_grub on \
set 5 legacy_boot on
partprobe $disk
udevadm settle
}
for i in $DISK; do
partition_disk $i || exit 1
done
log disk $DISK
log Creating boot pool
# ---
# shellcheck disable=SC2046
createbpool="zpool create \
-o compatibility=grub2 \
-o ashift=12 \
-o autotrim=on \
-O acltype=posixacl \
-O canmount=off \
-O compression=lz4 \
-O devices=off \
-O normalization=formD \
-O relatime=on \
-O xattr=sa \
-m /boot \
-R $MNT \
bpool \
`for i in $DISK; do
printf '%s ' ${i}p3
done`"
echo $createbpool
eval $createbpool
log Creating root pool
# ---
# shellcheck disable=SC2046
echo $POOLPASS | zpool create \
-o ashift=12 \
-o autotrim=on \
-R $MNT \
-O acltype=posixacl \
-O canmount=off \
-O compression=zstd \
-O dnodesize=auto \
-O normalization=formD \
-O relatime=on \
-O xattr=sa \
-o feature@encryption=enabled \
-O encryption=on \
-O keyformat=passphrase \
-m / \
rpool \
$(for i in $DISK; do
printf '%s ' "${i}p2";
done)
log Creating encrypted root system container
# ---
echo $POOLPASS | zfs create \
-o canmount=off \
-o mountpoint=none \
-o encryption=on \
-o keylocation=prompt \
-o keyformat=passphrase \
rpool/nixos
log Creating system datasets, managing mountpoints with mountpoint=legacy
# ---
zfs create -o mountpoint=legacy rpool/nixos/root
mount -t zfs rpool/nixos/root "${MNT}"/
zfs create -o mountpoint=legacy rpool/nixos/home
mkdir "${MNT}"/home
mount -t zfs rpool/nixos/home "${MNT}"/home
zfs create -o mountpoint=legacy rpool/nixos/var
zfs create -o mountpoint=legacy rpool/nixos/var/lib
zfs create -o mountpoint=legacy rpool/nixos/var/log
zfs create -o mountpoint=none bpool/nixos
zfs create -o mountpoint=legacy bpool/nixos/root
mkdir "${MNT}"/boot
mount -t zfs bpool/nixos/root "${MNT}"/boot
mkdir -p "${MNT}"/var/log
mkdir -p "${MNT}"/var/lib
mount -t zfs rpool/nixos/var/lib "${MNT}"/var/lib
mount -t zfs rpool/nixos/var/log "${MNT}"/var/log
zfs create -o mountpoint=legacy rpool/nixos/empty
zfs snapshot rpool/nixos/empty@start
log Formatting and mounting ESP
# ---
for i in ${DISK}; do
mkfs.vfat -n EFI "${i}"p4
mkdir -p "${MNT}"/boot/efis/"${i##*/}"p4
mount -t vfat -o iocharset=iso8859-1 "${i}"p4 "${MNT}"/boot/efis/"${i##*/}"p4
done
log Cloning template flake configuration
# ---
mkdir -p "${MNT}"/etc
git clone --depth 1 --branch custom \
https://github.com/marcpartensky/nixos-zfs-installer.git "${MNT}"/etc/nixos
rm -rf "${MNT}"/etc/nixos/.git
git -C "${MNT}"/etc/nixos/ init -b master
git -C "${MNT}"/etc/nixos/ add "${MNT}"/etc/nixos/
git -C "${MNT}"/etc/nixos config user.email $EMAIL
git -C "${MNT}"/etc/nixos config user.name $NAME
git -C "${MNT}"/etc/nixos commit -nasm 'initial commit'
log Customizing configuration to your hardware
# ---
for i in ${DISK}; do
sed -i \
"s|/dev/disk/by-id/|${i%/*}/|" \
"${MNT}"/etc/nixos/hosts/nixos/default.nix
break
done
diskNames=""
for i in ${DISK}; do
diskNames="${diskNames} \"${i##*/}\""
done
sed -i "s|\"bootDevices_placeholder\"|${diskNames}|g" \
"${MNT}"/etc/nixos/hosts/nixos/default.nix
sed -i "s|\"abcd1234\"|\"$(head -c4 /dev/urandom | od -A none -t x4| sed 's| ||g' || true)\"|g" \
"${MNT}"/etc/nixos/hosts/nixos/default.nix
sed -i "s|\"x86_64-linux\"|\"$(uname -m || true)-linux\"|g" \
"${MNT}"/etc/nixos/flake.nix
cp "$(command -v nixos-generate-config || true)" ./nixos-generate-config
chmod a+rwx ./nixos-generate-config
# shellcheck disable=SC2016
echo 'print STDOUT $initrdAvailableKernelModules' >> ./nixos-generate-config
kernelModules="$(./nixos-generate-config --show-hardware-config --no-filesystems | tail -n1 || true)"
sed -i "s|\"kernelModules_placeholder\"|${kernelModules}|g" \
"${MNT}"/etc/nixos/hosts/nixos/default.nix
log Setting root password
# ---
rootPwd=$(echo $POOLPASS | mkpasswd -sm SHA-512)
sed -i \
"s|rootHash_placeholder|${rootPwd}|" \
"${MNT}"/etc/nixos/configuration.nix
log Commiting changes to local repo
# ---
git -C "${MNT}"/etc/nixos commit -asm 'initial installation'
log Updating flake lock file to track latest system version
# ---
nix flake update --commit-lock-file \
"git+file://${MNT}/etc/nixos"
log Installing system and apply configuration
# ---
nixos-install \
--root "${MNT}" \
--no-root-passwd \
--flake "git+file://${MNT}/etc/nixos#nixos"
log Setuping encrypted swap. This is useful if the available memory is small
# ---
for i in ${DISK}; do
cryptsetup open --type plain --key-file /dev/random "${i}"p1 "${i##*/}"p1
mkswap /dev/mapper/"${i##*/}"p1
swapon /dev/mapper/"${i##*/}"p1
done
log Unmounting filesystems
# ---
umount -Rl "${MNT}"
zpool export -a
log The installation is done, enjoy
+34 -58
View File
@@ -11,6 +11,11 @@ in {
type = types.bool;
default = true;
};
luks.enable = mkOption {
description = "Use luks encryption";
type = types.bool;
default = false;
};
devNodes = mkOption {
description = "Specify where to discover ZFS pools";
type = types.str;
@@ -24,15 +29,7 @@ in {
description = "Specify boot devices";
type = types.nonEmptyListOf types.str;
};
availableKernelModules = mkOption {
type = types.nonEmptyListOf types.str;
default = [ "uas" "nvme" "ahci" ];
};
kernelParams = mkOption {
type = types.listOf types.str;
default = [ ];
};
immutable = mkOption {
immutable.enable = mkOption {
description = "Enable root on ZFS immutable root support";
type = types.bool;
default = false;
@@ -44,56 +41,61 @@ in {
};
partitionScheme = mkOption {
default = {
swap = "p1";
rootPool = "p2";
bootPool = "p3";
efiBoot = "p4";
biosBoot = "p5";
efiBoot = "p1";
swap = "p4";
bootPool = "p2";
rootPool = "p3";
};
description = "Describe on disk partitions";
type = types.attrsOf types.str;
};
sshUnlock = {
enable = mkOption {
type = types.bool;
default = false;
};
authorizedKeys = mkOption {
type = types.listOf types.str;
default = [ ];
};
};
};
config = mkIf (cfg.enable) (mkMerge [
{
zfs-root.fileSystems.datasets = {
# rpool/path/to/dataset = "/path/to/mountpoint"
"rpool/nixos/home" = mkDefault "/home";
"rpool/nixos/var/lib" = mkDefault "/var/lib";
"rpool/nixos/var/log" = mkDefault "/var/log";
"bpool/nixos/root" = "/boot";
};
}
(mkIf (!cfg.immutable) {
(mkIf cfg.luks.enable {
boot.initrd.luks.devices = mkMerge (map (diskName: {
"luks-rpool-${diskName}${cfg.partitionScheme.rootPool}" = {
device = (cfg.devNodes + diskName + cfg.partitionScheme.rootPool);
allowDiscards = true;
bypassWorkqueues = true;
};
}) cfg.bootDevices);
})
(mkIf (!cfg.immutable.enable) {
zfs-root.fileSystems.datasets = { "rpool/nixos/root" = "/"; };
})
(mkIf cfg.immutable {
(mkIf cfg.immutable.enable {
zfs-root.fileSystems = {
datasets = {
# rpool/path/to/dataset = "/path/to/mountpoint"
"rpool/nixos/empty" = "/";
"rpool/nixos/root" = "/oldroot";
};
bindmounts = {
# /bindmount/source = /bindmount/target
"/oldroot/nix" = "/nix";
"/oldroot/etc/nixos" = "/etc/nixos";
};
};
boot.initrd.postDeviceCommands = ''
if ! grep -q zfs_no_rollback /proc/cmdline; then
zpool import -N rpool
zfs rollback -r rpool/nixos/empty@start
zpool export -a
fi
'';
boot.initrd.systemd.services.immutable-zfs-root = {
description = "Rollback root filesystem to an empty snapshot";
unitConfig.DefaultDependencies = false;
wantedBy = [ "zfs.target" ];
after = [ "zfs-import-rpool.service" ];
before = [ "sysroot.mount" ];
path = [ pkgs.zfs ];
serviceConfig.Type = "oneshot";
script = "zfs rollback -r rpool/nixos/empty@start";
};
})
{
zfs-root.fileSystems = {
@@ -104,10 +106,6 @@ in {
(map (diskName: diskName + cfg.partitionScheme.swap) cfg.bootDevices);
};
boot = {
kernelPackages =
mkDefault config.boot.zfs.package.latestCompatibleLinuxPackages;
initrd.availableKernelModules = cfg.availableKernelModules;
kernelParams = cfg.kernelParams;
supportedFilesystems = [ "zfs" ];
zfs = {
devNodes = cfg.devNodes;
@@ -136,27 +134,5 @@ in {
};
};
}
(mkIf cfg.sshUnlock.enable {
boot.initrd = {
network = {
enable = true;
ssh = {
enable = true;
hostKeys = [
"/var/lib/ssh_unlock_zfs_ed25519_key"
"/var/lib/ssh_unlock_zfs_rsa_key"
];
authorizedKeys = cfg.sshUnlock.authorizedKeys;
};
postCommands = ''
tee -a /root/.profile >/dev/null <<EOF
if zfs load-key rpool/nixos; then
pkill zfs
fi
exit
EOF'';
};
};
})
]);
}
+1 -3
View File
@@ -1,3 +1 @@
{ config, lib, pkgs, ... }: {
imports = [ ./boot ./fileSystems ./networking ./my-config ];
}
{ config, lib, pkgs, ... }: { imports = [ ./boot ./fileSystems ]; }
+2 -2
View File
@@ -41,7 +41,7 @@ in {
};
}) cfg.bindmounts ++ map (esp: {
"/boot/efis/${esp}" = {
device = "${config.zfs-root.boot.devNodes}/${esp}";
device = "${config.zfs-root.boot.devNodes}${esp}";
fsType = "vfat";
options = [
"x-systemd.idle-timeout=1min"
@@ -54,7 +54,7 @@ in {
};
}) cfg.efiSystemPartitions);
config.swapDevices = mkDefault (map (swap: {
device = "${config.zfs-root.boot.devNodes}/${swap}";
device = "${config.zfs-root.boot.devNodes}${swap}";
discardPolicy = mkDefault "both";
randomEncryption = {
enable = true;
-41
View File
@@ -1,41 +0,0 @@
{ config, lib, pkgs, ... }:
let inherit (lib) types mkIf mkDefault mkOption;
in {
options.my-config = {
template.desktop.gnome.enable = mkOption {
description = "Enable my customized GNOME desktop";
type = types.bool;
default = false;
};
};
# if my-config.template.desktop.gnome.enable is set to true
# set the following options
config = mkIf config.my-config.template.desktop.gnome.enable {
services.xserver = {
enable = true;
desktopManager.gnome.enable = true;
displayManager.gdm.enable = true;
};
# GNOME must be used with a non-root user,
# add a non-root user
users.users.alice = {
# Generate hashed password with "mkpasswd -m sha-512" command,
# "!" disables login.
# "mkpasswd" without "-m sha-512" will not work
initialHashedPassword = "!";
description = "Full Name";
# Users in "wheel" group are allowed to use "doas" command
# to obtain root permissions.
extraGroups = [ "wheel" ];
packages = builtins.attrValues {
inherit (pkgs)
mg # emacs-like editor
jq # other programs
;
};
isNormalUser = true;
};
};
}
+1 -1
View File
@@ -7,7 +7,7 @@ in {
hostName = mkOption {
description = "The name of the machine. Used by nix flake.";
type = types.str;
default = "exampleHost";
default = "nixos";
};
timeZone = mkOption {
type = types.str;
+1
View File
@@ -0,0 +1 @@
print STDOUT $initrdAvailableKernelModules
-38
View File
@@ -1,38 +0,0 @@
{ lib
, qtbase
, qtsvg
, qtgraphicaleffects
, qtquickcontrols2
, wrapQtAppsHook
, stdenvNoCC
, fetchFromGitHub
}:
stdenvNoCC.mkDerivation
rec {
pname = "sddm-apple";
version = "1..0";
dontBuild = true;
src = fetchFromGitHub {
owner = "vfosterm";
repo = "nixos-sddm-theme-noBlur";
rev = "master";
sha256 = "sha256-Hxifk68xVfnL9EWBicHctzJqyowkCBhAZgSLd7ZZXvg=";
};
nativeBuildInputs = [
wrapQtAppsHook
];
propagatedUserEnvPkgs = [
qtbase
qtsvg
qtgraphicaleffects
qtquickcontrols2
];
installPhase = ''
mkdir -p $out/share/sddm/themes
cp -aR $src $out/share/sddm/themes/sddm-apple
'';
}
-38
View File
@@ -1,38 +0,0 @@
{ lib
, qtbase
, qtsvg
, qtgraphicaleffects
, qtquickcontrols2
, wrapQtAppsHook
, stdenvNoCC
, fetchFromGitHub
}:
stdenvNoCC.mkDerivation
rec {
pname = "sddm-peace-color";
version = "1..0";
dontBuild = true;
src = fetchFromGitHub {
owner = "marcpartensky";
repo = "sddm-peace-color";
rev = "master";
sha256 = "sha256-JRCa8JYkQqkBKQ8YYNNjPrUPY3WwiEkq0W3pBmlhbEs=";
};
nativeBuildInputs = [
wrapQtAppsHook
];
propagatedUserEnvPkgs = [
qtbase
qtsvg
qtgraphicaleffects
qtquickcontrols2
];
installPhase = ''
mkdir -p $out/share/sddm/themes
cp -aR $src $out/share/sddm/themes/sddm-peace-color
'';
}
-19
View File
@@ -1,19 +0,0 @@
{ stdenv, fetchFromGitHub }:
{
sddm-theme-dialog = stdenv.mkDerivation rec {
pname = "sddm-theme-dialog";
version = "53f81e3";
dontBuild = true;
installPhase = ''
mkdir -p $out/share/sddm/themes
cp -aR $src $out/share/sddm/themes/sddm-theme-dialog
'';
src = fetchFromGitHub {
owner = "joshuakraemer";
repo = "sddm-theme-dialog";
rev = "53f81e322f715d3f8e3f41c38eb3774b1be4c19b";
sha256 = "qoLSRnQOvH3rAH+G1eRrcf9ZB6WlSRIZjYZBOTkew/0=";
};
};
}
-38
View File
@@ -1,38 +0,0 @@
{ lib
, qtbase
, qtsvg
, qtgraphicaleffects
, qtquickcontrols2
, wrapQtAppsHook
, stdenvNoCC
, fetchFromGitHub
}:
stdenvNoCC.mkDerivation
rec {
pname = "tokyo-night-sddm";
version = "1..0";
dontBuild = true;
src = fetchFromGitHub {
owner = "rototrash";
repo = "tokyo-night-sddm";
rev = "320c8e74ade1e94f640708eee0b9a75a395697c6";
sha256 = "sha256-JRVVzyefqR2L3UrEK2iWyhUKfPMUNUnfRZmwdz05wL0=";
};
nativeBuildInputs = [
wrapQtAppsHook
];
propagatedUserEnvPkgs = [
qtbase
qtsvg
qtgraphicaleffects
qtquickcontrols2
];
installPhase = ''
mkdir -p $out/share/sddm/themes
cp -aR $src $out/share/sddm/themes/tokyo-night-sddm
'';
}