diff --git a/machines/gustave/default.nix b/machines/gustave/default.nix index c85ed4c..71b4dcf 100644 --- a/machines/gustave/default.nix +++ b/machines/gustave/default.nix @@ -1,97 +1,46 @@ -{ config, pkgs, ... }: +{ lib, ... }: { - imports = - [ - # Include the results of the hardware scan. - ./hardware.nix - ./home-julien.nix - ]; + imports = [ + ../../users/default.nix + ../../users/julien.nix + ./hardware.nix + ./home-julien.nix + ]; - # Bootloader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - + deployment.targetHost = lib.mkForce "192.168.0.126"; disko = import ./disko.nix; - # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. + systemd.network.enable = true; + systemd.services."systemd-networkd".environment.SYSTEMD_LOG_LEVEL = "debug"; - # Configure network proxy if necessary - # networking.proxy.default = "http://user:password@proxy:port/"; - # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; - - # Enable networking - networking.networkmanager.enable = true; + networking.useNetworkd = true; + systemd.network.networks."10-wan" = { + matchConfig.Name = "ens18"; + networkConfig = { + # start a DHCP Client for IPv4 Addressing/Routing + DHCP = "ipv4"; + # accept Router Advertisements for Stateless IPv6 Autoconfiguraton (SLAAC) + IPv6AcceptRA = true; + }; + # make routing on this interface a dependency for network-online.target + linkConfig.RequiredForOnline = "routable"; + }; # Set your time zone. time.timeZone = "Europe/Paris"; - # Select internationalisation properties. - i18n.defaultLocale = "en_US.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"; + environment.persistence."/persistent" = { + hideMounts = true; + files = [ + "/etc/ssh/ssh_host_ed25519_key" + "/etc/ssh/ssh_host_ed25519_key.pub" + ]; }; - # Configure keymap in X11 - services.xserver = { - layout = "fr"; - xkbVariant = ""; - }; - - # Configure console keymap - console.keyMap = "fr"; - - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.julien = { - isNormalUser = true; - description = "Julien"; - extraGroups = [ "networkmanager" "wheel" ]; - packages = with pkgs; [ ]; - }; - - # List packages installed in system profile. To search, run: - # $ nix search wget - environment.systemPackages = with pkgs; [ - # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. - # wget - ]; - - # Some programs need SUID wrappers, can be configured further or are - # started in user sessions. - # programs.mtr.enable = true; - # programs.gnupg.agent = { - # enable = true; - # enableSSHSupport = true; - # }; - - # List services that you want to enable: - - # Enable the OpenSSH daemon. - services.openssh.enable = true; - - # Open ports in the firewall. - # networking.firewall.allowedTCPPorts = [ ... ]; - # networking.firewall.allowedUDPPorts = [ ... ]; - # Or disable the firewall altogether. - # networking.firewall.enable = false; - - # This value determines the NixOS release from which the default - # settings for stateful data, like file locations and database versions - # on your system were taken. It‘s perfectly fine and recommended to leave - # this value at the release version of the first install of this system. - # Before changing this value read the documentation for this option - # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). - system.stateVersion = "23.11"; # Did you read the comment? - + system.stateVersion = "23.11"; } diff --git a/machines/gustave/disko.nix b/machines/gustave/disko.nix index 2caf77e..8be9924 100644 --- a/machines/gustave/disko.nix +++ b/machines/gustave/disko.nix @@ -3,7 +3,7 @@ disk = { sda = { type = "disk"; - device = "/dev/disk/by-diskseq/3"; + device = "/dev/sda"; content = { type = "gpt"; partitions = { @@ -28,7 +28,7 @@ # unless their parent is mounted subvolumes = { # Subvolume name is different from mountpoint - "/rootfs" = { + "/root" = { mountpoint = "/"; }; # Subvolume name is the same as the mountpoint @@ -36,13 +36,13 @@ mountpoint = "/persistent"; }; "/nix" = { - mountOptions = [ "compress=zstd" "noatime" ]; + mountOptions = [ + "compress=zstd" + "noatime" + ]; mountpoint = "/nix"; }; }; - - mountpoint = "/partition-root"; - }; }; }; diff --git a/machines/gustave/hardware.nix b/machines/gustave/hardware.nix index 596671d..a383bfe 100644 --- a/machines/gustave/hardware.nix +++ b/machines/gustave/hardware.nix @@ -1,16 +1,46 @@ -{ config, lib, pkgs, modulesPath, ... }: +{ lib, modulesPath, ... }: { - imports = - [ - (modulesPath + "/profiles/qemu-guest.nix") - ]; + imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; - boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "virtio_pci" "virtio_scsi" "sd_mod" "sr_mod" ]; + boot.initrd.availableKernelModules = [ + "ata_piix" + "uhci_hcd" + "virtio_pci" + "virtio_scsi" + "sd_mod" + "sr_mod" + ]; boot.initrd.kernelModules = [ ]; boot.kernelModules = [ ]; boot.extraModulePackages = [ ]; + fileSystems."/persistent".neededForBoot = lib.mkForce true; + + boot.initrd.postDeviceCommands = lib.mkAfter '' + mkdir /btrfs_tmp + mount /dev/disk/by-partlabel/disk-sda-root /btrfs_tmp + if [[ -e /btrfs_tmp/root ]]; then + mkdir -p /btrfs_tmp/old_roots + timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") + mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" + fi + + delete_subvolume_recursively() { + IFS=$'\n' + for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do + delete_subvolume_recursively "/btrfs_tmp/$i" + done + btrfs subvolume delete "$1" + } + + for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do + delete_subvolume_recursively "$i" + done + + btrfs subvolume create /btrfs_tmp/root + umount /btrfs_tmp + ''; networking.useDHCP = lib.mkDefault true;