From 1d161bf1cad8d6f78bf1ea04384c22c0be536c37 Mon Sep 17 00:00:00 2001 From: Frank Lyder Bredland Date: Fri, 12 Jul 2024 20:52:41 +0200 Subject: [PATCH] Moving all nixos config into a flake --- os/nixos/Readme.md | 24 +-- os/nixos/flake.lock | 257 +++++++++++++++++++++++++++++ os/nixos/flake.nix | 59 +++++++ os/nixos/home-manager/apps.nix | 37 +++++ os/nixos/home-manager/env.nix | 3 +- os/nixos/home-manager/eww.nix | 23 +++ os/nixos/home-manager/home.nix | 4 +- os/nixos/home-manager/wayland.nix | 62 ++++--- os/nixos/machine/audio-video.nix | 23 ++- os/nixos/machine/configuration.nix | 18 +- os/nixos/machine/steam.nix | 1 + os/nixos/machine/virtual.nix | 11 ++ 12 files changed, 458 insertions(+), 64 deletions(-) create mode 100644 os/nixos/flake.lock create mode 100644 os/nixos/flake.nix create mode 100644 os/nixos/home-manager/apps.nix create mode 100644 os/nixos/home-manager/eww.nix create mode 100644 os/nixos/machine/virtual.nix diff --git a/os/nixos/Readme.md b/os/nixos/Readme.md index d0c9cfc..3f0fa12 100644 --- a/os/nixos/Readme.md +++ b/os/nixos/Readme.md @@ -1,27 +1,9 @@ # NixOS setup -## Machine config +NixOS setup using flakes. ```bash -$ sudo cat /etc/nixos/configuration.nix -{ config, pkgs, ... }: - -{ - imports = [ - /home/knarf/configs/os/nixos/machine/configuration.nix - ]; -} -``` - -This way I can version control my config by having an empty configurations.nix that just imports the one in the repo. - -After making changes simply run: - -```bash -sudo nixos-rebuild switch +sudo nixos-rebuild switch --flake . # To rebuild the machine +home-manager switch --flake . ``` -## home-manager - -[home-manager guide](https://nix-community.github.io/home-manager/) - diff --git a/os/nixos/flake.lock b/os/nixos/flake.lock new file mode 100644 index 0000000..220cb5f --- /dev/null +++ b/os/nixos/flake.lock @@ -0,0 +1,257 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720470846, + "narHash": "sha256-7ftA4Bv5KfH4QdTRxqe8/Hz2YTKo+7IQ9n7vbNWgv28=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "2fb5c1e0a17bc6059fa09dc411a43d75f35bb192", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "hyprcursor": { + "inputs": { + "hyprlang": [ + "hyprland", + "hyprlang" + ], + "nixpkgs": [ + "hyprland", + "nixpkgs" + ], + "systems": [ + "hyprland", + "systems" + ] + }, + "locked": { + "lastModified": 1720108799, + "narHash": "sha256-AxRkTJlbB8r7aG6gvc7IaLhc2T9TO4/8uqanKRxukBQ=", + "owner": "hyprwm", + "repo": "hyprcursor", + "rev": "a5c0d57325c5f0814c39110a70ca19c070ae9486", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprcursor", + "type": "github" + } + }, + "hyprland": { + "inputs": { + "hyprcursor": "hyprcursor", + "hyprlang": "hyprlang", + "hyprutils": "hyprutils", + "hyprwayland-scanner": "hyprwayland-scanner", + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems", + "xdph": "xdph" + }, + "locked": { + "lastModified": 1720453602, + "narHash": "sha256-7+PjJZn/jpqNkVKJ3AGVT9G601rVj/R8KkT+WWjhwyk=", + "ref": "refs/heads/main", + "rev": "b03f41efec14273cf25c42d4cef326acc36cb319", + "revCount": 4913, + "submodules": true, + "type": "git", + "url": "https://github.com/hyprwm/Hyprland" + }, + "original": { + "submodules": true, + "type": "git", + "url": "https://github.com/hyprwm/Hyprland" + } + }, + "hyprland-protocols": { + "inputs": { + "nixpkgs": [ + "hyprland", + "xdph", + "nixpkgs" + ], + "systems": [ + "hyprland", + "xdph", + "systems" + ] + }, + "locked": { + "lastModified": 1718746314, + "narHash": "sha256-HUklK5u86w2Yh9dOkk4FdsL8eehcOZ95jPhLixGDRQY=", + "owner": "hyprwm", + "repo": "hyprland-protocols", + "rev": "1b61f0093afff20ab44d88ad707aed8bf2215290", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprland-protocols", + "type": "github" + } + }, + "hyprlang": { + "inputs": { + "hyprutils": [ + "hyprland", + "hyprutils" + ], + "nixpkgs": [ + "hyprland", + "nixpkgs" + ], + "systems": [ + "hyprland", + "systems" + ] + }, + "locked": { + "lastModified": 1720381373, + "narHash": "sha256-lyC/EZdHULsaAKVryK11lgHY9u6pXr7qR4irnxNWC7k=", + "owner": "hyprwm", + "repo": "hyprlang", + "rev": "5df0174fd09de4ac5475233d65ffc703e89b82eb", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprlang", + "type": "github" + } + }, + "hyprutils": { + "inputs": { + "nixpkgs": [ + "hyprland", + "nixpkgs" + ], + "systems": [ + "hyprland", + "systems" + ] + }, + "locked": { + "lastModified": 1720203444, + "narHash": "sha256-lq2dPPPcwMHTLsFrQ2pRp4c2LwDZWoqzSyjuPdeJCP4=", + "owner": "hyprwm", + "repo": "hyprutils", + "rev": "a8c3a135701a7b64db0a88ec353a392f402d2a87", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprutils", + "type": "github" + } + }, + "hyprwayland-scanner": { + "inputs": { + "nixpkgs": [ + "hyprland", + "nixpkgs" + ], + "systems": [ + "hyprland", + "systems" + ] + }, + "locked": { + "lastModified": 1720215857, + "narHash": "sha256-JPdL+Qul+jEueAn8CARfcWP83eJgwkhMejQYfDvrgvU=", + "owner": "hyprwm", + "repo": "hyprwayland-scanner", + "rev": "d5fa094ca27e0039be5e94c0a80ae433145af8bb", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprwayland-scanner", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1720418205, + "narHash": "sha256-cPJoFPXU44GlhWg4pUk9oUPqurPlCFZ11ZQPk21GTPU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "655a58a72a6601292512670343087c2d75d859c1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "hyprland": "hyprland", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" + } + }, + "xdph": { + "inputs": { + "hyprland-protocols": "hyprland-protocols", + "hyprlang": [ + "hyprland", + "hyprlang" + ], + "nixpkgs": [ + "hyprland", + "nixpkgs" + ], + "systems": [ + "hyprland", + "systems" + ] + }, + "locked": { + "lastModified": 1720194466, + "narHash": "sha256-Rizg9efi6ue95zOp0MeIV2ZedNo+5U9G2l6yirgBUnA=", + "owner": "hyprwm", + "repo": "xdg-desktop-portal-hyprland", + "rev": "b9b97e5ba23fe7bd5fa4df54696102e8aa863cf6", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "xdg-desktop-portal-hyprland", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/os/nixos/flake.nix b/os/nixos/flake.nix new file mode 100644 index 0000000..8ff2ee8 --- /dev/null +++ b/os/nixos/flake.nix @@ -0,0 +1,59 @@ +{ + description = "NixOS and Home-manager config"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + hyprland = { + url = "git+https://github.com/hyprwm/Hyprland?submodules=1"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { nixpkgs, home-manager, hyprland, ... } @ inputs: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + system = "${system}"; + config = { + allowUnfree = true; + }; + }; + user = "knarf"; + in { + # Machine + nixosConfigurations."nixos" = nixpkgs.lib.nixosSystem { + inherit pkgs; + inherit system; + + modules = [ + ./machine/configuration.nix + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.${user} = import ./home-manager/home.nix; + } + ]; + + specialArgs = {inherit user;}; + }; + + # Home manager + homeConfigurations."${user}" = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + + modules = [ + hyprland.homeManagerModules.default + ./home-manager/home.nix + ]; + + extraSpecialArgs = {inherit user;}; + }; + }; +} diff --git a/os/nixos/home-manager/apps.nix b/os/nixos/home-manager/apps.nix new file mode 100644 index 0000000..c7e6b16 --- /dev/null +++ b/os/nixos/home-manager/apps.nix @@ -0,0 +1,37 @@ +{ config, pkgs, ... }: + +{ + nixpkgs = { + config = { + allowUnfree = true; + allowUnfreePredicate = (_: true); + }; + }; + + home.packages = [ + # Browsers + pkgs.firefox + + # Chat + pkgs.discord + + # Multimedia + pkgs.spotify + pkgs.vlc + pkgs.audacity + + # Streaming + pkgs.obs-studio + + # 3D / CAD / Game engines +# pkgs.blender +# pkgs.freecad + pkgs.openscad + pkgs.godot_4 + + # Other + pkgs.webtorrent_desktop + pkgs.obsidian + ]; + +} diff --git a/os/nixos/home-manager/env.nix b/os/nixos/home-manager/env.nix index 9be0bc0..5cc2c8f 100644 --- a/os/nixos/home-manager/env.nix +++ b/os/nixos/home-manager/env.nix @@ -33,7 +33,8 @@ pkgs.helix # Programming - pkgs.fnm # Fast and simple Node.js version manager + pkgs.nodejs_20 + pkgs.corepack pkgs.bun pkgs.rustup pkgs.go diff --git a/os/nixos/home-manager/eww.nix b/os/nixos/home-manager/eww.nix new file mode 100644 index 0000000..76a5c0c --- /dev/null +++ b/os/nixos/home-manager/eww.nix @@ -0,0 +1,23 @@ +{ config, pkgs, ... }: + +{ +/* + home.packages = [ + pkgs.eww + ]; + + xdg.configFile."eww.yuck" = { + target = "eww/eww.yuck"; + text = '' +test +''; + }; + + xdg.configFile."eww.scss" = { + target = "eww/eww.scss"; + text = '' +.test {} +''; + }; +*/ +} diff --git a/os/nixos/home-manager/home.nix b/os/nixos/home-manager/home.nix index 9807813..29bae53 100644 --- a/os/nixos/home-manager/home.nix +++ b/os/nixos/home-manager/home.nix @@ -1,9 +1,11 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: { imports = [ ./env.nix ./wayland.nix + ./eww.nix + ./apps.nix ]; # Home Manager needs a bit of information about you and the paths it should diff --git a/os/nixos/home-manager/wayland.nix b/os/nixos/home-manager/wayland.nix index 142a3da..2fdf062 100644 --- a/os/nixos/home-manager/wayland.nix +++ b/os/nixos/home-manager/wayland.nix @@ -2,15 +2,24 @@ { home.packages = [ - pkgs.kitty - pkgs.seatd + pkgs.kitty # Terminal emulator + pkgs.dunst # Notification deamon + pkgs.libnotify + pkgs.swww # Wallpaper deamon + pkgs.rofi-wayland # dmenu replacement for Wayland ]; +# xdg.portal = { +# enable = true; +# configPackages = [ pkgs.xdg-desktop-portal-hyprland ]; +# }; + wayland.windowManager.hyprland = { - # Whether to enable Hyprland wayland compositor enable = true; + # The hyprland package to use - package = pkgs.hyprland; + #package = pkgs.hyprland; + # Whether to enable XWayland xwayland.enable = true; @@ -20,27 +29,30 @@ settings = { "$mod" = "SUPER"; - bind = - [ - "$mod, F, exec, firefox" - ", Print, exec, grimblast copy area" - ] - ++ ( - # workspaces - # binds $mod + [shift +] {1..10} to [move to] workspace {1..10} - builtins.concatLists (builtins.genList ( - x: let - ws = let - c = (x + 1) / 10; - in - builtins.toString (x + 1 - (c * 10)); - in [ - "$mod, ${ws}, workspace, ${toString (x + 1)}" - "$mod SHIFT, ${ws}, movetoworkspace, ${toString (x + 1)}" - ] - ) - 10) - ); + "exec-once" = [ + #"waybar" + #"eww" + ]; + bind = [ + "$mod, F, exec, firefox" + ", Print, exec, grimblast copy area" + ] + ++ ( + # workspaces + # binds $mod + [shift +] {1..10} to [move to] workspace {1..10} + builtins.concatLists (builtins.genList ( + x: let + ws = let + c = (x + 1) / 10; + in + builtins.toString (x + 1 - (c * 10)); + in [ + "$mod, ${ws}, workspace, ${toString (x + 1)}" + "$mod SHIFT, ${ws}, movetoworkspace, ${toString (x + 1)}" + ] + ) + 10) + ); }; }; diff --git a/os/nixos/machine/audio-video.nix b/os/nixos/machine/audio-video.nix index a395fa1..c7078a2 100644 --- a/os/nixos/machine/audio-video.nix +++ b/os/nixos/machine/audio-video.nix @@ -2,14 +2,21 @@ { services.seatd.enable = true; # seatd is needed to run hyprland - programs.hyprland.enable = true; + + environment.sessionVariables = { + # Hint electron apps to use wayland + NIXOS_OZONE_WL = "1"; + }; # Enable OpenGL + /* hardware.opengl = { enable = true; - driSupport = true; - driSupport32Bit = true; +# driSupport = true; +# driSupport32Bit = true; }; + */ + hardware.graphics.enable = true; # Load nvidia driver for Xorg and Wayland services.xserver.videoDrivers = ["nvidia"]; @@ -20,7 +27,7 @@ # Nvidia power management. Experimental, and can cause sleep/suspend to fail. # Enable this if you have graphical corruption issues or application crashes after waking - # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead + # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead # of just the bare essentials. powerManagement.enable = false; @@ -30,9 +37,9 @@ # Use the NVidia open source kernel module (not to be confused with the # independent third-party "nouveau" open source driver). - # Support is limited to the Turing and later architectures. Full list of - # supported GPUs is at: - # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus + # Support is limited to the Turing and later architectures. Full list of + # supported GPUs is at: + # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus # Only available from driver 515.43.04+ # Currently alpha-quality/buggy, so false is currently the recommended setting. open = false; @@ -54,6 +61,6 @@ alsa.enable = true; alsa.support32Bit = true; pulse.enable = true; - #jack.enable = true; + jack.enable = true; }; } diff --git a/os/nixos/machine/configuration.nix b/os/nixos/machine/configuration.nix index 5f6a047..6e6e35a 100644 --- a/os/nixos/machine/configuration.nix +++ b/os/nixos/machine/configuration.nix @@ -1,13 +1,16 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: { imports = [ ./hardware-configuration.nix ./steam.nix ./audio-video.nix - + ./virtual.nix ]; + # Enable flakes + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + # Bootloader boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; @@ -40,13 +43,14 @@ "docker" "audio" "seat" # seatd group + "incus-admin" + "incus" ]; packages = with pkgs; []; shell = pkgs.zsh; }; - # System packages (allow unfree packages) - nixpkgs.config.allowUnfree = true; + # System packages environment.systemPackages = with pkgs; [ vim wget @@ -55,20 +59,18 @@ bash home-manager zsh - kitty pciutils ]; programs.zsh.enable = true; - # enable docker - virtualisation.docker.enable = true; - +/* home-manager.users.knarf = { pkgs, ... }: { # The state version is required and should stay at the version you # originally installed. home.stateVersion = "24.05"; }; +*/ # Some programs need SUID wrappers, can be configured further or are # started in user sessions. diff --git a/os/nixos/machine/steam.nix b/os/nixos/machine/steam.nix index b7a979c..f44df71 100644 --- a/os/nixos/machine/steam.nix +++ b/os/nixos/machine/steam.nix @@ -3,6 +3,7 @@ { environment.systemPackages = with pkgs; [ mangohud # overlay showing cpu / gpu load, etc + gamescope protonup lutris ]; diff --git a/os/nixos/machine/virtual.nix b/os/nixos/machine/virtual.nix new file mode 100644 index 0000000..e40bdb6 --- /dev/null +++ b/os/nixos/machine/virtual.nix @@ -0,0 +1,11 @@ +{ config, pkgs, ... }: + +{ + # enable docker + virtualisation.docker.enable = true; + + # enable incus + # todo: docker needs iptables, but Incus needs nftables. So need to figure out how to solve that conflict + #networking.nftables.enable = true + #virtualisation.incus.enable = true; +}