feasible config for the beginning

This commit is contained in:
MFlossmann 2024-03-27 23:45:23 +01:00
parent b4c2ba8174
commit 25d5980e6c
13 changed files with 563 additions and 203 deletions

21
flake.lock generated
View file

@ -1,5 +1,25 @@
{
"nodes": {
"disko": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1714405407,
"narHash": "sha256-h3pOvHCXkSdp1KOZqtkQmHgkR7VaOJXDhqhumk7sZLY=",
"owner": "nix-community",
"repo": "disko",
"rev": "5eaf747af38dd272e1ab28a8ec4bd972424b07cf",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "disko",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
@ -54,6 +74,7 @@
},
"root": {
"inputs": {
"disko": "disko",
"home-manager": "home-manager",
"nixpkgs": "nixpkgs",
"nixpkgs-stable": "nixpkgs-stable"

View file

@ -9,38 +9,27 @@
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self, nixpkgs, ...
} @ inputs: let
systems = [
"aarch64-linux"
"i686-linux"
"x86_64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
# This is a function that generates an attribute by calling a function you
# pass to it, with each system as an argument
forAllSystems = nixpkgs.lib.genAttrs systems;
systemModules = import ./modules/system;
homeModules = import ./modules/home;
in {
outputs = {...} @ inputs: let
# basic boilerplate-reducing lib with a bunch of functions
helperLib = import ./helperLib/default.nix {inherit inputs;};
in
with helperLib; {
nixosConfigurations = {
default = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs systemModules homeModules;};
modules = [
./hosts/default/configuration.nix
];
remus = mkSystem ./hosts/remus/configuration.nix;
};
remus = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs systemModules homeModules;};
modules = [
./hosts/remus/configuration.nix
];
};
homeConfigurations = {
"prunebutt@remus" = mkHome "x86_64-linux" ./hosts/remus/home.nix;
};
homeManagerModules.default = ./modules/home;
nixosModules.default = ./modules/nixOS;
};
}

103
helperLib/default.nix Normal file
View file

@ -0,0 +1,103 @@
{inputs}: let
helperLib = (import ./default.nix) {inherit inputs;};
outputs = inputs.self.outputs;
in rec {
# ================================================================ #
# = My Lib = #
# ================================================================ #
# ======================= Package Helpers ======================== #
pkgsFor = sys: inputs.nixpkgs.legacyPackages.${sys};
# ========================== Buildables ========================== #
mkSystem = config:
inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs outputs helperLib;
};
modules = [
config
outputs.nixosModules.default
];
};
mkHome = sys: config:
inputs.home-manager.lib.homeManagerConfiguration {
pkgs = pkgsFor sys;
extraSpecialArgs = {
inherit inputs helperLib outputs;
};
modules = [
config
outputs.homeManagerModules.default
];
};
# =========================== Helpers ============================ #
filesIn = dir: (map (fname: dir + "/${fname}")
(builtins.attrNames (builtins.readDir dir)));
dirsIn = dir:
inputs.nixpkgs.lib.filterAttrs (name: value: value == "directory")
(builtins.readDir dir);
fileNameOf = path: (builtins.head (builtins.split "\\." (baseNameOf path)));
# ========================== Extenders =========================== #
# Evaluates nixos/home-manager module and extends it's options / config
extendModule = {path, ...} @ args: {pkgs, ...} @ margs: let
eval =
if (builtins.isString path) || (builtins.isPath path)
then import path margs
else path margs;
evalNoImports = builtins.removeAttrs eval ["imports" "options"];
extra =
if (builtins.hasAttr "extraOptions" args) || (builtins.hasAttr "extraConfig" args)
then [
({...}: {
options = args.extraOptions or {};
config = args.extraConfig or {};
})
]
else [];
in {
imports =
(eval.imports or [])
++ extra;
options =
if builtins.hasAttr "optionsExtension" args
then (args.optionsExtension (eval.options or {}))
else (eval.options or {});
config =
if builtins.hasAttr "configExtension" args
then (args.configExtension (eval.config or evalNoImports))
else (eval.config or evalNoImports);
};
# Applies extendModules to all modules
# modules can be defined in the same way
# as regular imports, or taken from "filesIn"
extendModules = extension: modules:
map
(f: let
name = fileNameOf f;
in (extendModule ((extension name) // {path = f;})))
modules;
# ============================ Shell ============================= #
forAllSystems = pkgs:
inputs.nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
]
(system: pkgs inputs.nixpkgs.legacyPackages.${system});
}

View file

@ -1,111 +1,36 @@
# 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, inputs, ... }:
{
{ config, pkgs, lib, inputs, outputs, system, helperLib, ... }: {
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
inputs.home-manager.nixosModules.default
outputs.nixosModules.default
];
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# Bootloader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.hostName = "remus";
# 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";
# Enable networking
networking.networkmanager.enable = true;
# Set your time zone.
time.timeZone = "Europe/Berlin";
# Select internationalisation properties.
i18n.defaultLocale = "en_US.UTF-8";
i18n.extraLocaleSettings = {
LC_ADDRESS = "de_DE.UTF-8";
LC_IDENTIFICATION = "de_DE.UTF-8";
LC_MEASUREMENT = "de_DE.UTF-8";
LC_MONETARY = "de_DE.UTF-8";
LC_NAME = "de_DE.UTF-8";
LC_NUMERIC = "de_DE.UTF-8";
LC_PAPER = "de_DE.UTF-8";
LC_TELEPHONE = "de_DE.UTF-8";
LC_TIME = "de_DE.UTF-8";
boot.loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
# 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;
# Configure keymap in X11
services.xserver.xkb = {
layout = "de";
variant = "neo";
networking = {
hostName = "remus";
networkmanager.enable = true;
# wireless.enable = true; # Enables wireless support via wpa_supplicant.
};
# Configure console keymap
console.keyMap = "de";
myNixOS = {
bundles.general-desktop.enable = true;
# Enable CUPS to print documents.
services.printing.enable = true;
# Enable sound with pipewire.
sound.enable = true;
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;
users.users.prunebutt = {
isNormalUser = true;
description = "prunebutt";
extraGroups = [ "networkmanager" "wheel" ];
packages = with pkgs; [
firefox
thunderbird
signal-desktop
keepassxc
syncthing
];
};
home-manager = {
extraSpecialArgs = { inherit inputs; };
users = {
"prunebutt" = import ./home.nix;
home-users = {
"prunebutt" = {
userConfig = ./home.nix;
userSettings = {
extraGroups = ["networkmanager" "wheel" "libvirtd" "docker"];
};
};
};
};
# Allow unfree packages
nixpkgs.config.allowUnfree = true;
# List packages installed in system profile. To search, run:
# $ nix search wget
@ -113,6 +38,7 @@
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
git
libgcc
];
# Some programs need SUID wrappers, can be configured further or are
@ -126,7 +52,7 @@
# List services that you want to enable:
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
services.openssh.enable = true;
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];

View file

@ -1,28 +1,21 @@
{ config, pkgs, ... }:
{
# Home Manager needs a bit of information about you and the paths it should
# manage.
home.username = "prunebutt";
home.homeDirectory = "/home/prunebutt";
# This value determines the Home Manager release that your configuration is
# compatible with. This helps avoid breakage when a new Home Manager release
# introduces backwards incompatible changes.
#
# home.username = "prunebutt";
# home.homeDirectory = "/home/prunebutt";
home = let
user = "prunebutt";
in {
username = "${user}";
homeDirectory = "/home/${user}";
# You should not change this value, even if you update Home Manager. If you do
# want to update the value, then make sure to first check the Home Manager
# release notes.
home.stateVersion = "23.11"; # Please read the comment before changing.
stateVersion = "23.11"; # Please read the comment before changing.
# The home.packages option allows you to install Nix packages into your
# environment.
home.packages = with pkgs; [
# # Adds the 'hello' command to your environment. It prints a friendly
# # "Hello, world!" when run.
# pkgs.hello
nerdfonts
packages = with pkgs; [
# # It is sometimes useful to fine-tune packages, for example, by applying
# # overrides. You can do that directly here, just don't forget the
# # parentheses. Maybe you want to install Nerd Fonts with a limited number of
@ -36,59 +29,21 @@
# echo "Hello, ${config.home.username}!"
# '')
# Core
ranger
## GNOME
gnomeExtensions.gsconnect
gnomeExtensions.syncthing-icon
# Maker
freecad
# Development
lazygit
];
};
myHomeManager.bundles.desktop.enable = true;
myHomeManager.bundles.maker.enable = true;
programs.zsh.enable = true;
programs.neovim.enable = true;
programs.neovim.defaultEditor = true;
# Home Manager is pretty good at managing dotfiles. The primary way to manage
# plain files is through 'home.file'.
home.file = {
# # Building this configuration will create a copy of 'dotfiles/screenrc' in
# # the Nix store. Activating the configuration will then make '~/.screenrc' a
# # symlink to the Nix store copy.
# ".screenrc".source = dotfiles/screenrc;
# # You can also set the file content immediately.
# ".gradle/gradle.properties".text = ''
# org.gradle.console=verbose
# org.gradle.daemon.idletimeout=3600000
# '';
};
# Home Manager can also manage your environment variables through
# 'home.sessionVariables'. If you don't want to manage your shell through Home
# Manager then you have to manually source 'hm-session-vars.sh' located at
# either
#
# ~/.nix-profile/etc/profile.d/hm-session-vars.sh
#
# or
#
# ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh
#
# or
#
# /etc/profiles/per-user/prunebutt/etc/profile.d/hm-session-vars.sh
#
home.sessionVariables = {
EDITOR = "nvim";
};
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
# programs.home-manager.enable = true;
}

View file

@ -0,0 +1,54 @@
{
pkgs,
config,
lib,
inputs,
...
}: {
imports = [];
nixpkgs.config = {
allowUnfree = true;
experimental-features = "nix-command flakes";
};
programs.home-manager.enable = true;
home.packages = with pkgs; [
# nix
nil
nh
git
lazygit
tree-sitter
# file-management
ranger
pistol
file
p7zip
unzip
zip
# tools
killall
fzf
eza # ls-replacement
fd
zoxide
bat
dust
ripgrep
fastfetch
wget
];
home.sessionVariables = {
EDITOR = "nvim";
};
programs.neovim.enable = true;
programs.neovim.defaultEditor = true;
}

View file

@ -0,0 +1,24 @@
{
pkgs,
config,
lib,
inputs,
...
}: {
imports = [];
home.packages = with pkgs; [
thunderbird
signal-desktop
keepassxc
];
programs.firefox = {
enable = true;
};
# TODO: fill this out (and move it in a service, probably)
# services.syncthing = {
# enable = true
# };
}

View file

@ -0,0 +1,15 @@
{
pkgs,
config,
lib,
inputs,
...
}: {
imports = [];
home.packages = with pkgs; [
freecad
prusa-slicer
printrun
];
}

47
modules/home/default.nix Normal file
View file

@ -0,0 +1,47 @@
{
pkgs,
system,
inputs,
config,
lib,
helperLib,
...
}: let
cfg = config.myHomeManager;
# # Taking all modules in ./features and adding enables to them
# features =
# helperLib.extendModules
# (name: {
# extraOptions = {
# myHomeManager.${name}.enable = lib.mkEnableOption "enable my ${name} configuration";
# };
#
# configExtension = config: (lib.mkIf cfg.${name}.enable config);
# })
# (helperLib.filesIn ./features);
#
# Taking all module bundles in ./bundles and adding bundle.enables to them
bundles =
helperLib.extendModules
(name: {
extraOptions = {
myHomeManager.bundles.${name}.enable = lib.mkEnableOption "enable ${name} module bundle";
};
configExtension = config: (lib.mkIf cfg.bundles.${name}.enable config);
})
(helperLib.filesIn ./bundles);
in {
imports = [
]
# ++ features
++ bundles
;
config = {
myHomeManager = {
bundles.core.enable = lib.mkDefault true;
};
};
}

View file

@ -0,0 +1,58 @@
{
pkgs,
lib,
...
}: {
boot.kernel.sysctl = {
"kernel.sysrq" = 502; # enables "REISUB"
};
services.xserver.xkb = lib.mkDefault {
layout = "de";
variant = "neo";
};
console.keyMap = lib.mkDefault "neo";
services.xserver.enable = true;
services.xserver.displayManager.sddm.enable = lib.mkDefault true;
services.desktopManager.plasma6.enable = lib.mkDefault true;
services.printing.enable = true;
# For touchscreen/pad support (supposedly)
services.xserver.libinput.enable = true;
# sound
sound.enable = true;
hardware.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
jack.enable = lib.mkDefault 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;
};
fonts.packages = with pkgs; [
nerdfonts
(pkgs.nerdfonts.override {fonts = ["JetBrainsMono" "Iosevka" "FiraCode"];})
cm_unicode
corefonts
];
fonts.enableDefaultPackages = true;
fonts.fontconfig = {
defaultFonts = {
monospace = ["JetBrainsMono Nerd Font Mono"];
sansSerif = ["JetBrainsMono Nerd Font"];
serif = ["JetBrainsMono Nerd Font"];
};
};
}

View file

@ -0,0 +1,60 @@
{
lib,
config,
inputs,
outputs,
helperLib,
pkgs,
...
}: let
cfg = config.myNixOS;
in {
options.myNixOS.home-users = lib.mkOption {
type = lib.types.attrsOf ( lib.types.submodule {
options = {
userConfig = lib.mkOption {
example = "home.nix";
};
userSettings = lib.mkOption {
default = {};
example = "{}";
};
};
});
default = {};
};
config = {
programs.zsh.enable = true;
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = {
inherit inputs;
inherit helperLib;
outputs = inputs.self.outputs;
};
users =
builtins.mapAttrs (name: user: {...}: {
imports = [
(import user.userConfig)
outputs.homeManagerModules.default
];
})
(config.myNixOS.home-users);
};
users.users = builtins.mapAttrs (
name: user:
{
isNormalUser = true;
shell = pkgs.zsh;
extraGroups = ["libvirtd" "networkmanager"];
}
// user.userSettings
) (config.myNixOS.home-users);
};
}

89
modules/nixOS/default.nix Normal file
View file

@ -0,0 +1,89 @@
{
pkgs,
config,
lib,
inputs,
outputs,
helperLib,
...
}: let
cfg = config.myNixOS;
# Taking all modules in ./features and adding enables to them
features =
helperLib.extendModules
(name: {
extraOptions = {
myNixOS.${name}.enable = lib.mkEnableOption "enable my ${name} configuration";
};
configExtension = config: (lib.mkIf cfg.${name}.enable config);
})
(helperLib.filesIn ./features);
# taking all module bundles in ./bundles and adding bundle.enables to them
bundles =
helperLib.extendModules
(name: {
extraOptions = {
myNixOS.bundles.${name}.enable = lib.mkEnableOption "enable ${name} module bundle";
};
configExtension = config: (lib.mkIf cfg.bundles.${name}.enable config);
})
(helperLib.filesIn ./bundles);
# taking all module services in ./services and adding service.enables to them
# services =
# helperLib.extendModules
# (name: {
# extraOptions = {
# myNixOS.services.${name}.enable = lib.mkEnableOption "enable ${name} module service";
# };
#
# configExtension = config: (lib.mkIf cfg.services.${name}.enable config);
# })
# (helperLib.filesIn ./services);
in {
imports =
[
inputs.home-manager.nixosModules.home-manager
]
++ features
++ bundles
# ++ services
;
options.myNixOS = {
sharedSettings = {
# put settings here that are shared between homemanager and nixos, e.g.
# hyprland.enable = lib.mkEnableOption "enable hyprland";
};
};
config = {
nix.settings.experimental-features = ["nix-command" "flakes"];
programs.nix-ld.enable = true;
nixpkgs.config.allowUnfree = lib.mkDefault true;
myNixOS = {
defaultLocale.enable = lib.mkDefault true;
bundles.users.enable = lib.mkDefault true;
};
};
}
# imports = [
# ./neo.nix
# ./locale.nix
# ./pipewire.nix
# ];
#
# locale.enable = lib.mkDefault true;
# neo.enable = lib.mkDefault true;
#
# pipewire.enable = lib.mkDefault true;
# pipewire.useJack = lib.mkDefault false;
# }

View file

@ -0,0 +1,19 @@
{ pkgs, lib, config, ...}: {
config = {
time.timeZone = lib.mkDefault "Europe/Berlin";
i18n.defaultLocale = lib.mkDefault "en_US.UTF-8";
i18n.extraLocaleSettings = lib.mkDefault {
LC_ADDRESS = "de_DE.UTF-8";
LC_IDENTIFICATION = "de_DE.UTF-8";
LC_MEASUREMENT = "de_DE.UTF-8";
LC_MONETARY = "de_DE.UTF-8";
LC_NAME = "de_DE.UTF-8";
LC_NUMERIC = "de_DE.UTF-8";
LC_PAPER = "de_DE.UTF-8";
LC_TELEPHONE = "de_DE.UTF-8";
LC_TIME = "de_DE.UTF-8";
};
};
}