Universe/modules/default.nix

312 lines
7.6 KiB
Nix

# Universe - The big bang to my universe
#
# Copyright (c) 2023-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
params:
rec {
# A single nixos config outputting multiple formats.
# Alternatively put this in a configuration.nix.
generator = {config, ...}: {
imports = [
params.nixos-generators.nixosModules.all-formats
];
nixpkgs.hostPlatform = "x86_64-linux";
# customize an existing format
formatConfigs.iso = {config, ...}: {
services.openssh.enable = true;
};
};
git = import ./git;
base = {config, lib, pkgs, inputs, ...}:
let
universePkg = pkgs.callPackage ../derivations/universe.nix {};
in {
# point the system nixpkgs to this flake by indirecting through
# /etc so it changes when the system switches without having to
# restart all the terminals. thanks ElvishJerricco
nix.registry = builtins.mapAttrs (n: flake: { inherit flake; }) inputs;
environment.etc = lib.mapAttrs' (name: flake: {
name = "nix/inputs/${name}";
value.source = flake.outPath;
}) inputs;
nix.nixPath = [ "/etc/nix/inputs" ];
# Neverever change this value
system.stateVersion = "24.05";
services.getty.greetingLine = ''[Welcome to Universe ${config.system.nixos.label} (\m) - \l]'';
# Include some utilities that are useful for installing or repairing
# the system.
environment.systemPackages = [
pkgs.w3m-nographics # needed for the manual anyway
pkgs.testdisk # useful for repairing boot problems
pkgs.ms-sys # for writing Microsoft boot sectors / MBRs
pkgs.efibootmgr
pkgs.efivar
pkgs.parted
pkgs.gptfdisk
pkgs.ddrescue
pkgs.ccrypt
pkgs.cryptsetup # needed for dm-crypt volumes
# Some networking tools.
pkgs.fuse
pkgs.fuse3
pkgs.sshfs-fuse
pkgs.socat
pkgs.screen
pkgs.tcpdump
# Hardware-related tools.
pkgs.sdparm
pkgs.hdparm
pkgs.smartmontools # for diagnosing hard disks
pkgs.pciutils
pkgs.usbutils
pkgs.nvme-cli
# Some compression/archiver tools.
pkgs.unzip
pkgs.zip
pkgs.ripgrep
pkgs.bat
pkgs.wget
pkgs.curl
pkgs.htop
pkgs.man
pkgs.man-pages
pkgs.man-pages-posix
pkgs.git
pkgs.emacs-nox
universePkg
];
environment.variables.EDITOR = "emacs";
documentation.enable = true;
documentation.dev.enable = true;
documentation.man = {
man-db.enable = true;
enable = true;
generateCaches = false;
};
nix.settings = {
experimental-features = lib.mkDefault "nix-command flakes";
};
i18n.defaultLocale = "en_US.UTF-8";
console = {
font = "Lat2-Terminus16";
keyMap = lib.mkDefault "us";
useXkbConfig = true; # use xkb.options in tty.
};
# Include support for various filesystems and tools to create / manipulate them.
boot.supportedFilesystems =
[ "btrfs" "cifs" "f2fs" "vfat" "xfs" ];
services.openssh.enable = true;
programs.mtr.enable = true;
programs.gnupg.agent = {
enable = true;
enableSSHSupport = true;
};
};
desktop = { pkgs, lib, inputs, ... }: {
environment.noXlibs = lib.mkForce false;
services.xserver = {
enable = true;
autorun = false;
xkb.layout = "us";
xkb.options = "eurosign:e";
displayManager = {
defaultSession = "fg42";
startx.enable = true;
};
libinput.enable = true; # for touchpad support
videoDrivers = [
"amdgpu"
];
};
hardware.opengl.extraPackages = with pkgs; [
amdvlk
];
sound.enable = true;
# Enable sound in virtualbox appliances.
hardware.pulseaudio.enable = true;
hardware.opengl = {
enable = true;
setLdLibraryPath = true;
package = pkgs.mesa_drivers;
driSupport = true;
driSupport32Bit = true;
};
environment.systemPackages = [
pkgs.glxinfo
pkgs.xorg.xhost # not included by the x11 nixos module bydefault
];
networking.networkmanager.enable = true;
};
installerUser = {config, pkgs, ...}: {
users = {
users.universe = {
password = "universe";
isNormalUser = true;
extraGroups = [
"wheel"
"networkmanager"
];
};
};
nix.settings = {
trusted-users = [ "root" "@wheel" "universe" ];
};
};
bootable = { lib, pkgs, ...}: {
boot = {
kernelPackages = lib.mkDefault pkgs.linuxPackages_latest;
loader = {
grub.enable = lib.mkDefault true;
};
};
};
disk-installer = host: diskFile: { lib, pkgs, inputs, hostBuilderConfig, ... }: {
imports = [];
environment.systemPackages = [
pkgs.disko
(pkgs.writeShellScriptBin "install-universe" ''
# if /etc/universe_release
export NIX_PATH=/etc/nix/inputs/
echo "Partitioning the disk..."
echo "${diskFile}"
cp "${diskFile}" /etc/sdisk.nix
${pkgs.disko}/bin/disko -m disko /etc/disks.nix
mkdir -p /mnt/etc/nix
ln -s /mnt/etc/nix/inputs/ /etc/nix/inputs/
cd /mnt
echo "running installer"
nixos-install --impure --flake self#${host} --root /mnt -v --show-trace
echo "done"
'')
];
environment.etc = {
"disks.nix".source = diskFile;
};
boot.loader.grub.device = "nodev";
boot.loader.grub.efiSupport = true;
boot.loader.grub.efiInstallAsRemovable = true;
};
disk = diskFile: { lib, pkgs, inputs, hostBuilderConfig, ... }: {
imports = [
"${inputs.disko}/module.nix"
];
disko = lib.optionalAttrs (!hostBuilderConfig.inVM) (import diskFile).disko;
environment.etc = {
"disks.nix".source = diskFile;
};
boot.loader.grub.device = "nodev";
boot.loader.grub.efiSupport = true;
boot.loader.grub.efiInstallAsRemovable = true;
};
styles = { lib, pkgs, inputs, ...}: {
imports = [
inputs.stylix.nixosModules.stylix
];
stylix.image = lib.mkDefault ./wallpaper.jpg;
stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/stella.yaml";
stylix.polarity = "dark";
stylix.fonts = {
serif = {
package = pkgs.vazir-fonts;
name = "Vazirmatn";
};
sansSerif = {
package = pkgs.vazir-fonts;
name = "Vazirmatn";
};
monospace = {
package = pkgs.fira-mono;
name = "Fira Mono";
};
emoji = {
package = pkgs.noto-fonts-emoji;
name = "Noto Color Emoji";
};
sizes = {
applications = 10;
desktop = 10;
popups = 10;
terminal = 10;
};
};
};
yubikey = { config, lib, pkgs, ...}: {
services.pcscd.enable = true;
services.udev.packages = [ pkgs.yubikey-personalization ];
environment.systemPackages = [
pkgs.yubikey-manager
];
};
virtualisation = import ./virtualisation {};
}