From 4cef631a8ca72b2f3f915a0af0007e385a490b06 Mon Sep 17 00:00:00 2001 From: boyreau Date: Sat, 1 Aug 2026 20:29:56 +0200 Subject: [PATCH] moving toward a multi-machine configuration ! --- README.md | 35 ++++++ configuration.nix | 111 +----------------- machines/desktop.nix | 38 ++++++ machines/memere/default.nix | 31 +++++ machines/memere/users.nix | 24 ++++ .../niczos/bootloader.nix | 0 machines/niczos/default.nix | 80 +++++++++++++ .../niczos/hardware-configuration.nix | 0 hardware.nix => machines/niczos/hardware.nix | 14 ++- kernel.nix => machines/niczos/kernel.nix | 2 +- machines/niczos/security.nix | 7 ++ users.nix => machines/niczos/users.nix | 2 +- nix.nix | 2 +- npins/sources.json | 28 +---- pkgs/default.nix | 1 + .../jailed-packages.nix | 2 +- pkgs/rayfish.nix | 36 ------ security.nix | 18 ++- 18 files changed, 250 insertions(+), 181 deletions(-) create mode 100644 README.md create mode 100644 machines/desktop.nix create mode 100644 machines/memere/default.nix create mode 100644 machines/memere/users.nix rename bootloader.nix => machines/niczos/bootloader.nix (100%) create mode 100644 machines/niczos/default.nix rename hardware-configuration.nix => machines/niczos/hardware-configuration.nix (100%) rename hardware.nix => machines/niczos/hardware.nix (87%) rename kernel.nix => machines/niczos/kernel.nix (81%) create mode 100644 machines/niczos/security.nix rename users.nix => machines/niczos/users.nix (95%) create mode 100644 pkgs/default.nix rename jailed-packages.nix => pkgs/jailed-packages.nix (88%) delete mode 100644 pkgs/rayfish.nix diff --git a/README.md b/README.md new file mode 100644 index 0000000..b99c784 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +Top-level files are global configurations + +- machines/ + - server.nix # Abstract default + - desktop.nix + - name/ # A concrete machine + - default.nix # Machine configuration + - home/ # Home-manager configuration + - pkgs/ # custom derivations + - jailed-packages.nix # Security-wrapped packages + +. +├── security.nix # Global security settings +├── configuration.nix +├── machines/ # Machines configurations +│   ├── desktop.nix # Global desktop settings +│ │ +│   ├── memere/ # Machine-specific configuration +│   │ ├── default.nix +│   │ └── hardware-configuration.nix +│   └── niczos/ # Machine-specific configuration +│   ├── default.nix +│   ├── hardware-configuration.nix +│   ├── kernel.nix +│   └── security.nix # Specializes the global security.nix +│ +├── nix.nix # Package manager config +├── npins # Pins to ensure coherent packages versions +│   ├── default.nix +│   └── sources.json +├── pkgs # Custom derivations and overlay +│   ├── default.nix +│   └── jailed-packages.nix +├── README.md +└── shell.nix diff --git a/configuration.nix b/configuration.nix index e047993..8531818 100644 --- a/configuration.nix +++ b/configuration.nix @@ -1,112 +1,3 @@ { - config, - ... -}: - -let - pkgs = import ./jailed-packages.nix; - more_pkgs = { - rayfish = pkgs.callPackage ./pkgs/rayfish.nix { }; - }; -in -{ - imports = [ - ./security.nix - ./hardware-configuration.nix - ./hardware.nix - ./bootloader.nix - ./kernel.nix - ./nix.nix - ./users.nix - ]; - - programs.fuse.userAllowOther = true; - networking.hostName = "niczos"; - networking.networkmanager.enable = true; - - time.timeZone = "Europe/Paris"; - - i18n.defaultLocale = "en_US.UTF-8"; - - virtualisation = { - waydroid = { - enable = true; - package = pkgs.waydroid-nftables.unjailed; - }; - docker = { - enable = true; - storageDriver = "btrfs"; - }; - }; - - programs.steam.enable = true; - - services.pipewire = { - enable = true; - audio.enable = true; - pulse.enable = true; - alsa = { - enable = true; - }; - wireplumber.enable = true; - }; - security = { - rtkit.enable = true; - wrappers = { - waydroid = { - source = "${pkgs.waydroid}/bin/waydroid"; - capabilities = "cap_net_admin=ep"; - enable = true; - owner = "root"; - group = "root"; - program = "waydroid"; - }; - }; - }; - - systemd = { - defaultUnit = "graphical.target"; - - services."getty@tty1" = { - overrideStrategy = "asDropin"; - serviceConfig.ExecStart = [ - "" - "@${pkgs.util-linux}/sbin/agetty agetty --login-program ${config.services.getty.loginProgram} --autologin zo --noclear --keep-baud %I 115200,38400,9600 $TERM" - ]; - }; - - packages = [ - more_pkgs.rayfish - ]; - - services."rayfish" = { - wantedBy = [ "multi-user.target" ]; - enable = true; - }; - }; - - environment.systemPackages = with pkgs; [ - curl - wget - cryptsetup - cachix - more_pkgs.rayfish - ]; - - fonts.packages = with pkgs; [ - noto-fonts - noto-fonts-cjk-sans - noto-fonts-color-emoji - liberation_ttf - fira-code - fira-code-symbols - mplus-outline-fonts.githubRelease - dina-font - proggyfonts - font-awesome - ]; - - system.copySystemConfiguration = true; - - system.stateVersion = "26.05"; # Not here to update, here for data models backward compatibility. Don't change. + _ = abort "please set a configuration using -I /etc/nixos/machines/some-machine/default.nix"; } diff --git a/machines/desktop.nix b/machines/desktop.nix new file mode 100644 index 0000000..8934750 --- /dev/null +++ b/machines/desktop.nix @@ -0,0 +1,38 @@ +{ + config, + pkgs ? import (config.root + /pkgs), + ... +}: +{ + programs.dconf.enable = true; + + systemd = { + defaultUnit = "graphical.target"; + }; + + services.pipewire = { + enable = true; + audio.enable = true; + pulse.enable = true; + alsa = { + enable = true; + }; + wireplumber.enable = true; + }; + + fonts.packages = with pkgs; [ + noto-fonts + noto-fonts-cjk-sans + noto-fonts-color-emoji + liberation_ttf + fira-code + fira-code-symbols + mplus-outline-fonts.githubRelease + dina-font + proggyfonts + font-awesome + ]; + + time.timeZone = "Europe/Paris"; + i18n.defaultLocale = pkgs.lib.mkDefault "fr_FR.UTF-8"; +} diff --git a/machines/memere/default.nix b/machines/memere/default.nix new file mode 100644 index 0000000..6c1ba7f --- /dev/null +++ b/machines/memere/default.nix @@ -0,0 +1,31 @@ +{ + config, + pkgs ? import , # Do not use jail.nix packages + ... +}: + +{ + imports = [ + /etc/nixos/security.nix + /etc/nixos/nix.nix + ./users.nix + ]; + + services.desktopManager.gnome.enable = true; + services.gnome = { + core-apps.enable = true; + core-shell.enable = true; + gnome-software.enable = true; + }; + + nix.nixPath = [ + "nixos-config=/etc/nixos/machines/memere/default.nix" + "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" + "/nix/var/nix/profiles/per-user/root/channels" + ]; + + networking.hostName = "pepere"; + networking.networkmanager.enable = true; + + i18n.defaultLocale = "fr_FR.UTF-8"; +} diff --git a/machines/memere/users.nix b/machines/memere/users.nix new file mode 100644 index 0000000..18f869e --- /dev/null +++ b/machines/memere/users.nix @@ -0,0 +1,24 @@ +{ config, pkgs, ... }: +let + source = import (config.root + /npins); + home-manager = source.home-manager; +in +{ + imports = [ + (import "${home-manager}/nixos") + ]; + + home-manager.useGlobalPkgs = true; + + users.users.memere.isNormalUser = true; + home-manager.users.memere = + { pkgs, ... }: + { + home.packages = [ ]; + programs.bash.enable = true; + + # The state version is required and should stay at the version you + # originally installed. + home.stateVersion = "26.05"; + }; +} diff --git a/bootloader.nix b/machines/niczos/bootloader.nix similarity index 100% rename from bootloader.nix rename to machines/niczos/bootloader.nix diff --git a/machines/niczos/default.nix b/machines/niczos/default.nix new file mode 100644 index 0000000..b25aac8 --- /dev/null +++ b/machines/niczos/default.nix @@ -0,0 +1,80 @@ +{ + config, + ... +}: +let + pkgs = import /etc/nixos/pkgs/jailed-packages.nix; +in +{ + imports = [ + /etc/nixos/security.nix + /etc/nixos/nix.nix + /etc/nixos/machines/desktop.nix + ./bootloader.nix + ./hardware-configuration.nix + ./hardware.nix + ./kernel.nix + ./security.nix + ./users.nix + ]; + + nix.nixPath = [ + "nixos-config=/etc/nixos/machines/niczos/default.nix" + "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" + "/nix/var/nix/profiles/per-user/root/channels" + ]; + + networking.hostName = "niczos"; + networking.networkmanager.enable = true; + + systemd = { + services."getty@tty1" = { + overrideStrategy = "asDropin"; + serviceConfig.ExecStart = [ + "" + "@${pkgs.util-linux}/sbin/agetty agetty --login-program ${config.services.getty.loginProgram} --autologin zo --noclear --keep-baud %I 115200,38400,9600 $TERM" + ]; + }; + }; + + programs = { + steam.enable = true; + fuse.userAllowOther = true; + }; + + virtualisation.docker = { + enable = true; + storageDriver = "btrfs"; + }; + + # Waydroid configuration + virtualisation.waydroid = { + enable = true; + package = pkgs.waydroid-nftables.unjailed; + }; + security = { + rtkit.enable = true; + wrappers = { + waydroid = { + source = "${pkgs.waydroid}/bin/waydroid"; + capabilities = "cap_net_admin=ep"; + enable = true; + owner = "root"; + group = "root"; + program = "waydroid"; + }; + }; + }; + + environment.systemPackages = [ + pkgs.curl + pkgs.wget + pkgs.cryptsetup + pkgs.cachix + ]; + + i18n.defaultLocale = "en_US.UTF-8"; + + system.copySystemConfiguration = true; + system.stateVersion = "26.05"; +} diff --git a/hardware-configuration.nix b/machines/niczos/hardware-configuration.nix similarity index 100% rename from hardware-configuration.nix rename to machines/niczos/hardware-configuration.nix diff --git a/hardware.nix b/machines/niczos/hardware.nix similarity index 87% rename from hardware.nix rename to machines/niczos/hardware.nix index fbc98b1..baa6448 100644 --- a/hardware.nix +++ b/machines/niczos/hardware.nix @@ -14,11 +14,13 @@ pkgs.epsonscan2 ]; - boot.kernelParams = [ - "nvidia.NVreg_PreserveVideoMemoryAllocations=1" - "nvidia.NVreg_TemporaryFilePath=/var/tmp" - "usb-storage.quirks=152d:0578:u" - ]; + boot = { + kernelParams = [ + "nvidia.NVreg_PreserveVideoMemoryAllocations=1" + "nvidia.NVreg_TemporaryFilePath=/var/tmp" + "usb-storage.quirks=152d:0578:u" + ]; + }; hardware = { enableRedistributableFirmware = lib.mkDefault true; @@ -26,7 +28,7 @@ ########## Printers and scanners ########## sane.enable = true; - ######### nVidia Quadro RTX 3000m ######### + ######### Nvidia Quadro RTX 3000m ######### graphics.enable = true; nvidia = { open = false; # Not compatible with current GPU diff --git a/kernel.nix b/machines/niczos/kernel.nix similarity index 81% rename from kernel.nix rename to machines/niczos/kernel.nix index c0d782f..07a9d22 100644 --- a/kernel.nix +++ b/machines/niczos/kernel.nix @@ -1,5 +1,5 @@ let - sources = import ./npins/default.nix; + sources = import /etc/nixos/npins/default.nix; cachy-source = import sources.nix-cachyos-kernel; cachy-kernel = cachy-source.outputs.legacyPackages.x86_64-linux.linuxPackages-cachyos-bore-lto-x86_64-v3; diff --git a/machines/niczos/security.nix b/machines/niczos/security.nix new file mode 100644 index 0000000..3485572 --- /dev/null +++ b/machines/niczos/security.nix @@ -0,0 +1,7 @@ +{ + # Classic deny all + networking.firewall = { + allowedTCPPorts = [ 1716 ]; + allowedUDPPorts = [ 1716 ]; + }; +} diff --git a/users.nix b/machines/niczos/users.nix similarity index 95% rename from users.nix rename to machines/niczos/users.nix index 165e37d..37265f3 100644 --- a/users.nix +++ b/machines/niczos/users.nix @@ -1,6 +1,6 @@ { pkgs, ... }: let - source = import ./npins; + source = import /etc/nixos/npins; home-manager = source.home-manager; in { diff --git a/nix.nix b/nix.nix index 6bd7cde..1b09f31 100644 --- a/nix.nix +++ b/nix.nix @@ -1,6 +1,6 @@ { nix.gc = { - automatic = true; + automatic = false; dates = "weekly"; options = "--delete-older-than 30d"; }; diff --git a/npins/sources.json b/npins/sources.json index 20cd2a1..62c07a9 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -9,9 +9,9 @@ }, "branch": "release-26.05", "submodules": false, - "revision": "3cd22efe6471dc7365c822bd9ad73a21e55f38fb", - "url": "https://github.com/nix-community/home-manager/archive/3cd22efe6471dc7365c822bd9ad73a21e55f38fb.tar.gz", - "hash": "sha256-qajyHfZY29G2oEQk+uHxmsJcRoBUBXP9maTpFlwP/dI=" + "revision": "d4fd24667c8cbef124bb70a20380cab75ec8474d", + "url": "https://github.com/nix-community/home-manager/archive/d4fd24667c8cbef124bb70a20380cab75ec8474d.tar.gz", + "hash": "sha256-Rgs2xKnGLFWQscxUaXX07oyZeuMDOHEbqDOsgliLFGM=" }, "jail.nix": { "type": "Git", @@ -34,30 +34,14 @@ }, "branch": "release", "submodules": false, - "revision": "4673c8f6d48baf2ec3f14b6a9f8c4ecfb0810d6f", - "url": "https://github.com/xddxdd/nix-cachyos-kernel/archive/4673c8f6d48baf2ec3f14b6a9f8c4ecfb0810d6f.tar.gz", - "hash": "sha256-w5ALD125oHIa5MVhoBXo3qx2ktvRvJ+1p8UScV9f8OI=" + "revision": "4f3c8ca048091c5fbad5447c660133ac1a151ac7", + "url": "https://github.com/xddxdd/nix-cachyos-kernel/archive/4f3c8ca048091c5fbad5447c660133ac1a151ac7.tar.gz", + "hash": "sha256-QeJMNuRgY5E7pAYTjgMO8Te9Rg0AEI5CgS8EYQpZzHw=" }, "nixpkgs": { "type": "Tarball", "url": "https://releases.nixos.org/nixos/26.05/nixos-26.05.2462.e8210c649915/nixexprs.tar.xz", "hash": "sha256-2khLdWQw7Z9psJUEORs8dKPwivbhLbiBTas81jEZtJs=" - }, - "rayfish": { - "type": "GitRelease", - "repository": { - "type": "GitHub", - "owner": "rayfish", - "repo": "rayfish" - }, - "pre_releases": false, - "version_upper_bound": null, - "release_prefix": null, - "submodules": false, - "version": "v0.2.0", - "revision": "21239b1c2007e42eba1552ed2c2cf4bb0d1b7bc3", - "url": "https://api.github.com/repos/rayfish/rayfish/tarball/refs/tags/v0.2.0", - "hash": "sha256-Y9XQt6HhGWXI7Uwpw4TjqMavqEE/+pa0gEhQ0Gh/SqM=" } }, "version": 7 diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..d62705e --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1 @@ +(import ./jailed-packages.nix) diff --git a/jailed-packages.nix b/pkgs/jailed-packages.nix similarity index 88% rename from jailed-packages.nix rename to pkgs/jailed-packages.nix index 02ac73f..e794112 100644 --- a/jailed-packages.nix +++ b/pkgs/jailed-packages.nix @@ -1,5 +1,5 @@ let - sources = import ./npins/default.nix; + sources = import /etc/nixos/npins/default.nix; jail-nix = import /home/zo/dev/jail.nix { }; jailOverlay = final: prev: diff --git a/pkgs/rayfish.nix b/pkgs/rayfish.nix deleted file mode 100644 index 3193e13..0000000 --- a/pkgs/rayfish.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ - fetchFromGitHub, - rustPlatform, -}: -let - sources = import ../npins/default.nix; - rayfish-repo = sources.rayfish; -in -rustPlatform.buildRustPackage { - pname = "rayfish"; - version = "0.2.0"; - - src = fetchFromGitHub { - owner = rayfish-repo.repository.owner; - repo = rayfish-repo.repository.repo; - tag = rayfish-repo.version; - hash = rayfish-repo.hash; - }; - - cargoHash = "sha256-mh4lGbI3GUH32vf0FwVqyh737gCM7nEphQJr1rQed48="; - doCheck = false; - - installPhase = /* bash */ '' - runHook installPhase - - mkdir -p $out/bin/ - mkdir -p $out/lib/systemd/system/ - - # Copy binary and service to out - cp ./target/x86_64-unknown-linux-gnu/release/ray $out/bin/ - cp ./contrib/rayfish.service $out/lib/systemd/system/ - - # Patch binary path in service file to match derivation path - sed -i "s|/usr/local/bin/ray|$out/bin/ray|g" $out/lib/systemd/system/rayfish.service - ''; -} diff --git a/security.nix b/security.nix index 3b08f47..4e9ca0a 100644 --- a/security.nix +++ b/security.nix @@ -1,9 +1,21 @@ { + # Classic deny all networking.nftables.enable = true; networking.firewall = { enable = true; - # Lwk connect ports - allowedTCPPorts = [ 1716 ]; - allowedUDPPorts = [ 1716 ]; + allowedTCPPorts = [ ]; + allowedUDPPorts = [ ]; }; + + # No fork bomb + environment.etc."security/limits.conf".text = '' + * soft nproc 2000 + * hard nproc 4000 + ''; + + # Wheel group may edit the configuration. + systemd.tmpfiles.rules = [ + "Z! /etc/nixos 4070 root wheel" + "A! /etc/nixos - - - - d:u::rwx,d:g::-,d:g:wheel:rwx,d:mask:rwx" + ]; }