flakes: Migrate the config and miku to flakes

This commit is contained in:
2021-11-01 21:33:21 +01:00
parent 09d385806a
commit 1d8f2f8053
64 changed files with 2612 additions and 1739 deletions

179
lib/baseSystem.nix Normal file
View File

@@ -0,0 +1,179 @@
{ config, pkgs, lib, ... }:
let
network = import ./network.nix;
isVM = config.ptw.system.isVM;
wireless = config.ptw.system.wireless;
in {
time.timeZone = "Europe/Berlin";
ostylk.nftables = {
enable = true;
tables.firewall = {
family = "inet";
chains = {
non-libvirt.extraConfig = let
deviceIPString = lib.concatStringsSep "," (with network; [
miku nishimiya tamaki mashu # ayame
]);
in ''
# Accept traffic from my devices
ip saddr != { ${deviceIPString} } drop
'';
input.extraConfig = ''
type filter hook input priority 0
ct state { established, related } accept
iif lo accept
# TODO
#iif {primaryInterfaceWrapper} goto non-libvirt
'';
};
};
};
networking = {
useDHCP = false; # Done by the network manager
networkmanager.enable = false;
#interfaces.*.useDHCP = false;
hostName = config.ptw.system.hostName;
wireless.enable = (if wireless then true else lib.mkForce false);
hosts = lib.mkIf (!isVM) {
"${network.miku}" = [ "miku.local" ];
"${network.nishimiya}" = [ "nishimiya.local" ];
#"${network.ayame}" = [ "ayame.local" ];
"${network.tamaki}" = [ "tamaki.local" ];
"${network.mashu}" = [ "mashu.local" ];
};
};
i18n.defaultLocale = "en_GB.UTF-8";
console = {
font = "Lat2-Terminus16";
keyMap = "de";
};
users = {
mutableUsers = false;
extraUsers = {
root = {
# Disable root login
hashedPassword = "*";
};
};
};
environment = {
systemPackages = with pkgs; [
htop
vim
git # Otherwise we cannot install home-manager
git-crypt
gnupg
python3
# RT scheduling
rtkit
] ++ lib.optionals (!isVM) (with pkgs; [ gopass ]);
sessionVariables = {
# Prevent us from having to always type it out
NIXOS_CONFIG = "/home/${config.ptw.system.singleUser}/Development/Personal/nixos-config/hosts/${config.networking.hostName}.nix";
};
};
fonts.fonts = with pkgs; [
# CJK fonts
source-han-sans source-han-serif
# Coding fonts
source-code-pro
# Icon fonts
nerdfonts
];
# We don't tolerate non-free software, except for Steam and Linux firmware
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"firmwareLinuxNonfree" "microcodeAmd" "microcodeIntel"
"steam" "steam-original" "steam-runtime"
"discord"
];
services = {
connman.enable = true;
# TODO: Is this correct? Maybe run once
timesyncd.enable = false;
# Everyone needs sound
pipewire = {
enable = true;
pulse.enable = true;
jack.enable = true;
alsa.enable = true;
alsa.support32Bit = true;
};
# On desktop: Monitor keyboards, mice, ...
# On portable devices: Monitor their battery
upower.enable = true;
# What generated entropy?
haveged.enable = true;
printing.enable = lib.mkDefault false;
avahi.enable = false;
# For debugging.
# TODO: Lock to known IPs and keys
sshd.enable = true;
# Prevent unexpected OOM situations with heavy swapping
earlyoom = {
enable = true;
enableNotifications = true;
};
};
# Don't wait for a network connection
systemd.services.NetworkManager-wait-online.enable = false;
security.sudo.extraConfig = ''
Defaults env_keep += "NIXOS_CONFIG"
'';
hardware = {
enableRedistributableFirmware = true;
# This is a Pipewire household!
pulseaudio.enable = false;
opengl = {
enable = true;
driSupport32Bit = true;
driSupport = true;
extraPackages = with pkgs; [ vaapiVdpau libvdpau-va-gl ];
};
# Only a subset of my devices have bluetooth
bluetooth = lib.mkIf wireless {
enable = true;
};
} // (if wireless then {
wifiInterface = config.ptw.system.wifiInterface;
} else {});
nix.package = pkgs.nixUnstable;
nix.extraOptions = ''
experimental-features = nix-command flakes ca-references
'';
boot = {
loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
};
system.stateVersion = "21.05";
}

22
lib/default.nix Normal file
View File

@@ -0,0 +1,22 @@
{ inputs, config, lib, ... }:
{
# Creates an overlay from a given input
mkOverlayFromInput = name: input: {
nixpkgs.overlays = [
(final: prev:
prev.lib.attrsets.setAttrByPath [ name ] (
import input {
system = prev.system;
overlays = [ inputs.self.overlay ];
#config = config.nixpkgs.config;
}
))
];
};
mkSystem = import ./mkSystem.nix {
inherit inputs config lib;
};
network = import ./network.nix;
}

7
lib/flake.nix Normal file
View File

@@ -0,0 +1,7 @@
{ flake-utils, lib }:
let
defaultLinuxSystems = lib.filter (system: lib.strings.hasSuffix "-linux" system) flake-utils.lib.defaultSystems;
in {
eachDefaultLinuxSystem = arg: flake-utils.lib.eachSystem defaultLinuxSystems arg;
}

45
lib/helpers/kanshi.nix Normal file
View File

@@ -0,0 +1,45 @@
{
mkWallpaperScript = { pkgs, config }: let
wallpapers = "/home/${config.ptw.system.singleUser}/Data/Wallpaper";
wallpapersHorizontal = "${wallpapers}/horizontal";
wallpapersVertical = "${wallpapers}/vertical";
in pkgs.writeShellScript "wallpaper.sh" ''
set -x
[[ $# -lt 1 ]] && echo "No profile specified" && exit 1
random_file() {
find "$1" -maxdepth 1 -type f | shuf -n 1
}
setbg() {
# Sets the background of $1 to $2
swaymsg "output \"$1\" background $2 fill"
}
case $1 in
homeMultihead)
horiz=$(random_file ${wallpapersHorizontal})
vert=$(random_file ${wallpapersVertical})
setbg "DP-2" $horiz
setbg "HDMI-A-3" $vert
;;
genericMultihead)
horiz1=$(random_file ${wallpapersHorizontal})
horiz2=$(random_file ${wallpapersHorizontal})
setbg "eDP-1" $horiz1
setbg "HDMI-A-1" $horiz2
;;
laptop)
horiz=$(random_file ${wallpapersHorizontal})
setbg "eDP-1" $horiz
;;
esac
'';
mkProfile = { script, name, outputs }: {
outputs = outputs;
exec = "${script} ${name}";
};
}

48
lib/mkSystem.nix Normal file
View File

@@ -0,0 +1,48 @@
{ inputs, config, lib, nur, emacs, ... }:
{
hostConfigFile
, architecture ? "x86_64-linux"
}: let
pkgs = inputs.nixpkgs;
config = pkgs.lib;
network = import ./network.nix;
util = import ./default.nix {
inherit inputs config lib;
};
#primaryInterfaceWrapper = if wifiInterface != "" && primaryInterface == "" then wifiInterface else primaryInterface;
in inputs.nixpkgs.lib.nixosSystem {
system = architecture;
modules = [
inputs.home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
}
(util.mkOverlayFromInput "stable" inputs.stable)
(util.mkOverlayFromInput "unstable" inputs.nixpkgs)
{
nixpkgs.overlays = [
nur.overlay
emacs.overlay
(import ../packages)
];
}
(import ../modules)
inputs.ostylk.nixosModules.nftables
(import ./baseSystem.nix)
(import hostConfigFile)
#(extraOptions baseConfig)
];
specialArgs = {
inherit inputs;
};
}

10
lib/network.nix Normal file
View File

@@ -0,0 +1,10 @@
rec {
network-base = "192.168.178";
# A collection of IP addresses for various uses
miku = "${network-base}.38";
nishimiya = "${network-base}.21";
#ayame = "${network-base}.35"; # TODO: That one's wrong
tamaki = "${network-base}.27";
mashu = "${network-base}.52"; # TODO: That's wrong
}