From 08b81a2118932db3a0cca86e24bfaa8766a07148 Mon Sep 17 00:00:00 2001 From: Friedrich Altheide Date: Thu, 20 Jun 2024 14:55:31 +0200 Subject: [PATCH] Allow building installers with custom configs - Move previous config snippets into snippet files, used as default snippets (getCustomOrDefaultSnippet) - If a custom snippet is found in customConfigSnippets, it is used instead --- .editorconfig | 4 + modules/nixos/defaultConfigs/modules/.gitkeep | 0 .../defaultConfigs/snippets/audio.snippet | 16 + .../defaultConfigs/snippets/autologin.snippet | 3 + .../snippets/autologingdm.snippet | 3 + .../snippets/autologintty.snippet | 2 + .../defaultConfigs/snippets/bootbios.snippet | 5 + .../defaultConfigs/snippets/bootefi.snippet | 5 + .../snippets/bootgrubcrypt.snippet | 6 + .../defaultConfigs/snippets/bootnone.snippet | 2 + .../defaultConfigs/snippets/connman.snippet | 2 + .../defaultConfigs/snippets/console.snippet | 2 + .../snippets/desktopEnv/budgie.snippet | 6 + .../snippets/desktopEnv/cinnamon.snippet | 6 + .../snippets/desktopEnv/deepin.snippet | 6 + .../snippets/desktopEnv/enlightment.snippet | 9 + .../snippets/desktopEnv/gnome.snippet | 6 + .../snippets/desktopEnv/lumina.snippet | 6 + .../snippets/desktopEnv/lxqt.snippet | 6 + .../snippets/desktopEnv/mate.snippet | 6 + .../snippets/desktopEnv/pantheon.snippet | 6 + .../snippets/desktopEnv/plasma5.snippet | 6 + .../snippets/desktopEnv/plasma6.snippet | 7 + .../snippets/desktopEnv/xfce.snippet | 6 + .../defaultConfigs/snippets/extra.snippet | 1 + .../defaultConfigs/snippets/firefox.snippet | 1 + .../defaultConfigs/snippets/head.snippet | 7 + .../defaultConfigs/snippets/imports.snippet | 5 + .../defaultConfigs/snippets/keymap.snippet | 5 + .../defaultConfigs/snippets/locale.snippet | 2 + .../snippets/localeextra.snippet | 11 + .../defaultConfigs/snippets/misc.snippet | 5 + .../defaultConfigs/snippets/network.snippet | 6 + .../snippets/networkmanager.snippet | 1 + .../defaultConfigs/snippets/nmapplet.snippet | 2 + .../defaultConfigs/snippets/pkgs.snippet | 6 + .../defaultConfigs/snippets/tail.snippet | 28 ++ .../defaultConfigs/snippets/time.snippet | 1 + .../defaultConfigs/snippets/unfree.snippet | 2 + .../defaultConfigs/snippets/users.snippet | 7 + modules/nixos/main.py | 415 +++--------------- 41 files changed, 288 insertions(+), 343 deletions(-) create mode 100644 modules/nixos/defaultConfigs/modules/.gitkeep create mode 100644 modules/nixos/defaultConfigs/snippets/audio.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/autologin.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/autologingdm.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/autologintty.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/bootbios.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/bootefi.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/bootgrubcrypt.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/bootnone.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/connman.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/console.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/budgie.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/cinnamon.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/deepin.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/enlightment.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/gnome.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/lumina.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/lxqt.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/mate.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/pantheon.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/plasma5.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/plasma6.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/desktopEnv/xfce.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/extra.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/firefox.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/head.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/imports.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/keymap.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/locale.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/localeextra.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/misc.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/network.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/networkmanager.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/nmapplet.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/pkgs.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/tail.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/time.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/unfree.snippet create mode 100644 modules/nixos/defaultConfigs/snippets/users.snippet diff --git a/.editorconfig b/.editorconfig index 44e191e..b3c224e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -27,3 +27,7 @@ insert_final_newline = true indent_style = tab insert_final_newline = true +[*.snippet] +indent_style = space +indent_size = 2 +insert_final_newline = true diff --git a/modules/nixos/defaultConfigs/modules/.gitkeep b/modules/nixos/defaultConfigs/modules/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/nixos/defaultConfigs/snippets/audio.snippet b/modules/nixos/defaultConfigs/snippets/audio.snippet new file mode 100644 index 0000000..e7c04ab --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/audio.snippet @@ -0,0 +1,16 @@ + # Enable sound with pipewire. + sound.enable = false; + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + # If you want to use JACK applications, uncomment this + #jack.enable = true; + + # use the example session manager (no others are packaged yet so this is enabled by default, + # no need to redefine it in your config for now) + #media-session.enable = true; + }; diff --git a/modules/nixos/defaultConfigs/snippets/autologin.snippet b/modules/nixos/defaultConfigs/snippets/autologin.snippet new file mode 100644 index 0000000..1f4e76e --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/autologin.snippet @@ -0,0 +1,3 @@ + # Enable automatic login for the user. + services.xserver.displayManager.autoLogin.enable = true; + services.xserver.displayManager.autoLogin.user = "@@username@@"; diff --git a/modules/nixos/defaultConfigs/snippets/autologingdm.snippet b/modules/nixos/defaultConfigs/snippets/autologingdm.snippet new file mode 100644 index 0000000..dd11ed6 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/autologingdm.snippet @@ -0,0 +1,3 @@ + # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229 + systemd.services."getty@tty1".enable = false; + systemd.services."autovt@tty1".enable = false; diff --git a/modules/nixos/defaultConfigs/snippets/autologintty.snippet b/modules/nixos/defaultConfigs/snippets/autologintty.snippet new file mode 100644 index 0000000..0d210d6 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/autologintty.snippet @@ -0,0 +1,2 @@ + # Enable automatic login for the user. + services.getty.autologinUser = "@@username@@"; diff --git a/modules/nixos/defaultConfigs/snippets/bootbios.snippet b/modules/nixos/defaultConfigs/snippets/bootbios.snippet new file mode 100644 index 0000000..886abae --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/bootbios.snippet @@ -0,0 +1,5 @@ + # Bootloader. + boot.loader.grub.enable = true; + boot.loader.grub.device = "@@bootdev@@"; + boot.loader.grub.useOSProber = true; + boot.tmp.useTmpfs = true; diff --git a/modules/nixos/defaultConfigs/snippets/bootefi.snippet b/modules/nixos/defaultConfigs/snippets/bootefi.snippet new file mode 100644 index 0000000..d9b8c89 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/bootefi.snippet @@ -0,0 +1,5 @@ + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.systemd-boot.configurationLimit = 42; + boot.loader.efi.canTouchEfiVariables = true; + boot.tmp.useTmpfs = true; diff --git a/modules/nixos/defaultConfigs/snippets/bootgrubcrypt.snippet b/modules/nixos/defaultConfigs/snippets/bootgrubcrypt.snippet new file mode 100644 index 0000000..0c73d67 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/bootgrubcrypt.snippet @@ -0,0 +1,6 @@ + # Setup keyfile + boot.initrd.secrets = { + "/boot/crypto_keyfile.bin" = null; + }; + + boot.loader.grub.enableCryptodisk = true; diff --git a/modules/nixos/defaultConfigs/snippets/bootnone.snippet b/modules/nixos/defaultConfigs/snippets/bootnone.snippet new file mode 100644 index 0000000..c3ac45a --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/bootnone.snippet @@ -0,0 +1,2 @@ + # Disable bootloader. + boot.loader.grub.enable = false; diff --git a/modules/nixos/defaultConfigs/snippets/connman.snippet b/modules/nixos/defaultConfigs/snippets/connman.snippet new file mode 100644 index 0000000..2e9f0b8 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/connman.snippet @@ -0,0 +1,2 @@ + # Enable networking + services.connman.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/console.snippet b/modules/nixos/defaultConfigs/snippets/console.snippet new file mode 100644 index 0000000..50c743b --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/console.snippet @@ -0,0 +1,2 @@ + # Configure console keymap + console.keyMap = "@@vconsole@@"; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/budgie.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/budgie.snippet new file mode 100644 index 0000000..be721e0 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/budgie.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the Budgie Desktop environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.budgie.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/cinnamon.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/cinnamon.snippet new file mode 100644 index 0000000..af1f1c6 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/cinnamon.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the Cinnamon Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.cinnamon.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/deepin.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/deepin.snippet new file mode 100644 index 0000000..b6195a1 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/deepin.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the Deepin Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.deepin.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/enlightment.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/enlightment.snippet new file mode 100644 index 0000000..5765fe7 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/enlightment.snippet @@ -0,0 +1,9 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the Enlightenment Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.enlightenment.enable = true; + + # Enable acpid + services.acpid.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/gnome.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/gnome.snippet new file mode 100644 index 0000000..4c91487 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/gnome.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the GNOME Desktop Environment. + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/lumina.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/lumina.snippet new file mode 100644 index 0000000..bd23443 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/lumina.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the Lumina Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.lumina.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/lxqt.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/lxqt.snippet new file mode 100644 index 0000000..8de4f19 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/lxqt.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the LXQT Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.lxqt.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/mate.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/mate.snippet new file mode 100644 index 0000000..64ab2ee --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/mate.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the MATE Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.mate.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/pantheon.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/pantheon.snippet new file mode 100644 index 0000000..640251f --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/pantheon.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the Pantheon Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.pantheon.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/plasma5.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/plasma5.snippet new file mode 100644 index 0000000..2398e56 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/plasma5.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the KDE Plasma Desktop Environment. + services.xserver.displayManager.sddm.enable = true; + services.xserver.desktopManager.plasma5.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/plasma6.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/plasma6.snippet new file mode 100644 index 0000000..ed31850 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/plasma6.snippet @@ -0,0 +1,7 @@ + # Enable the X11 windowing system. + # You can disable this if you're only using the Wayland session. + services.xserver.enable = true; + + # Enable the KDE Plasma Desktop Environment. + services.displayManager.sddm.enable = true; + services.desktopManager.plasma6.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/desktopEnv/xfce.snippet b/modules/nixos/defaultConfigs/snippets/desktopEnv/xfce.snippet new file mode 100644 index 0000000..71f7155 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/desktopEnv/xfce.snippet @@ -0,0 +1,6 @@ + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the XFCE Desktop Environment. + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.xfce.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/extra.snippet b/modules/nixos/defaultConfigs/snippets/extra.snippet new file mode 100644 index 0000000..1300c6f --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/extra.snippet @@ -0,0 +1 @@ + # intentionally empty diff --git a/modules/nixos/defaultConfigs/snippets/firefox.snippet b/modules/nixos/defaultConfigs/snippets/firefox.snippet new file mode 100644 index 0000000..88cdcc8 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/firefox.snippet @@ -0,0 +1 @@ + programs.firefox.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/head.snippet b/modules/nixos/defaultConfigs/snippets/head.snippet new file mode 100644 index 0000000..b2b148b --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/head.snippet @@ -0,0 +1,7 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ diff --git a/modules/nixos/defaultConfigs/snippets/imports.snippet b/modules/nixos/defaultConfigs/snippets/imports.snippet new file mode 100644 index 0000000..6c76d6d --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/imports.snippet @@ -0,0 +1,5 @@ + imports = + [ + # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; diff --git a/modules/nixos/defaultConfigs/snippets/keymap.snippet b/modules/nixos/defaultConfigs/snippets/keymap.snippet new file mode 100644 index 0000000..415fb07 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/keymap.snippet @@ -0,0 +1,5 @@ + # Configure keymap in X11 + services.xserver.xkb = { + layout = "@@kblayout@@"; + variant = "@@kbvariant@@"; + }; diff --git a/modules/nixos/defaultConfigs/snippets/locale.snippet b/modules/nixos/defaultConfigs/snippets/locale.snippet new file mode 100644 index 0000000..34014e9 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/locale.snippet @@ -0,0 +1,2 @@ + # Select internationalisation properties. + i18n.defaultLocale = "@@LANG@@"; diff --git a/modules/nixos/defaultConfigs/snippets/localeextra.snippet b/modules/nixos/defaultConfigs/snippets/localeextra.snippet new file mode 100644 index 0000000..b5a870b --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/localeextra.snippet @@ -0,0 +1,11 @@ + i18n.extraLocaleSettings = { + LC_ADDRESS = "@@LC_ADDRESS@@"; + LC_IDENTIFICATION = "@@LC_IDENTIFICATION@@"; + LC_MEASUREMENT = "@@LC_MEASUREMENT@@"; + LC_MONETARY = "@@LC_MONETARY@@"; + LC_NAME = "@@LC_NAME@@"; + LC_NUMERIC = "@@LC_NUMERIC@@"; + LC_PAPER = "@@LC_PAPER@@"; + LC_TELEPHONE = "@@LC_TELEPHONE@@"; + LC_TIME = "@@LC_TIME@@"; + }; diff --git a/modules/nixos/defaultConfigs/snippets/misc.snippet b/modules/nixos/defaultConfigs/snippets/misc.snippet new file mode 100644 index 0000000..5b9c40a --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/misc.snippet @@ -0,0 +1,5 @@ + # Enable CUPS to print documents. + services.printing.enable = true; + + # Enable touchpad support (enabled default in most desktopManager). + # services.xserver.libinput.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/network.snippet b/modules/nixos/defaultConfigs/snippets/network.snippet new file mode 100644 index 0000000..013b8c0 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/network.snippet @@ -0,0 +1,6 @@ + networking.hostName = "@@hostname@@"; # Define your hostname. + # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; diff --git a/modules/nixos/defaultConfigs/snippets/networkmanager.snippet b/modules/nixos/defaultConfigs/snippets/networkmanager.snippet new file mode 100644 index 0000000..20c4f71 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/networkmanager.snippet @@ -0,0 +1 @@ + networking.networkmanager.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/nmapplet.snippet b/modules/nixos/defaultConfigs/snippets/nmapplet.snippet new file mode 100644 index 0000000..90b904d --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/nmapplet.snippet @@ -0,0 +1,2 @@ + # Enable network manager applet + programs.nm-applet.enable = true; diff --git a/modules/nixos/defaultConfigs/snippets/pkgs.snippet b/modules/nixos/defaultConfigs/snippets/pkgs.snippet new file mode 100644 index 0000000..cc2d093 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/pkgs.snippet @@ -0,0 +1,6 @@ + # 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 + ]; diff --git a/modules/nixos/defaultConfigs/snippets/tail.snippet b/modules/nixos/defaultConfigs/snippets/tail.snippet new file mode 100644 index 0000000..1c5f419 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/tail.snippet @@ -0,0 +1,28 @@ + # 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 = "@@nixosversion@@"; # Did you read the comment? + +} diff --git a/modules/nixos/defaultConfigs/snippets/time.snippet b/modules/nixos/defaultConfigs/snippets/time.snippet new file mode 100644 index 0000000..174a7f0 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/time.snippet @@ -0,0 +1 @@ + time.timeZone = "@@timezone@@"; diff --git a/modules/nixos/defaultConfigs/snippets/unfree.snippet b/modules/nixos/defaultConfigs/snippets/unfree.snippet new file mode 100644 index 0000000..38cb845 --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/unfree.snippet @@ -0,0 +1,2 @@ + # Allow unfree packages + nixpkgs.config.allowUnfree = true; diff --git a/modules/nixos/defaultConfigs/snippets/users.snippet b/modules/nixos/defaultConfigs/snippets/users.snippet new file mode 100644 index 0000000..6313a7c --- /dev/null +++ b/modules/nixos/defaultConfigs/snippets/users.snippet @@ -0,0 +1,7 @@ + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.@@username@@ = { + isNormalUser = true; + description = "@@fullname@@"; + extraGroups = [ @@groups@@ ]; + packages = with pkgs; [@@pkgs@@]; + }; diff --git a/modules/nixos/main.py b/modules/nixos/main.py index c116ec0..20172e8 100644 --- a/modules/nixos/main.py +++ b/modules/nixos/main.py @@ -22,320 +22,44 @@ fallback=True, ).gettext +def getCalamaresNixosModulePath(): + return '/run/current-system/sw/lib/calamares/modules/nixos' -# The following strings contain pieces of a nix-configuration file. -# They are adapted from the default config generated from the nixos-generate-config command. +def getCustomOrDefaultSnippet(snippetName): + configPath = getCalamaresNixosModulePath() -cfghead = """# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page -# and in the NixOS manual (accessible by running ‘nixos-help’). + # Check if a custom snippet exists for the config name + snippetConfigPath = '{}/defaultConfigs/snippets/{}.snippet'.format(configPath, snippetName) + customConfigFilePath = '{}/customConfigs/snippets/{}.snippet'.format(configPath, snippetName) -{ config, pkgs, ... }: - -{ - imports = - [ # Include the results of the hardware scan. - ./hardware-configuration.nix - ]; - -""" -cfgbootefi = """ # Bootloader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - -""" - -cfgbootbios = """ # Bootloader. - boot.loader.grub.enable = true; - boot.loader.grub.device = "@@bootdev@@"; - boot.loader.grub.useOSProber = true; - -""" - -cfgbootnone = """ # Disable bootloader. - boot.loader.grub.enable = false; - -""" - -cfgbootgrubcrypt = """ # Setup keyfile - boot.initrd.secrets = { - "/boot/crypto_keyfile.bin" = null; - }; - - boot.loader.grub.enableCryptodisk = true; - -""" - -cfgnetwork = """ networking.hostName = "@@hostname@@"; # Define your hostname. - # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. - - # Configure network proxy if necessary - # networking.proxy.default = "http://user:password@proxy:port/"; - # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; - -""" - -cfgnetworkmanager = """ # Enable networking - networking.networkmanager.enable = true; - -""" - -cfgconnman = """ # Enable networking - services.connman.enable = true; - -""" - -cfgnmapplet = """ # Enable network manager applet - programs.nm-applet.enable = true; - -""" - -cfgtime = """ # Set your time zone. - time.timeZone = "@@timezone@@"; - -""" - -cfglocale = """ # Select internationalisation properties. - i18n.defaultLocale = "@@LANG@@"; - -""" - -cfglocaleextra = """ i18n.extraLocaleSettings = { - LC_ADDRESS = "@@LC_ADDRESS@@"; - LC_IDENTIFICATION = "@@LC_IDENTIFICATION@@"; - LC_MEASUREMENT = "@@LC_MEASUREMENT@@"; - LC_MONETARY = "@@LC_MONETARY@@"; - LC_NAME = "@@LC_NAME@@"; - LC_NUMERIC = "@@LC_NUMERIC@@"; - LC_PAPER = "@@LC_PAPER@@"; - LC_TELEPHONE = "@@LC_TELEPHONE@@"; - LC_TIME = "@@LC_TIME@@"; - }; - -""" - -cfggnome = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the GNOME Desktop Environment. - services.xserver.displayManager.gdm.enable = true; - services.xserver.desktopManager.gnome.enable = true; - -""" - -cfgplasma5 = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the KDE Plasma Desktop Environment. - services.displayManager.sddm.enable = true; - services.xserver.desktopManager.plasma5.enable = true; - -""" - -cfgplasma6 = """ # Enable the X11 windowing system. - # You can disable this if you're only using the Wayland session. - services.xserver.enable = true; - - # Enable the KDE Plasma Desktop Environment. - services.displayManager.sddm.enable = true; - services.desktopManager.plasma6.enable = true; - -""" - -cfgxfce = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the XFCE Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.xfce.enable = true; - -""" - -cfgpantheon = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the Pantheon Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.pantheon.enable = true; - -""" - -cfgcinnamon = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the Cinnamon Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.cinnamon.enable = true; - -""" - -cfgmate = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the MATE Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.mate.enable = true; - -""" - -cfgenlightenment = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the Enlightenment Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.enlightenment.enable = true; - - # Enable acpid - services.acpid.enable = true; - -""" - -cfglxqt = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the LXQT Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.lxqt.enable = true; - -""" - -cfglumina = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the Lumina Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.lumina.enable = true; - -""" - -cfgbudgie = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the Budgie Desktop environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.budgie.enable = true; - -""" - -cfgdeepin = """ # Enable the X11 windowing system. - services.xserver.enable = true; - - # Enable the Deepin Desktop Environment. - services.xserver.displayManager.lightdm.enable = true; - services.xserver.desktopManager.deepin.enable = true; - -""" - -cfgkeymap = """ # Configure keymap in X11 - services.xserver.xkb = { - layout = "@@kblayout@@"; - variant = "@@kbvariant@@"; - }; - -""" -cfgconsole = """ # Configure console keymap - console.keyMap = "@@vconsole@@"; - -""" - -cfgmisc = """ # Enable CUPS to print documents. - services.printing.enable = true; - - # Enable sound with pipewire. - hardware.pulseaudio.enable = false; - security.rtkit.enable = true; - services.pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; - # If you want to use JACK applications, uncomment this - #jack.enable = true; - - # use the example session manager (no others are packaged yet so this is enabled by default, - # no need to redefine it in your config for now) - #media-session.enable = true; - }; - - # Enable touchpad support (enabled default in most desktopManager). - # services.xserver.libinput.enable = true; - -""" -cfgusers = """ # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.@@username@@ = { - isNormalUser = true; - description = "@@fullname@@"; - extraGroups = [ @@groups@@ ]; - packages = with pkgs; [@@pkgs@@]; - }; - -""" - -cfgfirefox = """ # Install firefox. - programs.firefox.enable = true; - -""" - -cfgautologin = """ # Enable automatic login for the user. - services.xserver.displayManager.autoLogin.enable = true; - services.xserver.displayManager.autoLogin.user = "@@username@@"; - -""" - -cfgautologingdm = """ # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229 - systemd.services."getty@tty1".enable = false; - systemd.services."autovt@tty1".enable = false; - -""" - -cfgautologintty = """ # Enable automatic login for the user. - services.getty.autologinUser = "@@username@@"; - -""" - -cfgunfree = """ # Allow unfree packages - nixpkgs.config.allowUnfree = true; - -""" - -cfgpkgs = """ # 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 - ]; - -""" - -cfgtail = """ # 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: + if os.path.isfile(customConfigFilePath): + libcalamares.utils.debug('Selected custom snippet: {} from {}'.format(snippetName, customConfigFilePath)) + snippetConfigPath = customConfigFilePath + else: + libcalamares.utils.debug('Selected default snippet: {} from {}'.format(snippetName, snippetConfigPath)) - # Enable the OpenSSH daemon. - # services.openssh.enable = true; + # load config + with open(snippetConfigPath, 'r') as configReader: + snippet = configReader.read() + snippet += '\n' + return snippet - # Open ports in the firewall. - # networking.firewall.allowedTCPPorts = [ ... ]; - # networking.firewall.allowedUDPPorts = [ ... ]; - # Or disable the firewall altogether. - # networking.firewall.enable = false; + libcalamares.utils.error('Failed to load config snippet {}'.format(snippetName)) + return "" - # 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 = "@@nixosversion@@"; # Did you read the comment? +def copyModules(root_mount_point, subpath): + customModuleFolderPath = '{}/{}/.'.format(getCalamaresNixosModulePath(), subpath) + destModuleFolderPath = '{}/etc/nixos/modules/'.format(root_mount_point) + if not os.path.isdir(destModuleFolderPath): + libcalamares.utils.host_env_process_output( + ["mkdir", "-p", destModuleFolderPath], None + ) + if os.path.isdir(customModuleFolderPath): + libcalamares.utils.debug('Copying module directory {}'.format(customModuleFolderPath)) + libcalamares.utils.host_env_process_output(["cp", "-r", customModuleFolderPath, destModuleFolderPath], None) + else: + libcalamares.utils.debug('Skipping non-existing module directory {}'.format(customModuleFolderPath)) -} -""" def env_is_set(name): envValue = os.environ.get(name) return not (envValue is None or envValue == "") @@ -388,7 +112,8 @@ def run(): libcalamares.job.setprogress(0.1) # Create initial config file - cfg = cfghead + cfg = getCustomOrDefaultSnippet('head') + cfg += getCustomOrDefaultSnippet('imports') gs = libcalamares.globalstorage variables = dict() @@ -406,12 +131,12 @@ def run(): # Check bootloader if fw_type == "efi": - cfg += cfgbootefi + cfg += getCustomOrDefaultSnippet('bootefi') elif bootdev != "nodev": - cfg += cfgbootbios + cfg += getCustomOrDefaultSnippet('bootbios') catenate(variables, "bootdev", bootdev) else: - cfg += cfgbootnone + cfg += getCustomOrDefaultSnippet('bootnone') # Setup encrypted swap devices. nixos-generate-config doesn't seem to notice them. for part in gs.value("partitions"): @@ -442,7 +167,7 @@ def run(): (boot_is_partition and boot_is_encrypted) or (root_is_encrypted and not boot_is_partition) ): - cfg += cfgbootgrubcrypt + cfg += getCustomOrDefaultSnippet('bootgrubcrypt') status = _("Setting up LUKS") libcalamares.job.setprogress(0.15) try: @@ -531,18 +256,18 @@ def run(): status = _("Configuring NixOS") libcalamares.job.setprogress(0.18) - cfg += cfgnetwork + cfg += getCustomOrDefaultSnippet('network') if gs.value("packagechooser_packagechooser") == "enlightenment": - cfg += cfgconnman + cfg += getCustomOrDefaultSnippet('connman') else: - cfg += cfgnetworkmanager + cfg += getCustomOrDefaultSnippet('networkmanager') if ( (gs.value("packagechooser_packagechooser") == "mate") | (gs.value("packagechooser_packagechooser") == "lxqt") | (gs.value("packagechooser_packagechooser") == "lumina") ): - cfg += cfgnmapplet + cfg += getCustomOrDefaultSnippet('nmapplet') if gs.value("hostname") is None: catenate(variables, "hostname", "nixos") @@ -550,7 +275,7 @@ def run(): catenate(variables, "hostname", gs.value("hostname")) if gs.value("locationRegion") is not None and gs.value("locationZone") is not None: - cfg += cfgtime + cfg += getCustomOrDefaultSnippet('time') catenate( variables, "timezone", @@ -562,47 +287,47 @@ def run(): if gs.value("localeConf") is not None: localeconf = gs.value("localeConf") locale = localeconf.pop("LANG").split("/")[0] - cfg += cfglocale + cfg += getCustomOrDefaultSnippet('locale') catenate(variables, "LANG", locale) if ( len(set(localeconf.values())) != 1 or list(set(localeconf.values()))[0] != locale ): - cfg += cfglocaleextra + cfg += getCustomOrDefaultSnippet('localeextra') for conf in localeconf: catenate(variables, conf, localeconf.get(conf).split("/")[0]) # Choose desktop environment if gs.value("packagechooser_packagechooser") == "gnome": - cfg += cfggnome + cfg += getCustomOrDefaultSnippet('desktopEnv/gnome') elif gs.value("packagechooser_packagechooser") == "plasma5": - cfg += cfgplasma5 + cfg += getCustomOrDefaultSnippet('desktopEnv/plasma5') elif gs.value("packagechooser_packagechooser") == "plasma6": - cfg += cfgplasma6 + cfg += getCustomOrDefaultSnippet('desktopEnv/plasma6') elif gs.value("packagechooser_packagechooser") == "xfce": - cfg += cfgxfce + cfg += getCustomOrDefaultSnippet('desktopEnv/xfce') elif gs.value("packagechooser_packagechooser") == "pantheon": - cfg += cfgpantheon + cfg += getCustomOrDefaultSnippet('desktopEnv/pantheon') elif gs.value("packagechooser_packagechooser") == "cinnamon": - cfg += cfgcinnamon + cfg += getCustomOrDefaultSnippet('desktopEnv/cinnamon') elif gs.value("packagechooser_packagechooser") == "mate": - cfg += cfgmate + cfg += getCustomOrDefaultSnippet('desktopEnv/mate') elif gs.value("packagechooser_packagechooser") == "enlightenment": - cfg += cfgenlightenment + cfg += getCustomOrDefaultSnippet('desktopEnv/enlightenment') elif gs.value("packagechooser_packagechooser") == "lxqt": - cfg += cfglxqt + cfg += getCustomOrDefaultSnippet('desktopEnv/lxqt') elif gs.value("packagechooser_packagechooser") == "lumina": - cfg += cfglumina + cfg += getCustomOrDefaultSnippet('desktopEnv/lumina') elif gs.value("packagechooser_packagechooser") == "budgie": - cfg += cfgbudgie + cfg += getCustomOrDefaultSnippet('desktopEnv/budgie') elif gs.value("packagechooser_packagechooser") == "deepin": - cfg += cfgdeepin + cfg += getCustomOrDefaultSnippet('desktopEnv/deepin') if ( gs.value("keyboardLayout") is not None and gs.value("keyboardVariant") is not None ): - cfg += cfgkeymap + cfg += getCustomOrDefaultSnippet('keymap') catenate(variables, "kblayout", gs.value("keyboardLayout")) catenate(variables, "kbvariant", gs.value("keyboardVariant")) @@ -612,7 +337,7 @@ def run(): ["pkexec", "loadkeys", gs.value("keyboardVConsoleKeymap").strip()], stderr=subprocess.STDOUT, ) - cfg += cfgconsole + cfg += getCustomOrDefaultSnippet('console') catenate( variables, "vconsole", gs.value("keyboardVConsoleKeymap").strip() ) @@ -657,7 +382,7 @@ def run(): subprocess.check_output( ["pkexec", "loadkeys", vconsole], stderr=subprocess.STDOUT ) - cfg += cfgconsole + cfg += getCustomOrDefaultSnippet('console') catenate(variables, "vconsole", vconsole) except subprocess.CalledProcessError as e: libcalamares.utils.error("loadkeys: {}".format(e.output)) @@ -672,13 +397,13 @@ def run(): gs.value("packagechooser_packagechooser") is not None and gs.value("packagechooser_packagechooser") != "" ): - cfg += cfgmisc + cfg += getCustomOrDefaultSnippet('misc') if gs.value("username") is not None: fullname = gs.value("fullname") groups = ["networkmanager", "wheel"] - cfg += cfgusers + cfg += getCustomOrDefaultSnippet('users') catenate(variables, "username", gs.value("username")) catenate(variables, "fullname", fullname) catenate(variables, "groups", (" ").join(['"' + s + '"' for s in groups])) @@ -687,23 +412,23 @@ def run(): and gs.value("packagechooser_packagechooser") is not None and gs.value("packagechooser_packagechooser") != "" ): - cfg += cfgautologin + cfg += getCustomOrDefaultSnippet('autologin') if gs.value("packagechooser_packagechooser") == "gnome": - cfg += cfgautologingdm + cfg += getCustomOrDefaultSnippet('autologingdm') elif gs.value("autoLoginUser") is not None: - cfg += cfgautologintty + cfg += getCustomOrDefaultSnippet('autologintty') if gs.value("packagechooser_packagechooser") != "": - cfg += cfgfirefox + cfg += getCustomOrDefaultSnippet('firefox') # Check if unfree packages are allowed free = True if gs.value("packagechooser_unfree") is not None: if gs.value("packagechooser_unfree") == "unfree": free = False - cfg += cfgunfree + cfg += getCustomOrDefaultSnippet('unfree') - cfg += cfgpkgs + cfg += getCustomOrDefaultSnippet('pkgs') # Use firefox as default as a graphical web browser, and add kate to plasma desktop if gs.value("packagechooser_packagechooser") == "plasma5": catenate(variables, "pkgs", "\n kate\n # thunderbird\n ") @@ -716,7 +441,7 @@ def run(): else: catenate(variables, "pkgs", "") - cfg += cfgtail + cfg += getCustomOrDefaultSnippet('tail') version = ".".join(subprocess.getoutput(["nixos-version"]).split(".")[:2])[:5] catenate(variables, "nixosversion", version) @@ -806,6 +531,10 @@ def run(): # Write the configuration.nix file libcalamares.utils.host_env_process_output(["cp", "/dev/stdin", config], None, cfg) + # Copy modules + copyModules(root_mount_point, 'defaultConfigs/modules') + copyModules(root_mount_point, 'customConfigs/modules') + status = _("Installing NixOS") libcalamares.job.setprogress(0.3)