refactor: add modules
All checks were successful
/ check (push) Successful in 4m42s

This commit is contained in:
winston 2024-09-19 21:52:54 +02:00
parent be802492e9
commit 9e9cb4a006
Signed by: winston
GPG key ID: 3786770EDBC2B481
28 changed files with 203 additions and 139 deletions

View file

@ -404,7 +404,7 @@
"nur": "nur", "nur": "nur",
"pre-commit-hooks": "pre-commit-hooks", "pre-commit-hooks": "pre-commit-hooks",
"vscode-server": "vscode-server", "vscode-server": "vscode-server",
"wsl": "wsl" "nixos-wsl": "nixos-wsl"
} }
}, },
"rust-overlay": { "rust-overlay": {
@ -488,7 +488,7 @@
"type": "github" "type": "github"
} }
}, },
"wsl": { "nixos-wsl": {
"inputs": { "inputs": {
"flake-compat": [], "flake-compat": [],
"flake-utils": [ "flake-utils": [

View file

@ -26,7 +26,7 @@
system = "x86_64-linux"; system = "x86_64-linux";
username = "winston"; username = "winston";
isGraphical = false; isGraphical = false;
extraModules = [ inputs.wsl.nixosModules.default ]; extraModules = [ inputs.nixos-wsl.nixosModules.default ];
} }
]; ];
imports = [ inputs.pre-commit-hooks.flakeModule ]; imports = [ inputs.pre-commit-hooks.flakeModule ];
@ -65,9 +65,6 @@
RULES = "./home/secrets/secrets.nix"; RULES = "./home/secrets/secrets.nix";
buildInputs = buildInputs =
(with pkgs; [ (with pkgs; [
dhall
dhall-lsp-server
dhall-yaml
just just
nix-output-monitor nix-output-monitor
nixd nixd
@ -132,7 +129,7 @@
url = "github:nix-community/home-manager"; url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
wsl = { nixos-wsl = {
url = "github:nix-community/nixos-wsl"; url = "github:nix-community/nixos-wsl";
inputs.flake-compat.follows = ""; inputs.flake-compat.follows = "";
inputs.flake-utils.follows = "flake-utils"; inputs.flake-utils.follows = "flake-utils";

View file

@ -1,6 +1,7 @@
{ {
config, config,
lib, lib,
osConfig,
pkgs, pkgs,
... ...
}: }:
@ -43,9 +44,10 @@ in
watchexec watchexec
] ]
++ lib.optionals (config.isGraphical && isLinux) [ ++ lib.optionals (config.isGraphical && isLinux) [
_1password-gui (_1password-gui.override { polkitPolicyOwners = [ osConfig.dotfiles.username ]; })
uhk-agent
neovide neovide
nextcloud-client
uhk-agent
] ]
); );
sessionVariables.SSH_AUTH_SOCK = lib.optionalString isDarwin "${config.programs.gpg.homedir}/S.gpg-agent.ssh"; sessionVariables.SSH_AUTH_SOCK = lib.optionalString isDarwin "${config.programs.gpg.homedir}/S.gpg-agent.ssh";

View file

@ -6,6 +6,7 @@
}: }:
rec { rec {
inherit (pkgs.stdenv) isLinux isDarwin; inherit (pkgs.stdenv) isLinux isDarwin;
inherit (pkgs.lib) mkDefault mkOption types;
extraSpecialArgs = { extraSpecialArgs = {
flakePath = flakePath =
@ -21,10 +22,10 @@ rec {
"/Users/${username}" "/Users/${username}"
else else
throw "Unsupported system"; throw "Unsupported system";
home.username = username; home.username = mkDefault username;
isGraphical = false; isGraphical = mkDefault false;
targets.genericLinux.enable = isLinux; targets.genericLinux.enable = mkDefault isLinux;
xdg.mime.enable = isLinux; xdg.mime.enable = mkDefault isLinux;
}; };
modules = modules =
@ -36,10 +37,7 @@ rec {
]) ])
++ [ ++ [
( (
{ osConfig, lib, ... }: { osConfig, ... }:
let
inherit (lib) mkOption types;
in
{ {
options = { options = {
isGraphical = mkOption { isGraphical = mkOption {

View file

@ -1,5 +1,4 @@
{ {
config,
pkgs, pkgs,
lib, lib,
... ...
@ -66,6 +65,7 @@
builtins.concatStringsSep "\n" (map (app: ''yabai -m rule --add app="${app}" ${options}'') apps); builtins.concatStringsSep "\n" (map (app: ''yabai -m rule --add app="${app}" ${options}'') apps);
unmanaged = apps: mkRules apps "manage=off"; unmanaged = apps: mkRules apps "manage=off";
in in
# bash
'' ''
# auto-inject scripting additions # auto-inject scripting additions
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa" yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
@ -119,6 +119,7 @@
) )
); );
in in
# bash
'' ''
#!/usr/bin/env sh #!/usr/bin/env sh
# focus window # focus window
@ -157,11 +158,9 @@
}; };
}; };
environment.systemPackages = [ pkgs.jankyborders ];
launchd.user.agents.jankyborders.serviceConfig = { launchd.user.agents.jankyborders.serviceConfig = {
ProgramArguments = [ "${pkgs.jankyborders}/bin/borders" ]; ProgramArguments = [ (lib.getExe pkgs.jankyborders) ];
KeepAlive = true; KeepAlive = true;
RunAtLoad = true; RunAtLoad = true;
EnvironmentVariables.PATH = "${pkgs.jankyborders}/bin:${config.environment.systemPath}";
}; };
} }

View file

@ -15,9 +15,9 @@ let
); );
binary = binary =
{ {
swayfx = "sway"; hyprland = "Hyprland";
sway = "sway"; sway = "sway";
hyprland = "hypr"; swayfx = "sway";
} }
.${desktop} or (throw "greetd: desktop not supported"); .${desktop} or (throw "greetd: desktop not supported");
in in
@ -25,7 +25,7 @@ in
config = lib.mkIf condition { config = lib.mkIf condition {
services.greetd = { services.greetd = {
enable = true; enable = true;
settings.default_session.command = "${lib.getExe pkgs.greetd.tuigreet} --cmd '${pkgs.dbus}/bin/dbus-run-session ${binary}'"; settings.default_session.command = "${lib.getExe pkgs.greetd.tuigreet} --remember --cmd ${binary}";
}; };
services.gnome.gnome-keyring.enable = true; services.gnome.gnome-keyring.enable = true;
security.pam.services.greetd = { security.pam.services.greetd = {

View file

@ -37,12 +37,13 @@ in
programs.sway = { programs.sway = {
enable = true; enable = true;
package = lib.mkIf (config.dotfiles.desktop == "swayfx") pkgs.swayfx; package = if (config.dotfiles.desktop == "swayfx") then pkgs.swayfx else pkgs.sway;
extraPackages = with pkgs; [ extraPackages = with pkgs; [
swaylock-effects swaylock-effects
swayidle swayidle
]; ];
extraSessionCommands = '' extraSessionCommands = # bash
''
# session # session
export XDG_SESSION_TYPE=wayland export XDG_SESSION_TYPE=wayland
export XDG_SESSION_DESKTOP=sway export XDG_SESSION_DESKTOP=sway

View file

@ -1,18 +0,0 @@
{ lib, pkgs, ... }:
let
inherit (lib) mkForce;
in
{
services = {
kanata.enable = mkForce false;
dnsmasq.enable = mkForce false;
mullvad-vpn.enable = mkForce false;
stubby.enable = mkForce false;
};
virtualisation.podman.enable = mkForce false;
system = {
build.installBootLoader = mkForce "${pkgs.coreutils}/bin/true";
stateVersion = "23.11";
};
}

View file

@ -2,7 +2,10 @@
{ {
imports = [ ./hardware.nix ]; imports = [ ./hardware.nix ];
dotfiles.desktop = "sway"; dotfiles = {
desktop = "sway";
gaming.enable = true;
};
networking = { networking = {
networkmanager.enable = true; networkmanager.enable = true;
@ -17,54 +20,31 @@
time.timeZone = "Europe/Vienna"; time.timeZone = "Europe/Vienna";
services = { services = {
flatpak.enable = true;
openssh.enable = true; openssh.enable = true;
pcscd.enable = true; pcscd.enable = true;
transmission.enable = true;
transmission.openFirewall = true;
}; };
virtualisation.podman.enable = true; virtualisation = {
virtualisation.libvirtd.enable = true; libvirtd.enable = true;
podman.enable = true;
};
users.users."${config.dotfiles.username}".extraGroups = [ users.users."${config.dotfiles.username}".extraGroups = [
"libvirtd" "libvirtd"
"transmission"
]; ];
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
cabextract (pkgs.wrapOBS {
discover-overlay plugins = with pkgs.obs-studio-plugins; [
lutris-free obs-backgroundremoval
mangohud obs-composite-blur
obs-pipewire-audio-capture
wlrobs
];
})
virt-manager virt-manager
wineWowPackages.staging virtiofsd
winetricks
]; ];
programs = {
gamemode = {
enable = true;
settings = {
custom = {
start = "${pkgs.libnotify}/bin/notify-send 'GameMode started'";
end = "${pkgs.libnotify}/bin/notify-send 'GameMode ended'";
};
};
};
steam = {
enable = true;
package = pkgs.steam.override {
extraEnv.MANGOHUD = 1;
extraPkgs =
p: with p; [
corefonts
protontricks
gamescope
];
};
};
};
system.stateVersion = "22.11"; system.stateVersion = "22.11";
} }

View file

@ -3,7 +3,7 @@ rec {
hmCommonConfig = hmCommonConfig =
{ username }: { username }:
( (
{ config, pkgs, ... }: { pkgs, ... }:
let let
homeLib = import ../home/lib.nix { inherit inputs username pkgs; }; homeLib = import ../home/lib.nix { inherit inputs username pkgs; };
in in
@ -34,6 +34,9 @@ rec {
extraModules ? [ ], extraModules ? [ ],
}: }:
let let
pkgs = inputs.nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
ldTernary = ldTernary =
l: d: l: d:
if pkgs.stdenv.isLinux then if pkgs.stdenv.isLinux then
@ -42,17 +45,16 @@ rec {
d d
else else
throw "Unsupported system"; throw "Unsupported system";
target = ldTernary "nixosConfigurations" "darwinConfigurations";
builder = ldTernary inputs.nixpkgs.lib.nixosSystem inputs.darwin.lib.darwinSystem; builder = ldTernary inputs.nixpkgs.lib.nixosSystem inputs.darwin.lib.darwinSystem;
hostPlatform = ldTernary "nixos" "darwin";
module = ldTernary "nixosModules" "darwinModules"; module = ldTernary "nixosModules" "darwinModules";
hostPlatform = ldTernary "linux" "darwin"; target = ldTernary "nixosConfigurations" "darwinConfigurations";
linuxModules = [ inputs.nixos-cosmic.nixosModules.default ];
darwinModules = [ inputs.nekowinston-nur.darwinModules.default ]; darwinModules = [ inputs.nekowinston-nur.darwinModules.default ];
linuxModules = [
pkgs = inputs.nixpkgs.legacyPackages.${system}; inputs.nixos-cosmic.nixosModules.default
inherit (pkgs) lib; inputs.nixos-wsl.nixosModules.default
inherit (pkgs.lib) mkOption types; ];
in in
{ {
${target}."${host}" = builder { ${target}."${host}" = builder {
@ -60,43 +62,25 @@ rec {
modules = modules =
[ [
{ {
options = { config = {
dotfiles = { dotfiles = {
username = mkOption { username = lib.mkDefault username;
type = types.str; desktop = if (pkgs.stdenv.isLinux && isGraphical) then "sway" else null;
default = username;
description = "The username of the user";
}; };
desktop = mkOption { isGraphical = lib.mkDefault isGraphical;
type = types.nullOr ( networking.hostName = lib.mkDefault host;
types.enum [
"cosmic"
"gnome"
"hyprland"
"sway"
"swayfx"
]
);
default = if (pkgs.stdenv.isLinux && isGraphical) then "sway" else null;
description = "The desktop environment to use";
}; };
};
isGraphical = mkOption {
type = types.bool;
default = isGraphical;
description = "Whether the system is a graphical target";
};
};
config.networking.hostName = host;
} }
../modules/shared
../modules/${hostPlatform}
./common/shared ./common/shared
./common/${hostPlatform} ./common/${hostPlatform}
./${host} ./${host}
inputs.home-manager.${module}.home-manager inputs.home-manager.${module}.home-manager
(hmCommonConfig { inherit username; }) (hmCommonConfig { inherit username; })
] ]
++ lib.optionals pkgs.stdenv.isLinux linuxModules
++ lib.optionals pkgs.stdenv.isDarwin darwinModules ++ lib.optionals pkgs.stdenv.isDarwin darwinModules
++ lib.optionals pkgs.stdenv.isLinux linuxModules
++ extraModules; ++ extraModules;
specialArgs = { specialArgs = {
inherit inputs; inherit inputs;

View file

@ -1,5 +1,5 @@
{ {
imports = [ ../common/wsl ]; dotfiles.wsl.enable = true;
i18n.defaultLocale = "en_US.UTF-8"; i18n.defaultLocale = "en_US.UTF-8";
location = { location = {
@ -8,10 +8,5 @@
}; };
time.timeZone = "Europe/Vienna"; time.timeZone = "Europe/Vienna";
wsl = { system.stateVersion = "23.11";
enable = true;
defaultUser = "winston";
startMenuLaunchers = true;
useWindowsDriver = true;
};
} }

View file

@ -0,0 +1 @@
{ }

View file

@ -0,0 +1,6 @@
{
imports = [
./gaming.nix
./wsl.nix
];
}

41
modules/nixos/gaming.nix Normal file
View file

@ -0,0 +1,41 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.dotfiles.gaming;
gamePkgs =
pkgs: with pkgs; [
corefonts
gamescope
mangohud
];
in
{
options.dotfiles.gaming.enable = lib.mkEnableOption "gaming configuration";
config = lib.mkIf cfg.enable {
environment.systemPackages = with pkgs; [
discover-overlay
(lutris.override { extraPkgs = gamePkgs; })
];
programs = {
gamemode = {
enable = true;
settings = {
custom = {
start = "${pkgs.libnotify}/bin/notify-send 'GameMode started'";
end = "${pkgs.libnotify}/bin/notify-send 'GameMode ended'";
};
};
};
steam = {
enable = true;
package = pkgs.steam.override { extraPkgs = gamePkgs; };
};
};
};
}

37
modules/nixos/wsl.nix Normal file
View file

@ -0,0 +1,37 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.dotfiles.wsl;
inherit (lib) mkDefault mkForce;
in
{
options.dotfiles.wsl.enable = lib.mkEnableOption "NixOS-WSL specific options";
config = lib.mkIf cfg.enable {
# disable services that are not needed in WSL
services = {
dnsmasq.enable = mkForce false;
kanata.enable = mkForce false;
mullvad-vpn.enable = mkForce false;
stubby.enable = mkForce false;
};
# podman runs on native Windows
virtualisation.podman.enable = mkForce false;
# main WSL defaults
wsl = {
enable = mkDefault true;
defaultUser = mkDefault config.dotfiles.username;
startMenuLaunchers = mkDefault true;
useWindowsDriver = mkDefault true;
};
# skip installing the bootloader
system.build.installBootLoader = mkForce "${pkgs.coreutils}/bin/true";
};
}

36
modules/shared/config.nix Normal file
View file

@ -0,0 +1,36 @@
{
lib,
...
}:
let
inherit (lib) types;
in
{
options = {
dotfiles = lib.mkOption {
type = types.submodule {
options = {
desktop = lib.mkOption {
description = "The desktop environment to use";
type = types.nullOr (
types.enum [
"cosmic"
"gnome"
"hyprland"
"sway"
"swayfx"
]
);
};
username = lib.mkOption {
description = "The username of the user";
type = types.str;
};
};
};
};
isGraphical = lib.mkEnableOption "" // {
description = "Whether the system is a graphical target";
};
};
}

View file

@ -0,0 +1,5 @@
{
imports = [
./config.nix
];
}

View file

@ -4,15 +4,15 @@
( (
final: prev: final: prev:
let let
srcs = prev.callPackages ../_sources/generated.nix { }; srcs = final.callPackages ../_sources/generated.nix { };
in in
{ {
nushellPlugins = (prev.nushellPlugins or { }) // { nushellPlugins = (prev.nushellPlugins or { }) // {
clipboard = prev.callPackage ./nu_plugin_clipboard.nix { }; clipboard = final.callPackage ./nu_plugin_clipboard.nix { };
}; };
starship = prev.starship.overrideAttrs (old: { starship = prev.starship.overrideAttrs (old: {
patches = [ patches = [
(prev.fetchpatch { (final.fetchpatch {
url = "https://github.com/starship/starship/pull/4439.patch"; url = "https://github.com/starship/starship/pull/4439.patch";
sha256 = "sha256-BKH3elz96Oa424Oz5UIKA2/BOpkym1LTestvccFinnc="; sha256 = "sha256-BKH3elz96Oa424Oz5UIKA2/BOpkym1LTestvccFinnc=";
}) })
@ -22,10 +22,10 @@
inherit (srcs.yabai) version src; inherit (srcs.yabai) version src;
}); });
nur = import inputs.nur { nur = import inputs.nur {
nurpkgs = prev; nurpkgs = final;
pkgs = prev; pkgs = final;
repoOverrides = { repoOverrides = {
nekowinston = inputs.nekowinston-nur.packages.${prev.stdenv.system}; nekowinston = inputs.nekowinston-nur.packages.${final.stdenv.system};
}; };
}; };
} }