From c86be5008413970c85145f9a290b89cb79a07f2d Mon Sep 17 00:00:00 2001 From: LavaDesu Date: Thu, 15 Jul 2021 15:09:38 +0700 Subject: [PATCH] restructure - users/rin/default.nix -> users/rin.nix - users/rin/home.nix +-> users/rin.nix - users/rin/*.nix -> modules/user/*.nix - users/rin/scripts/ -> scripts/ - hosts/winter/default.nix -> hosts/winter.nix - hosts/winter/*.nix -> modules/system/*.nix - modules are dynamically imported as sets for system and user --- flake.nix | 32 +++- hosts/{winter/default.nix => winter.nix} | 22 +-- {hosts/winter => modules/system}/audio.nix | 0 {hosts/winter => modules/system}/gui.nix | 0 .../system}/hardware-configuration.nix | 0 {hosts/winter => modules/system}/kernel.nix | 0 .../winter => modules/system}/networking.nix | 0 {hosts/winter => modules/system}/packages.nix | 0 {hosts/winter => modules/system}/security.nix | 0 {hosts/winter => modules/system}/snapper.nix | 0 {users/rin => modules/user}/bspwm.nix | 0 {users/rin => modules/user}/dunst.nix | 0 {users/rin => modules/user}/kitty.nix | 0 {users/rin => modules/user}/mpv.nix | 0 {users/rin => modules/user}/neovim.nix | 0 {users/rin => modules/user}/npm.nix | 0 {users/rin => modules/user}/picom.nix | 0 {users/rin => modules/user}/polybar.nix | 2 +- {users/rin => modules/user}/rofi.nix | 0 {users/rin => modules/user}/sxhkd.nix | 0 {users/rin => modules/user}/theming.nix | 0 {users/rin => modules/user}/xdg.nix | 0 {users/rin => modules/user}/xorg.nix | 2 +- {users/rin => modules/user}/zsh.nix | 0 {users/rin/scripts => scripts}/osu | 0 {users/rin/scripts => scripts}/polybar.sh | 0 {users/rin/scripts => scripts}/xinitrc | 0 users/rin.nix | 138 ++++++++++++++++++ users/rin/default.nix | 9 -- users/rin/home.nix | 130 ----------------- 30 files changed, 178 insertions(+), 157 deletions(-) rename hosts/{winter/default.nix => winter.nix} (82%) rename {hosts/winter => modules/system}/audio.nix (100%) rename {hosts/winter => modules/system}/gui.nix (100%) rename {hosts/winter => modules/system}/hardware-configuration.nix (100%) rename {hosts/winter => modules/system}/kernel.nix (100%) rename {hosts/winter => modules/system}/networking.nix (100%) rename {hosts/winter => modules/system}/packages.nix (100%) rename {hosts/winter => modules/system}/security.nix (100%) rename {hosts/winter => modules/system}/snapper.nix (100%) rename {users/rin => modules/user}/bspwm.nix (100%) rename {users/rin => modules/user}/dunst.nix (100%) rename {users/rin => modules/user}/kitty.nix (100%) rename {users/rin => modules/user}/mpv.nix (100%) rename {users/rin => modules/user}/neovim.nix (100%) rename {users/rin => modules/user}/npm.nix (100%) rename {users/rin => modules/user}/picom.nix (100%) rename {users/rin => modules/user}/polybar.nix (97%) rename {users/rin => modules/user}/rofi.nix (100%) rename {users/rin => modules/user}/sxhkd.nix (100%) rename {users/rin => modules/user}/theming.nix (100%) rename {users/rin => modules/user}/xdg.nix (100%) rename {users/rin => modules/user}/xorg.nix (94%) rename {users/rin => modules/user}/zsh.nix (100%) rename {users/rin/scripts => scripts}/osu (100%) rename {users/rin/scripts => scripts}/polybar.sh (100%) rename {users/rin/scripts => scripts}/xinitrc (100%) create mode 100644 users/rin.nix delete mode 100644 users/rin/default.nix delete mode 100644 users/rin/home.nix diff --git a/flake.nix b/flake.nix index a70a80e..164170e 100644 --- a/flake.nix +++ b/flake.nix @@ -17,10 +17,32 @@ outputs = inputs: with inputs; let + lib = nixpkgs.lib; + getPaths = root: builtins.map (path: root + ("/" + path)) # Prepends root path (builtins.attrNames (builtins.readDir root)); # Reads root path + modules = + let + getName = path: lib.removeSuffix ".nix" ( # Strip extension + lib.last ( # Gets the last part (filename) + lib.splitString "/" ( # Splits the path into components + builtins.toString path # Converts the path into a string + ) + ) + ); + genModulePaths = basePath: builtins.listToAttrs ( + builtins.map (path: { + name = getName path; + value = path; + }) (getPaths basePath) + ); + in { + user = genModulePaths ./modules/user; + system = genModulePaths ./modules/system; + }; + customPackages = pkgs: let callPackage = pkgs.callPackage; @@ -32,7 +54,7 @@ overlays = (builtins.map (path: import path) # Imports path (builtins.filter - (path: nixpkgs.lib.hasSuffix ".nix" path) # Checks file extension + (path: lib.hasSuffix ".nix" path) # Checks file extension (getPaths ./overlays) ) ) ++ [(self: super: customPackages super)] @@ -55,23 +77,23 @@ useGlobalPkgs = true; useUserPackages = true; extraSpecialArgs = { - inherit inputs; + inherit inputs modules; enableGUI = true; }; }; }; in { - nixosConfigurations."winter" = nixpkgs.lib.nixosSystem { + nixosConfigurations."winter" = lib.nixosSystem { system = "x86_64-linux"; modules = [ base home-manager.nixosModules.home-manager - ./hosts/winter + ./hosts/winter.nix secrets.nixosModules.winter ]; specialArgs = { - inherit inputs; + inherit inputs modules; enableGUI = true; }; }; diff --git a/hosts/winter/default.nix b/hosts/winter.nix similarity index 82% rename from hosts/winter/default.nix rename to hosts/winter.nix index b587f5f..7466d65 100644 --- a/hosts/winter/default.nix +++ b/hosts/winter.nix @@ -1,4 +1,4 @@ -{ config, overlays, pkgs, ... }: { +{ config, modules, overlays, pkgs, ... }: { networking.hostName = "winter"; system.stateVersion = "20.09"; @@ -12,17 +12,17 @@ environment.pathsToLink = [ "/share/zsh" ]; users.mutableUsers = false; - imports = [ - ./audio.nix - ./gui.nix - ./hardware-configuration.nix - ./kernel.nix - ./networking.nix - ./packages.nix - ./security.nix - ./snapper.nix + imports = with modules.system; [ + audio + gui + hardware-configuration + kernel + networking + packages + security + snapper - ../../users/rin + ../users/rin.nix ]; nix = rec { package = pkgs.nixUnstable; diff --git a/hosts/winter/audio.nix b/modules/system/audio.nix similarity index 100% rename from hosts/winter/audio.nix rename to modules/system/audio.nix diff --git a/hosts/winter/gui.nix b/modules/system/gui.nix similarity index 100% rename from hosts/winter/gui.nix rename to modules/system/gui.nix diff --git a/hosts/winter/hardware-configuration.nix b/modules/system/hardware-configuration.nix similarity index 100% rename from hosts/winter/hardware-configuration.nix rename to modules/system/hardware-configuration.nix diff --git a/hosts/winter/kernel.nix b/modules/system/kernel.nix similarity index 100% rename from hosts/winter/kernel.nix rename to modules/system/kernel.nix diff --git a/hosts/winter/networking.nix b/modules/system/networking.nix similarity index 100% rename from hosts/winter/networking.nix rename to modules/system/networking.nix diff --git a/hosts/winter/packages.nix b/modules/system/packages.nix similarity index 100% rename from hosts/winter/packages.nix rename to modules/system/packages.nix diff --git a/hosts/winter/security.nix b/modules/system/security.nix similarity index 100% rename from hosts/winter/security.nix rename to modules/system/security.nix diff --git a/hosts/winter/snapper.nix b/modules/system/snapper.nix similarity index 100% rename from hosts/winter/snapper.nix rename to modules/system/snapper.nix diff --git a/users/rin/bspwm.nix b/modules/user/bspwm.nix similarity index 100% rename from users/rin/bspwm.nix rename to modules/user/bspwm.nix diff --git a/users/rin/dunst.nix b/modules/user/dunst.nix similarity index 100% rename from users/rin/dunst.nix rename to modules/user/dunst.nix diff --git a/users/rin/kitty.nix b/modules/user/kitty.nix similarity index 100% rename from users/rin/kitty.nix rename to modules/user/kitty.nix diff --git a/users/rin/mpv.nix b/modules/user/mpv.nix similarity index 100% rename from users/rin/mpv.nix rename to modules/user/mpv.nix diff --git a/users/rin/neovim.nix b/modules/user/neovim.nix similarity index 100% rename from users/rin/neovim.nix rename to modules/user/neovim.nix diff --git a/users/rin/npm.nix b/modules/user/npm.nix similarity index 100% rename from users/rin/npm.nix rename to modules/user/npm.nix diff --git a/users/rin/picom.nix b/modules/user/picom.nix similarity index 100% rename from users/rin/picom.nix rename to modules/user/picom.nix diff --git a/users/rin/polybar.nix b/modules/user/polybar.nix similarity index 97% rename from users/rin/polybar.nix rename to modules/user/polybar.nix index 88ced08..a822a79 100644 --- a/users/rin/polybar.nix +++ b/modules/user/polybar.nix @@ -1,7 +1,7 @@ { config, ... }: { services.polybar = { enable = true; - script = builtins.readFile ./scripts/polybar.sh; + script = builtins.readFile ../../scripts/polybar.sh; settings = { "bar/top" = { monitor = "eDP-1"; diff --git a/users/rin/rofi.nix b/modules/user/rofi.nix similarity index 100% rename from users/rin/rofi.nix rename to modules/user/rofi.nix diff --git a/users/rin/sxhkd.nix b/modules/user/sxhkd.nix similarity index 100% rename from users/rin/sxhkd.nix rename to modules/user/sxhkd.nix diff --git a/users/rin/theming.nix b/modules/user/theming.nix similarity index 100% rename from users/rin/theming.nix rename to modules/user/theming.nix diff --git a/users/rin/xdg.nix b/modules/user/xdg.nix similarity index 100% rename from users/rin/xdg.nix rename to modules/user/xdg.nix diff --git a/users/rin/xorg.nix b/modules/user/xorg.nix similarity index 94% rename from users/rin/xorg.nix rename to modules/user/xorg.nix index 958934f..a7738f4 100644 --- a/users/rin/xorg.nix +++ b/modules/user/xorg.nix @@ -6,7 +6,7 @@ scriptPath = ".config/xorg/xsession"; }; - xdg.configFile."xorg/xinitrc".source = ./scripts/xinitrc; + xdg.configFile."xorg/xinitrc".source = ../../scripts/xinitrc; xdg.configFile."xorg/wallpaper.png".source = ../../res/wallpaper.png; xresources = { path = "${config.xdg.configHome}/xorg/xresources"; diff --git a/users/rin/zsh.nix b/modules/user/zsh.nix similarity index 100% rename from users/rin/zsh.nix rename to modules/user/zsh.nix diff --git a/users/rin/scripts/osu b/scripts/osu similarity index 100% rename from users/rin/scripts/osu rename to scripts/osu diff --git a/users/rin/scripts/polybar.sh b/scripts/polybar.sh similarity index 100% rename from users/rin/scripts/polybar.sh rename to scripts/polybar.sh diff --git a/users/rin/scripts/xinitrc b/scripts/xinitrc similarity index 100% rename from users/rin/scripts/xinitrc rename to scripts/xinitrc diff --git a/users/rin.nix b/users/rin.nix new file mode 100644 index 0000000..0dcce47 --- /dev/null +++ b/users/rin.nix @@ -0,0 +1,138 @@ +{ config, lib, modules, pkgs, ... }: { + users.users.rin = { + isNormalUser = true; + extraGroups = [ "audio" "video" "wheel" ]; + shell = pkgs.zsh; + uid = 1001; + }; + home-manager.users.rin = { config, enableGUI, lib, pkgs, ... }: { + home = { + username = "rin"; + homeDirectory = "/home/rin"; + stateVersion = "21.05"; + packages = with pkgs; [ + ffmpeg + gnupg + neofetch + nodejs-16_x + pamixer + rnix-lsp + transcrypt + unrar + wine-osu + (winetricks.override { wine = wine-osu; }) + youtube-dl + + nodePackages_latest.pnpm + ] ++ lib.optionals enableGUI [ + brave + discord-canary + element-desktop + feh + gnome.file-roller + gimp + kotatogram-desktop + lxappearance + maim + pavucontrol + tor-browser-bundle-bin + transmission-remote-gtk + xclip + xorg.xgamma + ]; + + sessionVariables = { + PATH = builtins.concatStringsSep ":" [ + "${config.home.homeDirectory}/.local/bin" + "${config.xdg.dataHome}/npm/bin" + "$PATH" + ]; + + XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority"; + EDITOR = "nvim"; + + _JAVA_OPTIONS = "-Djava.util.prefs.userRoot=${config.xdg.configHome}/java"; + CARGO_HOME = "${config.xdg.dataHome}/cargo"; + DIRENV_LOG_FORMAT = ""; + GNUPGHOME = "${config.xdg.dataHome}/gnupg"; + GTK2_RC_FILES = "${config.xdg.configHome}/gtk-2.0/gtkrc"; + LESSHISTFILE = "-"; + NODE_REPL_HISTORY="${config.xdg.dataHome}/nodejs/repl_history"; + NPM_CONFIG_USERCONFIG = "${config.xdg.configHome}/npm/npmrc"; + PUB_CACHE = "${config.xdg.cacheHome}/dart"; + WGETRC = "${config.xdg.configHome}/wgetrc"; + XINITRC = "${config.xdg.configHome}/xorg/xinitrc"; + + WINEPREFIX = "${config.xdg.dataHome}/wine64"; + WINEARCH = "win64"; + }; + }; + + imports = with modules.user; [ + neovim + npm + zsh + ] ++ lib.optionals enableGUI [ + theming + xdg + + kitty + mpv + rofi + + dunst + picom + polybar + + xorg + sxhkd + bspwm + ]; + + programs = { + feh.enable = enableGUI; + + direnv = { + enable = true; + nix-direnv = { + enable = true; + enableFlakes = true; + }; + }; + git = { + enable = true; + userName = "LavaDesu"; + userEmail = "me@lava.moe"; + signing = { + key = "059F098EBF0E9A13E10A46BF6500251E087653C9"; + signByDefault = true; + }; + extraConfig = { + core.abbrev = 11; + }; + }; + gpg = { + enable = true; + homedir = "${config.xdg.dataHome}/gnupg"; + }; + }; + + services = { + # TODO: borked + clipmenu.enable = false; + gpg-agent = { + enable = true; + pinentryFlavor = if enableGUI then "gnome3" else "tty"; + }; + }; + + home.file.".local/bin/ipc-bridge.exe".source = builtins.fetchurl { + url = "https://github.com/0e4ef622/wine-discord-ipc-bridge/releases/download/v0.0.1/winediscordipcbridge.exe"; + sha256 = "1swn9spxpq6blm74kjmfz4ipq6a8qjzccvb2msb25pf5b1z7jnns"; + }; + home.file.".local/bin/osu" = { + executable = true; + source = ../scripts/osu; + }; + }; +} diff --git a/users/rin/default.nix b/users/rin/default.nix deleted file mode 100644 index dd9a585..0000000 --- a/users/rin/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ config, pkgs, ... }: { - users.users.rin = { - isNormalUser = true; - extraGroups = [ "audio" "video" "wheel" ]; - shell = pkgs.zsh; - uid = 1001; - }; - home-manager.users.rin = import ./home.nix; -} diff --git a/users/rin/home.nix b/users/rin/home.nix deleted file mode 100644 index b11d753..0000000 --- a/users/rin/home.nix +++ /dev/null @@ -1,130 +0,0 @@ -{ config, enableGUI, lib, pkgs, ... }: { - home = { - username = "rin"; - homeDirectory = "/home/rin"; - stateVersion = "21.05"; - packages = with pkgs; [ - ffmpeg - gnupg - neofetch - nodejs-16_x - pamixer - rnix-lsp - transcrypt - unrar - wine-osu - (winetricks.override { wine = wine-osu; }) - youtube-dl - - nodePackages_latest.pnpm - ] ++ lib.optionals enableGUI [ - brave - discord-canary - element-desktop - feh - gnome.file-roller - gimp - kotatogram-desktop - lxappearance - maim - pavucontrol - tor-browser-bundle-bin - transmission-remote-gtk - xclip - xorg.xgamma - ]; - - sessionVariables = { - PATH = builtins.concatStringsSep ":" [ - "${config.home.homeDirectory}/.local/bin" - "${config.xdg.dataHome}/npm/bin" - "$PATH" - ]; - - XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority"; - EDITOR = "nvim"; - - _JAVA_OPTIONS = "-Djava.util.prefs.userRoot=${config.xdg.configHome}/java"; - CARGO_HOME = "${config.xdg.dataHome}/cargo"; - DIRENV_LOG_FORMAT = ""; - GNUPGHOME = "${config.xdg.dataHome}/gnupg"; - GTK2_RC_FILES = "${config.xdg.configHome}/gtk-2.0/gtkrc"; - LESSHISTFILE = "-"; - NODE_REPL_HISTORY="${config.xdg.dataHome}/nodejs/repl_history"; - NPM_CONFIG_USERCONFIG = "${config.xdg.configHome}/npm/npmrc"; - PUB_CACHE = "${config.xdg.cacheHome}/dart"; - WGETRC = "${config.xdg.configHome}/wgetrc"; - XINITRC = "${config.xdg.configHome}/xorg/xinitrc"; - - WINEPREFIX = "${config.xdg.dataHome}/wine64"; - WINEARCH = "win64"; - }; - }; - - imports = [ - ./neovim.nix - ./npm.nix - ./zsh.nix - ] ++ lib.optionals enableGUI [ - ./theming.nix - ./xdg.nix - - ./kitty.nix - ./mpv.nix - ./rofi.nix - - ./dunst.nix - ./picom.nix - ./polybar.nix - - ./xorg.nix - ./sxhkd.nix - ./bspwm.nix - ]; - - programs = { - feh.enable = enableGUI; - - direnv = { - enable = true; - nix-direnv = { - enable = true; - enableFlakes = true; - }; - }; - git = { - enable = true; - userName = "LavaDesu"; - userEmail = "me@lava.moe"; - signing = { - key = "059F098EBF0E9A13E10A46BF6500251E087653C9"; - signByDefault = true; - }; - extraConfig = { - core.abbrev = 11; - }; - }; - gpg = { - enable = true; - homedir = "${config.xdg.dataHome}/gnupg"; - }; - }; - - services = { - # TODO: borked - clipmenu.enable = false; - gpg-agent = { - enable = true; - pinentryFlavor = if enableGUI then "gnome3" else "tty"; - }; - }; - - home.file.".local/bin/ipc-bridge.exe".source = builtins.fetchurl { - url = "https://github.com/0e4ef622/wine-discord-ipc-bridge/releases/download/v0.0.1/winediscordipcbridge.exe"; - sha256 = "1swn9spxpq6blm74kjmfz4ipq6a8qjzccvb2msb25pf5b1z7jnns"; - }; - home.file.".local/bin/osu" = { - executable = true; - source = ./scripts/osu; - }; -}