From 74424799482a17883c93d74197454b4e6a0ce18c Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 28 Feb 2024 09:31:58 -0600 Subject: [PATCH] Add nix-flake template --- flake.nix | 5 +- nixos/default.nix | 62 ++++++--- nixos/htpc.nix | 147 ---------------------- nixos/htpifour.nix | 138 ++++++++++++++++++++ templates/all.nix | 4 + templates/nix-flake/.helix/languages.toml | 9 ++ templates/nix-flake/flake.nix | 51 ++++++++ 7 files changed, 247 insertions(+), 169 deletions(-) delete mode 100644 nixos/htpc.nix create mode 100644 nixos/htpifour.nix create mode 100644 templates/nix-flake/.helix/languages.toml create mode 100644 templates/nix-flake/flake.nix diff --git a/flake.nix b/flake.nix index 668a925..ca314a1 100644 --- a/flake.nix +++ b/flake.nix @@ -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; diff --git a/nixos/default.nix b/nixos/default.nix index 1ccd7d1..b6027a4 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -1,20 +1,42 @@ -with builtins; (listToAttrs (map (name: { - name = name; - value = { - system = "x86_64-linux"; - specialArgs = { - }; - modules = [./${name}.nix]; - }; - }) [ - "base" - "htpc" - "beefcake" - "dragon" - "foxtrot" - "musicbox" - "rascal" - "router" - "thablet" - "thinker" - ])) +{ + base = { + system = "x86_64-linux"; + modules = [./base.nix]; + }; + beefcake = { + system = "x86_64-linux"; + modules = [./beefcake.nix]; + }; + 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]; + }; +} diff --git a/nixos/htpc.nix b/nixos/htpc.nix deleted file mode 100644 index 205ab32..0000000 --- a/nixos/htpc.nix +++ /dev/null @@ -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"; -} diff --git a/nixos/htpifour.nix b/nixos/htpifour.nix new file mode 100644 index 0000000..28887bb --- /dev/null +++ b/nixos/htpifour.nix @@ -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"; +} diff --git a/templates/all.nix b/templates/all.nix index a6a33a7..c45bf58 100644 --- a/templates/all.nix +++ b/templates/all.nix @@ -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"; diff --git a/templates/nix-flake/.helix/languages.toml b/templates/nix-flake/.helix/languages.toml new file mode 100644 index 0000000..55c2894 --- /dev/null +++ b/templates/nix-flake/.helix/languages.toml @@ -0,0 +1,9 @@ +[[language]] +auto-format = true +file-types = ["nix"] +name = "nix" +scope = "source.nix" + +[language.formatter] +args = ["-"] +command = "alejandra" diff --git a/templates/nix-flake/flake.nix b/templates/nix-flake/flake.nix new file mode 100644 index 0000000..6eed4f0 --- /dev/null +++ b/templates/nix-flake/flake.nix @@ -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; + }; +}