aboutsummaryrefslogtreecommitdiffstats
path: root/modules/by-name/di
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/by-name/di/direnv/module.nix53
-rwxr-xr-xmodules/by-name/di/direnv/pre-cache.sh78
-rw-r--r--modules/by-name/di/disks/fstrim.nix9
-rw-r--r--modules/by-name/di/disks/hibernate.nix16
-rw-r--r--modules/by-name/di/disks/module.nix115
5 files changed, 223 insertions, 48 deletions
diff --git a/modules/by-name/di/direnv/module.nix b/modules/by-name/di/direnv/module.nix
index 1ddf3d5d..31c70dad 100644
--- a/modules/by-name/di/direnv/module.nix
+++ b/modules/by-name/di/direnv/module.nix
@@ -1,21 +1,60 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
config,
lib,
+ pkgs,
+ sources,
...
}: let
cfg = config.soispha.programs.direnv;
+
+ devshells = sources.loadFlake "devshells";
+
+ pre-cache = pkgs.runCommand "pre-cache.sh" {} ''
+ cat "${./pre-cache.sh}" > $out
+
+ substituteInPlace $out \
+ --replace-fail "%DEVSHELLS_REPO%" "${devshells}" \
+ --replace-fail "%DEVSHELLS_REPO_REF%" "${devshells.sourceInfo.rev}"
+
+ '';
in {
options.soispha.programs.direnv = {
enable = lib.mkEnableOption "direnv";
};
- config.home-manager.users.soispha.programs.direnv = lib.mkIf cfg.enable {
- enable = true;
- nix-direnv.enable = true;
- config = {
- warn_timeout = 0;
- # strict_env = true;
- # disable_stdin = true;
+ config.home-manager.users.soispha = lib.mkIf cfg.enable {
+ programs.direnv = {
+ enable = true;
+
+ package = pkgs.direnv-patched;
+
+ nix-direnv = {
+ enable = true;
+ package = pkgs.nix-direnv.override {nix = config.nix.package;};
+ };
+
+ config = {
+ warn_timeout = 0;
+
+ # NOTE: Something variable is undeclared in the my default loaded stuff :/. <2026-08-18>
+ # strict_env = true;
+
+ # disable_stdin = true;
+ };
+ };
+ xdg.configFile = {
+ "direnv/lib/hm-pre-cache.sh" = {
+ source = pre-cache;
+ };
};
};
}
diff --git a/modules/by-name/di/direnv/pre-cache.sh b/modules/by-name/di/direnv/pre-cache.sh
new file mode 100755
index 00000000..8c43a556
--- /dev/null
+++ b/modules/by-name/di/direnv/pre-cache.sh
@@ -0,0 +1,78 @@
+#! /usr/bin/env sh
+
+_pre_cache_log() {
+ printf "pre-cache: %s\n" "$1"
+}
+_pre_cache_preflight() {
+ set -eu
+ _nix_direnv_preflight
+
+ REPO="%DEVSHELLS_REPO%"
+ system="x86_64-linux"
+ cache_dir="$XDG_CACHE_HOME/pre_cache"
+ [ -d "$cache_dir" ] || mkdir --parents "$cache_dir"
+
+ repo_ref="%DEVSHELLS_REPO_REF%"
+ final_cache="$cache_dir/$repo_ref"
+
+ if ! [ -d "$final_cache" ]; then
+ _pre_cache_log "Cache dir invalidated"
+
+ # There is not yet a final cache directory, so the ref must have changed.
+ # Therefore we delete the whole cache directory, so we invalidate old cached shells.
+ set -u
+ rm --recursive "$cache_dir"
+
+ mkdir --parents "$final_cache"
+ fi
+}
+
+_pre_cache_load_shell() {
+ lang="$1"
+ lang_cache="$final_cache/$lang"
+
+ if ! [ -f "$lang_cache" ]; then
+ tmp_profile="$final_cache/__tmp_profile"
+ profile="$final_cache/__profile"
+
+ # It does not already exists, we need to evaluate it.
+ _nix print-dev-env --profile "$tmp_profile" "$REPO#$lang" >"$lang_cache"
+
+ _nix_add_gcroot "$tmp_profile" "$profile"
+ # rm "$tmp_profile" "$tmp_profile"* || true
+ fi
+
+ _pre_cache_log "Loaded dev-shell for $lang."
+ _nix_import_env "$lang_cache"
+}
+
+_pre_cache_build_shells() {
+ installables=""
+
+ for lang in "$@"; do
+ new_part="$REPO#devShells.$system.$lang"
+
+ if [ -z "$installables" ]; then
+ installables="$new_part"
+ else
+ installables="$installables $new_part"
+ fi
+ done
+
+ # We want shell-spliting
+ # shellcheck disable=SC2086
+ _nix build --no-link $installables
+
+}
+
+pre_cache_load() {
+ _pre_cache_preflight
+
+ _pre_cache_build_shells "$@"
+
+ for lan in "$@"; do
+ _pre_cache_load_shell "$lan"
+ done
+}
+
+# vim: ft=sh
diff --git a/modules/by-name/di/disks/fstrim.nix b/modules/by-name/di/disks/fstrim.nix
index 6daeb65e..0fbb6c83 100644
--- a/modules/by-name/di/disks/fstrim.nix
+++ b/modules/by-name/di/disks/fstrim.nix
@@ -1,3 +1,12 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
pkgs,
lib,
diff --git a/modules/by-name/di/disks/hibernate.nix b/modules/by-name/di/disks/hibernate.nix
index a50e5b57..d3f8fe8b 100644
--- a/modules/by-name/di/disks/hibernate.nix
+++ b/modules/by-name/di/disks/hibernate.nix
@@ -1,3 +1,12 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{pkgs}: {
services = {
hibernate-preparation = {
@@ -39,7 +48,8 @@
systemd-hibernate.serviceConfig.Environment = "SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1";
systemd-logind.serviceConfig.Environment = "SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1";
};
- sleep.extraConfig = ''
- HibernateDelaySec=5m
- '';
+
+ sleep.settings.Sleep = {
+ HibernateDelaySec = "10m";
+ };
}
diff --git a/modules/by-name/di/disks/module.nix b/modules/by-name/di/disks/module.nix
index c0e5bcfd..ed5c939a 100644
--- a/modules/by-name/di/disks/module.nix
+++ b/modules/by-name/di/disks/module.nix
@@ -1,10 +1,19 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
config,
lib,
pkgs,
+ modules,
...
}: let
- # FIXME: The iso redeploy requires a bigger efi partition <2024-05-12>
cfg = config.soispha.disks;
defaultMountOptions = [
"compress-force=zstd:15" # This saves disk space, at a performance cost
@@ -24,22 +33,27 @@ in {
ssd = lib.mkEnableOption "ssd specific improvements, like trim";
swap = {
- uuid = lib.mkOption {
+ ram_size = lib.mkOption {
type = lib.types.str;
- example = lib.literalExpression "d1d20ae7-3d8a-44da-86da-677dbbb10c89";
- description = "The uuid of the swapfile";
- };
- resumeOffset = lib.mkOption {
- type = lib.types.str;
- example = lib.literalExpression "134324224";
- description = "The resume offset of the swapfile";
+ example = lib.literalExpression "16G";
+ description = "The size of the ram (translates to the swapfile size)";
};
};
};
+ imports = [
+ modules.disko.nixosModules.default
+ ];
+
config = lib.mkIf cfg.enable {
systemd = lib.recursiveUpdate (import ./hibernate.nix {inherit pkgs;}) (import ./fstrim.nix {inherit pkgs lib cfg;});
+ services.btrfs.autoScrub = {
+ enable = true;
+ fileSystems = ["/srv" "/nix"];
+ interval = "monthly";
+ };
+
disko.devices = {
disk = {
main = {
@@ -47,21 +61,44 @@ in {
content = {
type = "gpt";
partitions = {
+ ESP = {
+ # 2GiB plus 512MiB for tails ISO and normal boot stuff
+ size = "2600M";
+
+ type = "EF00";
+ content = {
+ type = "filesystem";
+ format = "vfat";
+ mountpoint = "/boot";
+ mountOptions = ["umask=0077"];
+ };
+ };
+
+ nix = {
+ size = "30G";
+ content = {
+ type = "luks";
+ name = "nixos-store";
+ extraOpenArgs = ["--allow-discards"];
+ content = {
+ type = "btrfs";
+ extraArgs = ["-f" "--label nixos-store"]; # Override existing partitions
+ mountpoint = "/nix";
+ mountOptions = defaultMountOptions;
+ };
+ };
+ };
+
root = {
size = "100%";
- name = "root";
content = {
type = "luks";
- name = "nixos";
+ name = "nixos-root";
extraOpenArgs = ["--allow-discards"];
content = {
type = "btrfs";
- extraArgs = ["-f" "--label nixos"]; # Override existing partitions
+ extraArgs = ["-f" "--label nixos-root"]; # Override existing partitions
subvolumes = {
- "nix" = {
- mountpoint = "/nix";
- mountOptions = defaultMountOptions;
- };
"persistent-storage" = {
mountpoint = "/srv";
mountOptions = defaultMountOptions;
@@ -72,22 +109,21 @@ in {
};
"swap" = {
mountpoint = "/swap";
- mountOptions = defaultMountOptions;
+ mountOptions = [
+ "noatime" # should have some performance upsides, and I don't use it anyways
+ "lazytime" # make time changes in memory
+ ];
+ swap = {
+ swapfile = {
+ priority = -1; # lower than zramSwap, just in case
+ size = cfg.swap.ram_size;
+ };
+ };
};
};
};
};
};
- boot = {
- type = "EF00";
- size = "512M";
- name = "boot";
- content = {
- type = "filesystem";
- format = "vfat";
- mountpoint = "/boot";
- };
- };
};
};
};
@@ -95,15 +131,27 @@ in {
nodev = {
"/" = {
fsType = "tmpfs";
- mountOptions = ["defaults" "size=4G" "mode=755"];
+ mountOptions = ["defaults" "size=25%" "mode=0755"];
};
"/tmp" = {
fsType = "tmpfs";
- mountOptions = ["defaults" "size=16G" "mode=755"];
+ mountOptions = ["defaults" "size=50%" "mode=0755"];
+ };
+ "/nix/var/nix/b" = {
+ fsType = "tmpfs";
+ mountOptions = [
+ "defaults"
+ "noswap" # Otherwise, we might run into io-based slowdowns
+ "size=80%"
+ "mode=0755"
+ ];
};
};
};
fileSystems = {
+ "/nix" = {
+ neededForBoot = true;
+ };
"/srv" = {
neededForBoot = true;
};
@@ -111,23 +159,14 @@ in {
neededForBoot = true;
};
};
- swapDevices = [
- #{
- # device = "/swap/swapfile";
- # priority = 1; # lower than zramSwap, just in case
- # # size = 2048; # TODO: can nixos create a btrfs swapfile correctly?
- #}
- ];
zramSwap = {
enable = true;
priority = 10; # needs to be higher than hardware-swap
};
boot = {
kernelParams = [
- "resume_offset=${cfg.swap.resumeOffset}"
"zswap.enabled=0" # zswap and zram are not really compatible
];
- resumeDevice = "/dev/disk/by-uuid/${cfg.swap.uuid}";
};
};
}