Add nix-flake template

This commit is contained in:
Daniel Flanagan 2024-02-28 09:31:58 -06:00
parent 5dc4873036
commit 7442479948
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
7 changed files with 247 additions and 169 deletions

View file

@ -4,7 +4,7 @@
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
pre-commit-hooks.inputs.nixpkgs-unstable.follows = "nixpkgs";
# pre-commit-hooks.inputs.nixpkgs-unstable.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager/master";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
@ -41,6 +41,7 @@
self,
nixpkgs,
home-manager,
hardware,
pre-commit-hooks,
api-lyte-dev,
...
@ -107,7 +108,7 @@
nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = {
inherit inputs outputs system api-lyte-dev;
inherit inputs outputs system api-lyte-dev hardware;
};
# extraSpecialArgs = {
# inherit inputs outputs system api-lyte-dev;

View file

@ -1,20 +1,42 @@
with builtins; (listToAttrs (map (name: {
name = name;
value = {
{
base = {
system = "x86_64-linux";
specialArgs = {
modules = [./base.nix];
};
modules = [./${name}.nix];
beefcake = {
system = "x86_64-linux";
modules = [./beefcake.nix];
};
}) [
"base"
"htpc"
"beefcake"
"dragon"
"foxtrot"
"musicbox"
"rascal"
"router"
"thablet"
"thinker"
]))
dragon = {
system = "x86_64-linux";
modules = [./dragon.nix];
};
foxtrot = {
system = "x86_64-linux";
modules = [./foxtrot.nix];
};
musicbox = {
system = "x86_64-linux";
modules = [./musicbox.nix];
};
rascal = {
system = "x86_64-linux";
modules = [./rascal.nix];
};
router = {
system = "x86_64-linux";
modules = [./router.nix];
};
thablet = {
system = "x86_64-linux";
modules = [./thablet.nix];
};
thinker = {
system = "x86_64-linux";
modules = [./thinker.nix];
};
htpifour = {
system = "aarch64-linux";
modules = [./htpifour.nix];
};
}

View file

@ -1,147 +0,0 @@
{
pkgs,
lib,
inputs,
outputs,
modulesPath,
...
}: {
nixpkgs.hostPlatform = "x86_64-linux";
networking.hostName = "htpc";
imports = with outputs.nixosModules; [
(modulesPath + "/installer/scan/not-detected.nix")
inputs.hardware.nixosModules.raspberry-pi-4
# inputs.hardware.nixosModules.common-cpu-intel-kaby-lake
# inputs.hardware.nixosModules.common-pc-ssd
# inputs.hardware.nixosModules.common-pc
desktop-usage
gnome
wifi
flanfam
flanfamkiosk
];
hardware = {
raspberry-pi."4".apply-overlays-dtmerge.enable = true;
deviceTree = {
enable = true;
filter = "*rpi-4-*.dtb";
};
};
console.enable = false;
services.gnome.gnome-remote-desktop.enable = true;
networking.networkmanager.enable = true;
home-manager.users.daniel = {
imports = with outputs.homeManagerModules; [linux-desktop];
};
environment.systemPackages = with pkgs;
#with pkgs;
[
libcec
variety
libraspberrypi
raspberrypi-eeprom
];
programs.steam.enable = true;
programs.steam.remotePlay.openFirewall = true;
services.xserver = {
enable = true;
displayManager = {
# lightdm.enable = true;
autoLogin.enable = true;
autoLogin.user = "daniel";
};
desktopManager.gnome.enable = true;
videoDrivers = ["fbdev"];
};
hardware.raspberry-pi."4".fkms-3d.enable = true;
hardware.raspberry-pi."4".audio.enable = true;
nixpkgs.overlays = [
# nixos-22.05
# (self: super: { libcec = super.libcec.override { inherit (self) libraspberrypi; }; })
# nixos-22.11
(self: super: {libcec = super.libcec.override {withLibraspberrypi = true;};})
];
# 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;
# hardware
systemd.targets.sleep.enable = false;
systemd.targets.suspend.enable = false;
systemd.targets.hibernate.enable = false;
systemd.targets.hybrid-sleep.enable = false;
powerManagement.enable = false;
# boot.loader.grub.enable = true;
boot.loader.grub.device = "/dev/sda";
boot.initrd.availableKernelModules = ["xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "sdhci_pci"];
boot.initrd.kernelModules = [];
boot.kernelModules = [
# "kvm-intel"
];
boot.extraModulePackages = [];
fileSystems."/" = {
device = "/dev/disk/by-uuid/0f4e5814-0002-43f0-bfab-8368e3fe5b8a";
fsType = "ext4";
};
networking = {
# useDHCP = true;
firewall = {
enable = true;
allowPing = true;
allowedTCPPorts = [22 5900];
allowedUDPPorts = [5900];
};
};
services.udev.extraRules = ''
# allow access to raspi cec device for video group (and optionally register it as a systemd device, used below)
SUBSYSTEM=="vchiq", GROUP="video", MODE="0660", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/dev/vchiq"
'';
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
# optional: attach a persisted cec-client to `/run/cec.fifo`, to avoid the CEC ~1s startup delay per command
# scan for devices: `echo 'scan' > /run/cec.fifo ; journalctl -u cec-client.service`
# set pi as active source: `echo 'as' > /run/cec.fifo`
systemd.sockets."cec-client" = {
after = ["dev-vchiq.device"];
bindsTo = ["dev-vchiq.device"];
wantedBy = ["sockets.target"];
socketConfig = {
ListenFIFO = "/run/cec.fifo";
SocketGroup = "video";
SocketMode = "0660";
};
};
systemd.services."cec-client" = {
after = ["dev-vchiq.device"];
bindsTo = ["dev-vchiq.device"];
wantedBy = ["multi-user.target"];
serviceConfig = {
ExecStart = ''${pkgs.libcec}/bin/cec-client -d 1'';
ExecStop = ''/bin/sh -c "echo q > /run/cec.fifo"'';
StandardInput = "socket";
StandardOutput = "journal";
Restart = "no";
};
};
system.stateVersion = "23.11";
}

138
nixos/htpifour.nix Normal file
View file

@ -0,0 +1,138 @@
{
pkgs,
lib,
hardware,
outputs,
modulesPath,
...
}: {
nixpkgs.hostPlatform = "aarch64-linux";
networking.hostName = "htpifour";
imports = with outputs.nixosModules; [
(modulesPath + "/installer/scan/not-detected.nix")
hardware.nixosModules.raspberry-pi-4
outputs.diskoConfigurations.unencrypted
desktop-usage
# gnome
kde-plasma
wifi
flanfam
flanfamkiosk
];
hardware = {
raspberry-pi."4".apply-overlays-dtmerge.enable = true;
deviceTree = {
enable = true;
filter = "*rpi-4-*.dtb";
};
};
console.enable = false;
home-manager.users.daniel = {
imports = with outputs.homeManagerModules; [linux-desktop wallpaper-manager];
};
environment.systemPackages = with pkgs;
#with pkgs;
[
# libcec
libraspberrypi
raspberrypi-eeprom
];
programs.steam.enable = true;
programs.steam.remotePlay.openFirewall = true;
services.xserver = {
displayManager = {
# lightdm.enable = true;
autoLogin.enable = true;
autoLogin.user = "daniel";
};
# videoDrivers = ["fbdev"];
};
hardware.raspberry-pi."4".fkms-3d.enable = true;
hardware.raspberry-pi."4".audio.enable = true;
nixpkgs.overlays = [
# nixos-22.05
# (self: super: { libcec = super.libcec.override { inherit (self) libraspberrypi; }; })
# nixos-22.11
# (self: super: {libcec = super.libcec.override {withLibraspberrypi = true;};})
];
# 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;
# hardware
systemd.targets.sleep.enable = false;
systemd.targets.suspend.enable = false;
systemd.targets.hibernate.enable = false;
systemd.targets.hybrid-sleep.enable = false;
powerManagement.enable = false;
boot = {
kernelPackages = pkgs.linuxKernel.packages.linux_rpi4;
initrd.availableKernelModules = ["xhci_pci" "usbhid" "usb_storage"];
loader = {
grub.enable = false;
generic-extlinux-compatible.enable = true;
};
};
networking = {
networkmanager.enable = true;
# useDHCP = true;
firewall = {
enable = true;
allowPing = true;
allowedTCPPorts = [
22 # ssh
];
allowedUDPPorts = [];
};
};
# services.udev.extraRules = ''
# # allow access to raspi cec device for video group (and optionally register it as a systemd device, used below)
# SUBSYSTEM=="vchiq", GROUP="video", MODE="0660", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/dev/vchiq"
# '';
# powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
# optional: attach a persisted cec-client to `/run/cec.fifo`, to avoid the CEC ~1s startup delay per command
# scan for devices: `echo 'scan' > /run/cec.fifo ; journalctl -u cec-client.service`
# set pi as active source: `echo 'as' > /run/cec.fifo`
# systemd.sockets."cec-client" = {
# after = ["dev-vchiq.device"];
# bindsTo = ["dev-vchiq.device"];
# wantedBy = ["sockets.target"];
# socketConfig = {
# ListenFIFO = "/run/cec.fifo";
# SocketGroup = "video";
# SocketMode = "0660";
# };
# };
# systemd.services."cec-client" = {
# after = ["dev-vchiq.device"];
# bindsTo = ["dev-vchiq.device"];
# wantedBy = ["multi-user.target"];
# serviceConfig = {
# ExecStart = ''${pkgs.libcec}/bin/cec-client -d 1'';
# ExecStop = ''/bin/sh -c "echo q > /run/cec.fifo"'';
# StandardInput = "socket";
# StandardOutput = "journal";
# Restart = "no";
# };
# };
hardware.opengl.driSupport32Bit = lib.mkForce false;
system.stateVersion = "24.05";
}

View file

@ -3,6 +3,10 @@
path = ./rust;
description = "A template for working on a Rust project";
};
nix-flake = {
path = ./nix-flake;
description = "A template for working on a Nix flake";
};
deno = {
path = ./deno;
description = "A template for working on a TypeScript and Deno project";

View file

@ -0,0 +1,9 @@
[[language]]
auto-format = true
file-types = ["nix"]
name = "nix"
scope = "source.nix"
[language.formatter]
args = ["-"]
command = "alejandra"

View file

@ -0,0 +1,51 @@
{
inputs = {
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
pre-commit-hooks,
...
}: let
inherit (self) outputs;
systems = [
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs systems;
in {
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
checks = forAllSystems (system: {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
};
};
});
devShell = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.mkShell {
buildInputs = with pkgs; [nil];
inherit (outputs.checks.${system}.pre-commit-check) shellHook;
});
# packages = forAllSystems (system: import ./pkgs {pkgs = nixpkgs.legacyPackages.${system};});
# overlays = import ./overlays self;
# nixosModules = import ./modules/nixos;
# homeManagerModules = import ./modules/home-manager;
# nixosConfigurations = import ./nixos;
# homeConfigurations = import ./home
# templates = import ./templates;
};
}