8 Commits

Author SHA1 Message Date
1c7b7c4cae Add pi definition 2023-12-10 22:42:33 +00:00
aabecfd68f Merge branch 'master' into rpi 2023-12-10 20:19:13 +00:00
75506d5acd Disable onboard audio, support Digi Pro DAC 2023-12-08 23:22:40 +00:00
81a46270b8 Update zigbee2mqtt settings 2023-12-08 22:56:53 +00:00
18f1efdaff Merge branch 'master' into rpi 2023-12-08 22:43:35 +00:00
47c304833c flake.lock: Update
Flake lock file updates:

• Updated input 'nixos-hardware':
    'github:NixOS/nixos-hardware/a89745edd5f657e2e5be5ed1bea86725ca78d92e' (2023-12-03)
  → 'github:NixOS/nixos-hardware/fa194fc484fd7270ab324bb985593f71102e84d1' (2023-12-04)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/5de0b32be6e85dc1a9404c75131316e4ffbc634c' (2023-12-01)
  → 'github:NixOS/nixpkgs/933d7dc155096e7575d207be6fb7792bc9f34f6d' (2023-12-02)
2023-12-04 18:28:29 +00:00
f47fd2217e Add services to pi 2023-12-03 23:24:21 +00:00
4ad4814bed Initial pi config 2023-12-03 23:17:30 +00:00
49 changed files with 682 additions and 472 deletions

42
flake.lock generated
View File

@@ -100,6 +100,21 @@
"type": "github"
}
},
"nixos-hardware": {
"locked": {
"lastModified": 1701656485,
"narHash": "sha256-xDFormrGCKKGqngHa2Bz1GTeKlFMMjLnHhTDRdMJ1hs=",
"owner": "NixOS",
"repo": "nixos-hardware",
"rev": "fa194fc484fd7270ab324bb985593f71102e84d1",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixos-hardware",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1677676435,
@@ -118,11 +133,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1702233072,
"narHash": "sha256-H5G2wgbim2Ku6G6w+NSaQaauv6B6DlPhY9fMvArKqRo=",
"lastModified": 1701952659,
"narHash": "sha256-TJv2srXt6fYPUjxgLAL0cy4nuf1OZD4KuA1TrCiQqg0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "781e2a9797ecf0f146e81425c822dca69fe4a348",
"rev": "b4372c4924d9182034066c823df76d6eaf1f4ec4",
"type": "github"
},
"original": {
@@ -136,9 +151,9 @@
"agenix": "agenix",
"firefox-gnome-theme": "firefox-gnome-theme",
"home-manager": "home-manager_2",
"nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs_2",
"thunderbird-gnome-theme": "thunderbird-gnome-theme",
"wallpapers": "wallpapers"
"thunderbird-gnome-theme": "thunderbird-gnome-theme"
}
},
"thunderbird-gnome-theme": {
@@ -156,23 +171,6 @@
"repo": "thunderbird-gnome-theme",
"type": "github"
}
},
"wallpapers": {
"flake": false,
"locked": {
"lastModified": 1702336410,
"narHash": "sha256-DyC9Ro5tj3X0P2M24gZdpTkFGuZEy9JXrFLUav/b5H0=",
"ref": "refs/heads/master",
"rev": "dd78ed7242af54c33e8304feee322a71da575abd",
"shallow": true,
"type": "git",
"url": "ssh://git@git.vimium.com/jordan/wallpapers.git"
},
"original": {
"shallow": true,
"type": "git",
"url": "ssh://git@git.vimium.com/jordan/wallpapers.git"
}
}
},
"root": "root",

119
flake.nix
View File

@@ -3,6 +3,7 @@
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.11";
nixos-hardware.url = "github:NixOS/nixos-hardware";
agenix.url = "github:ryantm/agenix";
home-manager = {
url = "github:nix-community/home-manager/release-23.11";
@@ -16,55 +17,79 @@
url = "github:rafaelmardojai/thunderbird-gnome-theme";
flake = false;
};
wallpapers = {
url = "git+ssh://git@git.vimium.com/jordan/wallpapers.git?shallow=1";
flake = false;
};
};
outputs = inputs @ { self, nixpkgs, agenix, home-manager, ... }:
let
nixpkgsForSystem = system: inputs.nixpkgs;
overlays = [
agenix.overlays.default
(import ./overlays/gnome.nix)
];
commonModules = [
agenix.nixosModules.age
home-manager.nixosModule
./modules
];
nixosSystem = system: name:
let
nixpkgs = nixpkgsForSystem system;
lib = (import nixpkgs { inherit overlays system; }).lib;
in
inputs.nixpkgs.lib.nixosSystem {
inherit lib system;
specialArgs = { modulesPath = toString (nixpkgs + "/nixos/modules"); inherit inputs; };
baseModules = import (nixpkgs + "/nixos/modules/module-list.nix");
modules = commonModules ++ [
({ config, ... }:
{
nixpkgs.pkgs = import nixpkgs {
inherit overlays system;
config.allowUnfree = true;
};
networking.hostName = name;
nix = {
extraOptions = "experimental-features = nix-command flakes";
};
})
./hosts/${name}
];
};
nixosConfigurations = {
atlas = nixosSystem "x86_64-linux" "atlas";
eos = nixosSystem "x86_64-linux" "eos";
helios = nixosSystem "x86_64-linux" "helios";
odyssey = nixosSystem "x86_64-linux" "odyssey";
};
in
{ inherit nixosConfigurations; };
}
inherit (lib) attrValues;
inherit (lib.my) mapModules mapModulesRec;
system = "x86_64-linux";
mkPkgs = pkgs: extraOverlays:
import pkgs {
inherit system;
config.allowUnfree = true;
overlays = extraOverlays ++ (lib.attrValues self.overlays);
};
pkgs = mkPkgs nixpkgs [];
lib = nixpkgs.lib.extend (self: super: {
my = import ./lib {
inherit pkgs inputs;
lib = self;
};
});
in {
lib = lib.my;
nixosConfigurations = {
atlas = nixpkgs.lib.nixosSystem {
modules = [
home-manager.nixosModules.home-manager
{ nixpkgs.overlays = [ (import ./overlays/gnome.nix) ]; }
(import ./modules)
./hosts/atlas
];
specialArgs = { inherit lib inputs; };
};
eos = nixpkgs.lib.nixosSystem {
modules = [
home-manager.nixosModules.home-manager
{ nixpkgs.overlays = [ (import ./overlays/gnome.nix) ]; }
(import ./modules)
./hosts/eos
];
specialArgs = { inherit lib inputs; };
};
helios = nixpkgs.lib.nixosSystem {
modules = [
home-manager.nixosModules.home-manager
{ nixpkgs.overlays = [ (import ./overlays/gnome.nix) ]; }
(import ./modules)
./hosts/helios
];
specialArgs = { inherit lib inputs; };
};
odyssey = nixpkgs.lib.nixosSystem {
modules = [
home-manager.nixosModules.home-manager
agenix.nixosModules.default
{ nixpkgs.overlays = [ (import ./overlays/gnome.nix) ]; }
(import ./modules)
./hosts/odyssey
];
specialArgs = { inherit lib inputs; };
};
pi = nixpkgs.lib.nixosSystem {
modules = [
home-manager.nixosModules.home-manager
agenix.nixosModules.default
(import ./modules)
./hosts/pi
];
specialArgs = { inherit lib inputs; };
};
};
};
}

View File

@@ -1,5 +1,6 @@
{ config, lib, pkgs, ... }:
with lib.my;
{
imports = [
./hardware-configuration.nix

View File

@@ -1,66 +1,67 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
];
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
boot = {
initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ];
initrd.kernelModules = [ ];
initrd.supportedFilesystems = [ "zfs" ];
kernelModules = [ "kvm-intel" ];
kernelParams = [ "elevator=none" ];
extraModulePackages = [ ];
supportedFilesystems = [ "zfs" ];
};
boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ];
boot.initrd.kernelModules = [ ];
boot.initrd.supportedFilesystems = [ "zfs" ];
boot.kernelModules = [ "kvm-intel" ];
boot.kernelParams = [ "elevator=none" ];
boot.extraModulePackages = [ ];
boot.supportedFilesystems = [ "zfs" ];
fileSystems."/" = {
device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/" =
{ device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/home" = {
device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/home" =
{ device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/nix" = {
device = "rpool/local/nix";
fsType = "zfs";
};
fileSystems."/nix" =
{ device = "rpool/local/nix";
fsType = "zfs";
};
fileSystems."/tmp" = {
device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/tmp" =
{ device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/var" = {
device = "rpool/system/var";
fsType = "zfs";
};
fileSystems."/var" =
{ device = "rpool/system/var";
fsType = "zfs";
};
fileSystems."/var/log" = {
device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/log" =
{ device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/tmp" = {
device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/var/tmp" =
{ device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/boot" = {
device = "/dev/disk/by-uuid/00B2-0384";
fsType = "vfat";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/00B2-0384";
fsType = "vfat";
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.enp0s25.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View File

@@ -1,5 +1,7 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
{
time.timeZone = "Europe/London";

View File

@@ -1,5 +1,6 @@
{ config, lib, pkgs, ... }:
with lib.my;
{
imports = [
./hardware-configuration.nix

View File

@@ -1,65 +1,68 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
];
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
boot = {
initrd.availableKernelModules = [ "ehci_pci" "ahci" "usb_storage" "sd_mod" "sdhci_pci" ];
initrd.kernelModules = [ ];
initrd.supportedFilesystems = [ "zfs" ];
kernelModules = [ ];
kernelParams = [ "elevator=none" ];
extraModulePackages = [ ];
supportedFilesystems = [ "zfs" ];
};
boot.initrd.availableKernelModules = [ "ehci_pci" "ahci" "usb_storage" "sd_mod" "sdhci_pci" ];
boot.initrd.kernelModules = [ ];
boot.initrd.supportedFilesystems = [ "zfs" ];
boot.kernelModules = [ ];
boot.kernelParams = [ "elevator=none" ];
boot.extraModulePackages = [ ];
boot.supportedFilesystems = [ "zfs" ];
fileSystems."/" = {
device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/" =
{ device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/home" = {
device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/home" =
{ device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/nix" = {
device = "rpool/local/nix";
fsType = "zfs";
};
fileSystems."/nix" =
{ device = "rpool/local/nix";
fsType = "zfs";
};
fileSystems."/tmp" = {
device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/tmp" =
{ device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/var" = {
device = "rpool/system/var";
fsType = "zfs";
};
fileSystems."/var" =
{ device = "rpool/system/var";
fsType = "zfs";
};
fileSystems."/var/log" = {
device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/log" =
{ device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/tmp" = {
device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/var/tmp" =
{ device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/boot" = {
device = "/dev/disk/by-uuid/28E6-5509";
fsType = "vfat";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/28E6-5509";
fsType = "vfat";
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.enp0s25.useDHCP = lib.mkDefault true;
# networking.interfaces.wlp3s0.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View File

@@ -1,5 +1,6 @@
{ config, lib, pkgs, ... }:
with lib.my;
{
imports = [
./hardware-configuration.nix

View File

@@ -1,61 +1,62 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
];
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
boot = {
initrd.availableKernelModules = [ "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "sr_mod" "zfs" ];
initrd.kernelModules = [ ];
initrd.supportedFilesystems = [ "zfs" ];
kernelModules = [ "kvm-intel" ];
kernelParams = [ "elevator=none" ];
extraModulePackages = [ ];
supportedFilesystems = [ "zfs" ];
};
boot.initrd.availableKernelModules = [ "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "sr_mod" "zfs" ];
boot.initrd.kernelModules = [ ];
boot.initrd.supportedFilesystems = [ "zfs" ];
boot.kernelModules = [ "kvm-intel" ];
boot.kernelParams = [ "elevator=none" ];
boot.extraModulePackages = [ ];
boot.supportedFilesystems = [ "zfs" ];
fileSystems."/" = {
device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/" =
{ device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/home" = {
device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/home" =
{ device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/nix" = {
device = "rpool/local/nix";
fsType = "zfs";
};
fileSystems."/nix" =
{ device = "rpool/local/nix";
fsType = "zfs";
};
fileSystems."/tmp" = {
device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/tmp" =
{ device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/var/log" = {
device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/log" =
{ device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/tmp" = {
device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/var/tmp" =
{ device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/boot" = {
device = "/dev/sda1";
fsType = "ext2";
};
fileSystems."/boot" =
{ device = "/dev/sda1";
fsType = "ext2";
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.eno1.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View File

@@ -1,5 +1,6 @@
{ config, lib, pkgs, ... }:
with lib.my;
{
imports = [
./hardware-configuration.nix

View File

@@ -5,64 +5,63 @@
(modulesPath + "/installer/scan/not-detected.nix")
];
boot = {
initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "nvme" "usbhid" "usb_storage" "sd_mod" ];
initrd.kernelModules = [ ];
initrd.supportedFilesystems = [ "zfs" ];
kernelModules = [ "kvm-intel" ];
kernelPackages = pkgs.linuxPackages;
supportedFilesystems = [ "ntfs" ];
binfmt.emulatedSystems = [ "aarch64-linux" ];
};
boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "nvme" "usbhid" "usb_storage" "sd_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.kernelPackages = pkgs.linuxPackages;
boot.supportedFilesystems = [ "ntfs" ];
boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
hardware = {
cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
nvidia = {
modesetting.enable = true;
powerManagement.enable = true;
};
hardware.nvidia = {
modesetting.enable = true;
powerManagement.enable = true;
};
services.xserver.videoDrivers = [ "nvidia" ];
fileSystems."/" = {
device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/" =
{ device = "rpool/system/root";
fsType = "zfs";
};
fileSystems."/home" = {
device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/home" =
{ device = "rpool/user/home";
fsType = "zfs";
};
fileSystems."/var" = {
device = "rpool/system/var";
fsType = "zfs";
};
fileSystems."/var" =
{ device = "rpool/system/var";
fsType = "zfs";
};
fileSystems."/tmp" = {
device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/tmp" =
{ device = "rpool/local/tmp";
fsType = "zfs";
};
fileSystems."/var/log" = {
device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/log" =
{ device = "rpool/system/var/log";
fsType = "zfs";
};
fileSystems."/var/tmp" = {
device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/var/tmp" =
{ device = "rpool/system/var/tmp";
fsType = "zfs";
};
fileSystems."/boot" = {
device = "/dev/disk/by-uuid/E63E-8E75";
fsType = "vfat";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/E63E-8E75";
fsType = "vfat";
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.eno1.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

58
hosts/pi/default.nix Normal file
View File

@@ -0,0 +1,58 @@
{ config, lib, pkgs, ... }:
with lib.my;
{
imports = [
./hardware-configuration.nix
../server.nix
];
networking.hostName = "pi";
networking.hostId = "";
hardware = {
raspberry-pi."4" = {
apply-overlays-dtmerge.enable = true;
fkms-3d.enable = true;
};
deviceTree = {
enable = true;
filter = "*rpi-4-*.dtb";
};
};
sound.enable = true;
console.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
systemWide = true;
};
services.shairport-sync = {
enable = true;
group = [ "pipewire" ];
openFirewall = true;
};
services.zigbee2mqtt = {
enable = true;
settings = {
homeassistant = true;
frontend = true;
permit_join = true;
};
};
environment.systemPackages = with pkgs; [
libraspberrypi
raspberrypi-eeprom
];
system.stateVersion = "22.11";
}

View File

@@ -0,0 +1,21 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [
<nixos-hardware/raspberry-pi/4>
];
boot.loader.raspberryPi.firmwareConfig = ''
dtoverlay=vc4-kms-v3d,noaudio
dtoverlay=hifiberry-digi-pro
'';
fileSystems = {
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
options = [ "noatime" ];
};
};
}

View File

@@ -1,5 +1,7 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
{
time.timeZone = "Europe/London";

26
lib/attrs.nix Normal file
View File

@@ -0,0 +1,26 @@
{ lib, ... }:
with builtins;
with lib;
rec {
# attrsToList
attrsToList = attrs:
mapAttrsToList (name: value: { inherit name value; }) attrs;
# mapFilterAttrs ::
# (name -> value -> bool)
# (name -> value -> { name = any; value = any; })
# attrs
mapFilterAttrs = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs);
# Generate an attribute set by mapping a function over a list of values.
genAttrs' = values: f: listToAttrs (map f values);
# anyAttrs :: (name -> value -> bool) attrs
anyAttrs = pred: attrs:
any (attr: pred attr.name attr.value) (attrsToList attrs);
# countAttrs :: (name -> value -> bool) attrs
countAttrs = pred: attrs:
count (attr: pred attr.name attr.value) (attrsToList attrs);
}

19
lib/default.nix Normal file
View File

@@ -0,0 +1,19 @@
{ inputs, lib, pkgs, ... }:
let
inherit (lib) makeExtensible attrValues foldr;
inherit (modules) mapModules;
modules = import ./modules.nix {
inherit lib;
self.attrs = import ./attrs.nix { inherit lib; self = {}; };
};
mylib = makeExtensible (self:
with self; mapModules ./.
(file: import file { inherit self lib pkgs inputs; }));
in
mylib.extend
(self: super:
foldr (a: b: a // b) {} (attrValues super))

53
lib/modules.nix Normal file
View File

@@ -0,0 +1,53 @@
{ self, lib, ... }:
let
inherit (builtins) attrValues readDir pathExists concatLists;
inherit (lib) id mapAttrsToList filterAttrs hasPrefix hasSuffix nameValuePair removeSuffix;
inherit (self.attrs) mapFilterAttrs;
in
rec {
mapModules = dir: fn:
mapFilterAttrs
(n: v:
v != null &&
!(hasPrefix "_" n))
(n: v:
let path = "${toString dir}/${n}"; in
if v == "directory" && pathExists "${path}/default.nix"
then nameValuePair n (fn path)
else if v == "regular" &&
n != "default.nix" &&
hasSuffix ".nix" n
then nameValuePair (removeSuffix ".nix" n) (fn path)
else nameValuePair "" null)
(readDir dir);
mapModules' = dir: fn:
attrValues (mapModules dir fn);
mapModulesRec = dir: fn:
mapFilterAttrs
(n: v:
v != null &&
!(hasPrefix "_" n))
(n: v:
let path = "${toString dir}/${n}"; in
if v == "directory"
then nameValuePair n (mapModulesRec path fn)
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n
then nameValuePair (removeSuffix ".nix" n) (fn path)
else nameValuePair "" null)
(readDir dir);
mapModulesRec' = dir: fn:
let
dirs =
mapAttrsToList
(k: _: "${dir}/${k}")
(filterAttrs
(n: v: v == "directory" && !(hasPrefix "_" n))
(readDir dir));
files = attrValues (mapModules dir id);
paths = files ++ concatLists (map (d: mapModulesRec' d id) dirs);
in map fn paths;
}

25
lib/nixos.nix Normal file
View File

@@ -0,0 +1,25 @@
{ inputs, lib, pkgs, ... }:
with lib;
with lib.my;
let sys = "x86_64-linux";
in {
mkHost = path: attrs @ { system ? sys, ... }:
nixosSystem {
inherit system;
specialArgs = { inherit lib inputs system; };
modules = [
{
nixpkgs.pkgs = pkgs;
networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path));
}
(filterAttrs (n: v: !elem n [ "system" ]) attrs)
../. # /default.nix
(import path)
];
};
mapHosts = dir: attrs @ { system ? system, ... }:
mapModules dir
(hostPath: mkHost hostPath attrs);
}

35
lib/options.nix Normal file
View File

@@ -0,0 +1,35 @@
{ lib, ... }:
let
inherit (lib) mkOption types;
in
rec {
mkOpt = type: default:
mkOption { inherit type default; };
mkOpt' = type: default: description:
mkOption { inherit type default description; };
mkBoolOpt = default: mkOption {
inherit default;
type = types.bool;
example = true;
};
mkStringOpt = default: mkOption {
inherit default;
type = types.lines;
example = "";
};
mkListOfStringOpt = default: mkOption {
inherit default;
type = types.listOf types.lines;
example = [ "a" "b" "c" ];
};
mkPath = path:
if path != null
then toString path
else "";
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.apps.qbittorrent;
in {
options.modules.desktop.apps.qbittorrent = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
qbittorrent
];
};
}
}

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.apps.slack;
in {
options.modules.desktop.apps.slack = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
slack
];

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, inputs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.apps.thunderbird;
in {
options.modules.desktop.apps.thunderbird = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
home.file.".thunderbird/Default/chrome/thunderbird-gnome-theme".source = inputs.thunderbird-gnome-theme;
home.programs.thunderbird = {

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.apps.zoom;
in {
options.modules.desktop.apps.zoom = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
zoom-us
];

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, inputs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.browsers.firefox;
in {
options.modules.desktop.browsers.firefox = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
home.file.".mozilla/firefox/Default/chrome/firefox-gnome-theme".source = inputs.firefox-gnome-theme;
home.programs.firefox = {

View File

@@ -1,59 +1,34 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.gaming.emulators;
in {
options.modules.desktop.gaming.emulators = {
ds.enable = lib.mkOption {
default = false;
example = true;
};
gb.enable = lib.mkOption {
default = false;
example = true;
};
gba.enable = lib.mkOption {
default = false;
example = true;
};
gamecube.enable = lib.mkOption {
default = false;
example = true;
};
ps2.enable = lib.mkOption {
default = false;
example = true;
};
ps3.enable = lib.mkOption {
default = false;
example = true;
};
psp.enable = lib.mkOption {
default = false;
example = true;
};
snes.enable = lib.mkOption {
default = false;
example = true;
};
wii.enable = lib.mkOption {
default = false;
example = true;
};
ds.enable = mkBoolOpt false;
gb.enable = mkBoolOpt false;
gba.enable = mkBoolOpt false;
gamecube.enable = mkBoolOpt false;
ps2.enable = mkBoolOpt false;
ps3.enable = mkBoolOpt false;
psp.enable = mkBoolOpt false;
snes.enable = mkBoolOpt false;
wii.enable = mkBoolOpt false;
};
config = {
user.packages = with pkgs; [
(lib.mkIf cfg.ps2.enable pcsx2)
(lib.mkIf cfg.ps3.enable rpcs3)
(lib.mkIf cfg.psp.enable ppsspp)
(lib.mkIf cfg.ds.enable desmume)
(lib.mkIf (cfg.gba.enable ||
(mkIf cfg.ps2.enable pcsx2)
(mkIf cfg.ps3.enable rpcs3)
(mkIf cfg.psp.enable ppsspp)
(mkIf cfg.ds.enable desmume)
(mkIf (cfg.gba.enable ||
cfg.gb.enable ||
cfg.snes.enable)
higan)
(lib.mkIf (cfg.wii.enable ||
(mkIf (cfg.wii.enable ||
cfg.gamecube.enable)
dolphin-emu)
];
};
}
}

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.gaming.lutris;
in {
options.modules.desktop.gaming.lutris = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
lutris
vulkan-loader

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.gaming.steam;
in {
options.modules.desktop.gaming.steam = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
programs.steam.enable = true;
systemd.extraConfig = "DefaultLimitNOFILE=1048576";
};
}
}

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, inputs, ... }:
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.gnome;
in {
options.modules.desktop.gnome = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
services.xserver = {
enable = true;
displayManager.gdm.enable = true;
@@ -99,8 +98,8 @@ in {
window-gap = 8;
};
"org/gnome/desktop/background" = {
picture-uri = "file://${inputs.wallpapers}/Aqua.png";
picture-uri-dark = "file://${inputs.wallpapers}/Aqua.png";
picture-uri = "file://${pkgs.gnome.gnome-backgrounds}/share/backgrounds/gnome/adwaita-l.jpg";
picture-uri-dark = "file://${pkgs.gnome.gnome-backgrounds}/share/backgrounds/gnome/adwaita-d.jpg";
};
"org/gtk/settings/file-chooser" = {
show-hidden = true;

View File

@@ -1,28 +1,21 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.media.graphics;
in {
options.modules.desktop.media.graphics = {
modeling.enable = lib.mkOption {
default = false;
example = true;
};
raster.enable = lib.mkOption {
default = false;
example = true;
};
vector.enable = lib.mkOption {
default = false;
example = true;
};
modeling.enable = mkBoolOpt false;
raster.enable = mkBoolOpt false;
vector.enable = mkBoolOpt false;
};
config = {
user.packages = with pkgs; [
(lib.mkIf cfg.modeling.enable blender)
(lib.mkIf cfg.raster.enable gimp)
(lib.mkIf cfg.raster.enable krita)
(lib.mkIf cfg.vector.enable inkscape)
(mkIf cfg.modeling.enable blender)
(mkIf cfg.raster.enable gimp)
(mkIf cfg.raster.enable krita)
(mkIf cfg.vector.enable inkscape)
];
};
}
}

View File

@@ -1,16 +1,12 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.media.recording;
in {
options.modules.desktop.media.recording = {
audio.enable = lib.mkOption {
default = false;
example = true;
};
video.enable = lib.mkOption {
default = false;
example = true;
};
audio.enable = mkBoolOpt false;
video.enable = mkBoolOpt false;
};
config = {
@@ -25,4 +21,4 @@ in {
obs-studio
] else []);
};
}
}

View File

@@ -1,18 +1,17 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let
cfg = config.modules.desktop.mimeapps;
avApp = "io.github.celluloid_player.Celluloid.desktop";
imageApp = "org.gnome.eog.desktop";
in {
options.modules.desktop.mimeapps = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
xdg.mime.defaultApplications = {
# Audio/video
"audio/x-vorbis+ogg" = avApp;

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.desktop.office.libreoffice;
in {
options.modules.desktop.office.libreoffice = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
libreoffice
];

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.cc;
in {
options.modules.dev.cc = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
clang
gcc
@@ -18,4 +17,4 @@ in {
llvmPackages.libcxx
];
};
}
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.java;
in {
options.modules.dev.java = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
jdk
];
};
}
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.lua;
in {
options.modules.dev.lua = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
lua
];
};
}
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.node;
in {
options.modules.dev.node = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
nodejs_latest
];
};
}
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.python;
in {
options.modules.dev.python = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
python310
];
};
}
}

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.rust;
in {
options.modules.dev.rust = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
rustc
rustup
@@ -17,4 +16,4 @@ in {
rust-bindgen
];
};
}
}

View File

@@ -1,19 +1,18 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.scala;
in {
options.modules.dev.scala = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
jdk
sbt
scala
];
};
}
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.shell;
in {
options.modules.dev.shell = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
shellcheck
];
};
}
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.dev.zig;
in {
options.modules.dev.zig = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
zig
];
};
}
}

View File

@@ -1,17 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let
cfg = config.modules.editors.neovim;
dev = config.modules.dev;
in {
options.modules.editors.neovim = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
user.packages = with pkgs; [
(neovim.override {
configure = {

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.editors.vscode;
in {
options.modules.editors.vscode = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
environment.sessionVariables.NIXOS_OZONE_WL = "1";
home.programs.vscode = {

View File

@@ -1,19 +1,15 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.networking.tailscale;
in {
options.modules.networking.tailscale = {
enable = lib.mkOption {
default = false;
example = true;
};
restrictSSH = lib.mkOption {
default = true;
example = true;
};
enable = mkBoolOpt false;
restrictSSH = mkBoolOpt true;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
services.tailscale.enable = true;
services.openssh.openFirewall = !cfg.restrictSSH;
networking.firewall = {

View File

@@ -1,20 +1,21 @@
{ config, options, lib, home-manager, ... }:
with lib;
with lib.my;
{
options = with types; {
user = mkOption { type = attrs; default = { }; };
user = mkOpt attrs { };
home = {
configFile = mkOption { type = attrs; default = { }; description = "Files to place in $XDG_CONFIG_HOME"; };
dataFile = mkOption { type = attrs; default = { }; description = "Files to place in $XDG_DATA_HOME"; };
file = mkOption { type = attrs; default = { }; description = "Files to place directly in $HOME"; };
packages = mkOption { type = attrs; default = { }; description = "User-level installed packages"; };
programs = mkOption { type = attrs; default = { }; description = "Programs managed directly from home-manager"; };
services = mkOption { type = attrs; default = { }; description = "Services managed directly from home-manager"; };
configFile = mkOpt' attrs { } "Files to place in $XDG_CONFIG_HOME";
dataFile = mkOpt' attrs { } "Files to place in $XDG_DATA_HOME";
file = mkOpt' attrs { } "Files to place directly in $HOME";
packages = mkOpt' attrs { } "User-level installed packages";
programs = mkOpt' attrs { } "Programs managed directly from home-manager";
services = mkOpt' attrs { } "Services managed directly from home-manager";
};
dconf.settings = mkOption { type = attrs; default = { }; description = "dconf settings to enable"; };
dconf.settings = mkOpt' attrs { } "dconf settings to enable";
env = mkOption {
type = attrsOf (oneOf [ str path (listOf (either str path)) ]);
@@ -68,6 +69,8 @@ with lib;
users.users.${config.user.name} = mkAliasDefinitions options.user;
nixpkgs.config.allowUnfree = true;
environment.extraInit =
concatStringsSep "\n"
(mapAttrsToList (n: v: "export ${n}=\"${v}\"") config.env);

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.security.gpg;
in {
options.modules.security.gpg = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
home.programs.gpg = {
enable = true;
};
@@ -19,4 +18,4 @@ in {
enableSshSupport = true;
};
};
}
}

View File

@@ -1,18 +1,17 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.security.pass;
in {
options.modules.security.pass = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
home.programs.password-store = {
enable = true;
package = pkgs.pass.withExtensions (exts: [ exts.pass-otp ]);
};
};
}
}

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.shell.git;
in {
options.modules.shell.git = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
home.programs.git = {
enable = true;
aliases = {
@@ -36,4 +35,4 @@ in {
"git/ignore".source = ./ignore;
};
};
}
}

View File

@@ -1,15 +1,14 @@
{ config, lib, pkgs, ... }:
with lib;
with lib.my;
let cfg = config.modules.shell.zsh;
in {
options.modules.shell.zsh = {
enable = lib.mkOption {
default = false;
example = true;
};
enable = mkBoolOpt false;
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
users.defaultUserShell = pkgs.zsh;
programs.zsh = {