From 4298f9dc77791ff5b8080079e1211a1803cc3900 Mon Sep 17 00:00:00 2001 From: Alexander Szczepanski Date: Fri, 30 Aug 2024 13:22:30 +0200 Subject: [PATCH] desktop-2024-08-30-13-22-30 --- configs/browser.nix | 5 +-- configs/common.nix | 5 +-- configs/games.nix | 29 +++++------- configs/libvirt.nix | 5 +-- configs/user-gui.nix | 13 +++--- configs/user.nix | 25 +++++------ flake.lock | 39 +++++++++++++++++ flake.nix | 41 ++++++++++------- machine/desktop-hardware-configuration.nix | 39 +++++++++++++++++ machine/desktop.nix | 51 ++++++++++++++-------- overlays/default.nix | 23 ++++++++++ pkgs/default.nix | 5 +++ 12 files changed, 198 insertions(+), 82 deletions(-) create mode 100644 machine/desktop-hardware-configuration.nix create mode 100644 overlays/default.nix create mode 100644 pkgs/default.nix diff --git a/configs/browser.nix b/configs/browser.nix index b88ea6d..0b0c6f2 100755 --- a/configs/browser.nix +++ b/configs/browser.nix @@ -1,9 +1,6 @@ { config, pkgs, lib, ... }: -let - unstable = import { config.allowUnfree = true; }; -in { - environment.systemPackages = with unstable.pkgs; [ + environment.systemPackages = with pkgs.unstable; [ brave chromium firefox diff --git a/configs/common.nix b/configs/common.nix index ead0ad1..faf0569 100755 --- a/configs/common.nix +++ b/configs/common.nix @@ -1,7 +1,4 @@ { config, pkgs, lib, ... }: -let - unstable = import {}; -in { environment.shells = with pkgs; [ bashInteractive zsh ]; @@ -61,7 +58,7 @@ in networkmanager.dns = "none"; }; - environment.systemPackages = with unstable.pkgs; [ + environment.systemPackages = with pkgs.unstable; [ ack borgbackup borgmatic diff --git a/configs/games.nix b/configs/games.nix index 20967bc..ad6df3c 100755 --- a/configs/games.nix +++ b/configs/games.nix @@ -1,10 +1,4 @@ -{ config, pkgs, lib, ... }: -let - unstable = import { - config.allowUnfree = true; - }; - nix-gaming = import (builtins.fetchTarball "https://github.com/fufexan/nix-gaming/archive/master.tar.gz"); -in +{ config, pkgs, lib, outputs, ... }: { programs = { gamescope = { @@ -13,22 +7,23 @@ in }; steam = { enable = true; - package = unstable.pkgs.steam.override { - extraPkgs = pkgs: with unstable.pkgs; [ - gamescope - mangohud - libkrb5 - keyutils + package = pkgs.unstable.steam.override { + extraPkgs = pkgs: [ + pkgs.gamescope + pkgs.mangohud + # libkrb5 + # keyutils ]; }; }; }; - environment.systemPackages = with unstable.pkgs; [ + environment.systemPackages = with pkgs.unstable; [ (lutris.override { - extraPkgs = pkgs: with unstable.pkgs; [ - gamescope mangohud - ]; + extraPkgs = pkgs: [ + pkgs.gamescope + pkgs.mangohud + ]; }) heroic diff --git a/configs/libvirt.nix b/configs/libvirt.nix index e4c7083..9824e92 100755 --- a/configs/libvirt.nix +++ b/configs/libvirt.nix @@ -1,7 +1,4 @@ -{ config, pkgs, lib, ... }: -# let -# unstable = import { config.allowUnfree = true; }; -# in +{ pkgs, ... }: { virtualisation = { libvirtd = { diff --git a/configs/user-gui.nix b/configs/user-gui.nix index 619b8c2..8be95bb 100755 --- a/configs/user-gui.nix +++ b/configs/user-gui.nix @@ -1,7 +1,6 @@ -{ config, pkgs, lib, ... }: -let unstable = import { config.allowUnfree = true; }; -in { - imports = [ ]; +{ config, pkgs, inputs, home-manager, ... }: +{ + imports = [ inputs.home-manager.nixosModules.home-manager ]; networking = { firewall.enable = false; networkmanager = { enable = true; }; @@ -62,7 +61,7 @@ in { # }; }; - environment.systemPackages = with unstable.pkgs; [ + environment.systemPackages = with pkgs.unstable; [ alacritty czkawka # fslint before grsync @@ -83,7 +82,7 @@ in { programs = { vscode = { enable = true; - package = unstable.pkgs.vscode; + package = pkgs.unstable.vscode; }; mpv = { @@ -97,7 +96,7 @@ in { kitty = { enable = true; - package = unstable.pkgs.kitty; + package = pkgs.unstable.kitty; extraConfig = '' enable_audio_bell false diff --git a/configs/user.nix b/configs/user.nix index 6410e2d..a98168b 100755 --- a/configs/user.nix +++ b/configs/user.nix @@ -1,9 +1,15 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, inputs, ... }: let - unstable = import { config.allowUnfree = true; }; secrets = import ./secrets.nix; -in { - imports = [ ]; +in +{ + imports = [ + inputs.home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + } + ]; # Define a user account. Don't forget to set a password with ‘passwd’. users = { @@ -41,15 +47,12 @@ in { nix-ld.enable = true; }; - home-manager.useUserPackages = true; - home-manager.useGlobalPkgs = true; - environment.pathsToLink = [ "/share/zsh" ]; home-manager.users.alex = { pkgs, ... }: { home = { stateVersion = "24.05"; - packages = with unstable.pkgs; [ + packages = with pkgs.unstable; [ # atop broot ffmpeg @@ -141,7 +144,7 @@ in { plugins = [ { name = "powerlevel10k"; - src = unstable.pkgs.zsh-powerlevel10k; + src = pkgs.unstable.zsh-powerlevel10k; file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme"; } { @@ -159,10 +162,6 @@ in { "-g C" = "| wc -l"; "-g G" = "| grep --ignore-case"; bat = "upower -i /org/freedesktop/UPower/devices/battery_BAT0"; - brightness-max = - "echo 4794 | sudo tee /sys/class/backlight/intel_backlight/brightness"; - brightness-power-save = - "echo 2300 | sudo tee /sys/class/backlight/intel_backlight/brightness"; ff = "find . -type f -iname"; l = "eza --group-directories-first -l -g"; ll = "eza --group-directories-first -l -g"; diff --git a/flake.lock b/flake.lock index 8cc9012..30b058e 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,42 @@ { "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720042825, + "narHash": "sha256-A0vrUB6x82/jvf17qPCpxaM+ulJnD8YZwH9Ci0BsAzE=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "e1391fb22e18a36f57e6999c7a9f966dc80ac073", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-24.05", + "repo": "home-manager", + "type": "github" + } + }, + "nixos-hardware": { + "locked": { + "lastModified": 1724878143, + "narHash": "sha256-UjpKo92iZ25M05kgSOw/Ti6VZwpgdlOa73zHj8OcaDk=", + "owner": "nixos", + "repo": "nixos-hardware", + "rev": "95c3dfe6ef2e96ddc1ccdd7194e3cda02ca9a8ef", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "master", + "repo": "nixos-hardware", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1724855419, @@ -34,6 +71,8 @@ }, "root": { "inputs": { + "home-manager": "home-manager", + "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable" } diff --git a/flake.nix b/flake.nix index 8a5c375..5afc215 100644 --- a/flake.nix +++ b/flake.nix @@ -5,31 +5,42 @@ # Nixpkgs nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; + nixos-hardware.url = "github:nixos/nixos-hardware/master"; - # # Home manager - # home-manager.url = "github:nix-community/home-manager/release-24.05"; - # home-manager.inputs.nixpkgs.follows = "nixpkgs-unstable"; + # Home manager + home-manager = { + url = "github:nix-community/home-manager/release-24.05"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = - { self - , nixpkgs - , nixpkgs-unstable - # , home-manager - , ... - } @ inputs: + outputs = { self, nixpkgs, nixpkgs-unstable, home-manager, nixos-hardware, ... } @ inputs: let inherit (self) outputs; - system = "x86_64-linux"; + + # Supported systems for your flake packages, shell, etc. + 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; in { - # NixOS configuration entrypoint - # Available through 'nixos-rebuild --flake .#your-hostname' + overlays = import ./overlays { inherit inputs; }; + nixosConfigurations = { desktop = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; specialArgs = { inherit inputs outputs; }; - # > Our main nixos configuration file < - modules = [ ./machine/desktop.nix ]; + modules = [ + ./machine/desktop.nix + ]; }; }; }; diff --git a/machine/desktop-hardware-configuration.nix b/machine/desktop-hardware-configuration.nix new file mode 100644 index 0000000..d29e4b5 --- /dev/null +++ b/machine/desktop-hardware-configuration.nix @@ -0,0 +1,39 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/d43faf8e-ec90-4735-a1a4-aff6897604b2"; + fsType = "ext4"; + }; + + boot.initrd.luks.devices."luks-ba8eb308-e85f-4cee-9993-88c5ba0966ea".device = "/dev/disk/by-uuid/ba8eb308-e85f-4cee-9993-88c5ba0966ea"; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/1838-7DA8"; + 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..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp8s0.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp6s0.useDHCP = lib.mkDefault true; + + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/machine/desktop.nix b/machine/desktop.nix index 9732d75..b9c9098 100755 --- a/machine/desktop.nix +++ b/machine/desktop.nix @@ -1,18 +1,41 @@ -{ config, pkgs, lib, ... }: - +{ config, pkgs, inputs, outputs, ... }: let secrets = import ../configs/secrets.nix; be = import ../configs/borg-exclude.nix; wireguard = import ../configs/wireguard.nix; - unstable = import { config.allowUnfree = true; }; in { + nixpkgs = { + # You can add overlays here + overlays = [ + # Add overlays your own flake exports (from overlays and pkgs dir): + outputs.overlays.additions + outputs.overlays.modifications + outputs.overlays.unstable-packages + + # You can also add overlays exported from other flakes: + # neovim-nightly-overlay.overlays.default + + # Or define it inline, for example: + # (final: prev: { + # hi = final.hello.overrideAttrs (oldAttrs: { + # patches = [ ./change-hello-to-hi.patch ]; + # }); + # }) + ]; + # Configure your nixpkgs instance + config = { + # Disable if you don't want unfree packages + allowUnfree = true; + }; + }; + imports = [ - - - - - /etc/nixos/hardware-configuration.nix + ./desktop-hardware-configuration.nix + inputs.nixos-hardware.nixosModules.common-cpu-amd + inputs.nixos-hardware.nixosModules.common-cpu-amd-pstate + inputs.nixos-hardware.nixosModules.common-cpu-amd-zenpower + inputs.nixos-hardware.nixosModules.common-pc-ssd ../configs/browser.nix ../configs/common.nix ../configs/docker.nix @@ -23,16 +46,8 @@ in ../configs/user.nix ]; - # nixpkgs.localSystem = { - # gcc.arch = "znver2"; - # gcc.tune = "znver2"; - # system = "x86_64-linux"; - # }; - nix.settings.system-features = [ "nixos-test" "benchmark" "big-parallel" "kvm" "gccarch-znver2" ]; - nixpkgs.config.allowUnfree = true; - boot = { initrd.systemd.enable = true; loader = { @@ -50,7 +65,7 @@ in description = "AMDGPU Control Daemon"; wantedBy = [ "multi-user.target" ]; after = [ "multi-user.target" ]; - serviceConfig = { ExecStart = "${unstable.pkgs.lact}/bin/lact daemon"; }; + serviceConfig = { ExecStart = "${pkgs.unstable.lact}/bin/lact daemon"; }; }; }; @@ -79,7 +94,7 @@ in keyMap = "us"; }; - environment.systemPackages = with unstable.pkgs; [ + environment.systemPackages = with pkgs.unstable; [ lact amdgpu_top diff --git a/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..a1f5ca6 --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,23 @@ +# This file defines overlays +{ inputs, ... }: { + # This one brings our custom packages from the 'pkgs' directory + additions = final: _prev: import ../pkgs final.pkgs; + + # This one contains whatever you want to overlay + # You can change versions, add patches, set compilation flags, anything really. + # https://nixos.wiki/wiki/Overlays + modifications = final: prev: { + # example = prev.example.overrideAttrs (oldAttrs: rec { + # ... + # }); + }; + + # When applied, the unstable nixpkgs set (declared in the flake inputs) will + # be accessible through 'pkgs.unstable' + unstable-packages = final: _prev: { + unstable = import inputs.nixpkgs-unstable { + system = final.system; + config.allowUnfree = true; + }; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..3d9e23c --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,5 @@ +# Custom packages, that can be defined similarly to ones from nixpkgs +# You can build them using 'nix build .#example' +pkgs: { + # example = pkgs.callPackage ./example { }; +}