From d0c059e25e882a927a236c7f29100ad627ad7c5a Mon Sep 17 00:00:00 2001 From: Whovian9369 Date: Mon, 13 May 2024 23:18:54 -0400 Subject: [PATCH] First try of a slightly cleaner version. --- flake.lock | 18 --- flake.nix | 23 ++- home/aliases.nix | 16 ++ home/dotfiles.nix | 37 +++++ home/home.nix | 231 ++++++----------------------- home/pkgs_and_programs.nix | 117 +++++++++++++++ home/variables.nix | 14 ++ system/nixos-wsl/configuration.nix | 39 +++++ system/nixos-wsl/packages.nix | 52 +++++++ system/nixos-wsl/users.nix | 22 +++ system/nixos-wsl/wsl.nix | 12 ++ 11 files changed, 361 insertions(+), 220 deletions(-) create mode 100644 home/aliases.nix create mode 100644 home/dotfiles.nix create mode 100644 home/pkgs_and_programs.nix create mode 100644 home/variables.nix create mode 100644 system/nixos-wsl/configuration.nix create mode 100644 system/nixos-wsl/packages.nix create mode 100644 system/nixos-wsl/users.nix create mode 100644 system/nixos-wsl/wsl.nix diff --git a/flake.lock b/flake.lock index dd2fa1e..4689400 100644 --- a/flake.lock +++ b/flake.lock @@ -83,23 +83,6 @@ "type": "github" } }, - "my_packages": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1715061149, - "narHash": "sha256-ZM13/Z/7W9POKVIoMIJzRRzKY8v9oMD1nhLdXej0pFY=", - "path": "/home/whovian/.flakes", - "type": "path" - }, - "original": { - "path": "/home/whovian/.flakes", - "type": "path" - } - }, "nix-index-database": { "inputs": { "nixpkgs": [ @@ -181,7 +164,6 @@ "agenix": "agenix", "flake-utils": "flake-utils", "home-manager": "home-manager", - "my_packages": "my_packages", "nix-index-database": "nix-index-database", "nix-systems_default": "nix-systems_default", "nixos-wsl": "nixos-wsl", diff --git a/flake.nix b/flake.nix index fcc27ef..500ce13 100644 --- a/flake.nix +++ b/flake.nix @@ -31,11 +31,6 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - my_packages = { - url = "/home/whovian/.flakes"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - xil = { url = "github:Qyriad/Xil"; inputs.nixpkgs.follows = "nixpkgs"; @@ -71,13 +66,13 @@ # Needed self, nixpkgs, nixos-wsl, # Added by me - agenix, home-manager, my_packages, nix-index-database, xil, ... }: + agenix, home-manager, nix-index-database, xil, ... }: { nixosConfigurations = { nixos-wsl = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ - ./system/configuration.nix + ./system/nixos-wsl/configuration.nix nixos-wsl.nixosModules.wsl home-manager.nixosModules.home-manager { @@ -87,21 +82,23 @@ useGlobalPkgs = true; useUserPackages = true; sharedModules = [ - ./home/home.nix agenix.homeManagerModules.default nix-index-database.hmModules.nix-index ]; - users.whovian.home.packages = [ - agenix.packages.x86_64-linux.default - ]; + users.whovian = ./home/home.nix; # Optionally, use home-manager.extraSpecialArgs to pass arguments to home.nix extraSpecialArgs = { system = "x86_64-linux"; - inherit my_packages; inherit xil; - my_pkgs = my_packages.packages.x86_64-linux; + inherit nixpkgs; + pkgs = import nixpkgs { + system = "x86_64-linux"; + }; + inherit agenix; + # inherit my_packages; + # my_pkgs = my_packages.packages.x86_64-linux; }; }; } diff --git a/home/aliases.nix b/home/aliases.nix new file mode 100644 index 0000000..11d71af --- /dev/null +++ b/home/aliases.nix @@ -0,0 +1,16 @@ +{ + home.shellAliases = { + # From Windows "%PATH%" + "adb" = "adb.exe"; + "caja" = "explorer.exe"; + "hactoolnet" = "hactoolnet.exe"; + "mpv" = "mpv.com"; + "tailscale" = "tailscale.exe"; + "yt-dlp" = "yt-dlp.exe"; + "7zexe" = "/mnt/c/Program\\ Files/7-Zip/7z.exe"; + + # From Nix environment + "7z" = "7zz"; + # "7zz" is from "nixpkgs#_7zz" + }; +} diff --git a/home/dotfiles.nix b/home/dotfiles.nix new file mode 100644 index 0000000..72e36b5 --- /dev/null +++ b/home/dotfiles.nix @@ -0,0 +1,37 @@ +{ + home.file = { + /* + # Building this configuration will create a copy of 'dotfiles/screenrc' in + # the Nix store. Activating the configuration will then make '~/.screenrc' a + # symlink to the Nix store copy. + ".screenrc".source = dotfiles/screenrc; + + # You can also set the file content immediately. + ".gradle/gradle.properties".text = '' + org.gradle.console=verbose + org.gradle.daemon.idletimeout=3600000 + ''; + */ + + ".zshrc".text = '' + eval "$(direnv hook zsh)" + + download_nixpkgs_cache_index () { + filename="index-$(uname -m | sed 's/^arm64$/aarch64/')-$(uname | tr A-Z a-z)" + mkdir -p ~/.cache/nix-index && cd ~/.cache/nix-index + # -N will only download a new version if there is an update. + wget -q -N https://github.com/Mic92/nix-index-database/releases/latest/download/$filename + ln -f $filename files + } + ''; + + ".lftp/rc".text = '' + alias s32 "mirror -c --use-pget-n=32" + alias p32 "pget -n 32 -c" + alias p16 "pget -n 16 -c" + alias s16 "mirror -c --use-pget-n=16" + alias p8 "pget -n 8 -c" + alias ssl "set ssl:verify-certificate false" + ''; + }; +} diff --git a/home/home.nix b/home/home.nix index cf71032..97f88cd 100644 --- a/home/home.nix +++ b/home/home.nix @@ -1,94 +1,55 @@ { + lib, + agenix, config, + modulesPath, + nixosConfig, + nixpkgs, + options, + osConfig, pkgs, - my_pkgs, - xil, + specialArgs, system, - ... + xil }: - { - # Home Manager needs a bit of information about you and the paths it should - # manage. - home.username = "whovian"; - home.homeDirectory = "/home/whovian"; + imports = [ + ./pkgs_and_programs.nix # home.packages and programs + ./dotfiles.nix # home.file + ./variables.nix # home.sessionVariables + ./aliases.nix # home.shellAliases + ]; - /* - This value determines the Home Manager release that your configuration is - compatible with. This helps avoid breakage when a new Home Manager release - introduces backwards incompatible changes. - - You should not change this value, even if you update Home Manager. If you do - want to update the value, then make sure to first check the Home Manager - release notes. - */ - home.stateVersion = "23.05"; # Please read the comment before changing. + home = { + # Home Manager needs a bit of information about you and the paths it should + # manage. + username = "whovian"; + homeDirectory = "/home/whovian"; - # The home.packages option allows you to install Nix packages into your - # environment. - nixpkgs = { - config = { - allowUnfree = true; - }; + /* + This value determines the Home Manager release that your configuration is + compatible with. This helps avoid breakage when a new Home Manager release + introduces backwards incompatible changes. + + You should not change this value, even if you update Home Manager. If you do + want to update the value, then make sure to first check the Home Manager + release notes. + */ + stateVersion = "23.05"; # Please read the comment before changing. + + # The home.packages option allows you to install Nix packages into your + # environment. + + # Let Home Manager install and manage itself. + # Probably not needed for a module? + # programs.home-manager.enable = true; }; - home.packages = [ - pkgs._7zz - pkgs.bat - pkgs.binwalk - pkgs.cdecrypt - pkgs.colorized-logs - pkgs.croc - pkgs.dhex - pkgs.fd - pkgs.file - pkgs.gdrive3 - pkgs.git - pkgs.hactool - pkgs.instaloader - pkgs.internetarchive - pkgs.lynx - pkgs.megatools - pkgs.ncdu - pkgs.nixfmt-classic - pkgs.progress - pkgs.pyrosimple - pkgs.python3 - pkgs.quickbms - pkgs.rclone - pkgs.screen - pkgs.sshfs - pkgs.unrar-wrapper - pkgs.wget - pkgs.xxd - pkgs.yq - - # my_pkgs.irdkit - my_pkgs.ird_tools - my_pkgs.rom-properties - - xil.packages.${system}.xil - ]; - - /* - Disabled - pkgs.binutils - # Instead just do `nix shell nixpkgs#binutils -c strings -- INPUT.ext > INPUT.ext.strings - pkgs.mpv - pkgs.terminator - pkgs.yt-dlp - pkgs.p7zip - # Replaced in favour of nixpkgs#_7zz - Disabled - */ - - /* - # It is sometimes useful to fine-tune packages, for example, by applying - # overrides. You can do that directly here, just don't forget the - # parentheses. Maybe you want to install Nerd Fonts with a limited number of - # fonts? - (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) - */ + # nixpkgs = { + # config = { + # allowUnfree = true; + # }; + # }; age = { identityPaths = [ @@ -106,112 +67,4 @@ }; }; }; - - programs = { - bat = { - enable = true; - }; - direnv = { - enable = true; - enableBashIntegration = true; - enableZshIntegration = true; - nix-direnv.enable = true; - }; - git = { - enable = true; - userName = "Whovian9369"; - userEmail = "Whovian9369@gmail.com"; - extraConfig = { - init = { - defaultBranch = "main"; - }; - }; - }; - jq = { - enable = true; - }; - nix-index = { - enable = true; - enableZshIntegration = false; - }; - ripgrep = { - enable = true; - }; - zsh = { - enable = true; - # Honestly unsure if I should be using `programs.zsh.envExtra` or - # `programs.zsh.localVariables` here. - localVariables = { - DISABLE_MAGIC_FUNCTIONS = true; - }; - # enableAutosuggestions = true; - # enableCompletion = true; - oh-my-zsh = { - enable = true; - plugins = [ - "git" - "sudo" - ]; - theme = "bira"; - }; - }; - }; - - home.file = { - /* - # Building this configuration will create a copy of 'dotfiles/screenrc' in - # the Nix store. Activating the configuration will then make '~/.screenrc' a - # symlink to the Nix store copy. - ".screenrc".source = dotfiles/screenrc; - - # You can also set the file content immediately. - ".gradle/gradle.properties".text = '' - org.gradle.console=verbose - org.gradle.daemon.idletimeout=3600000 - ''; - */ - - ".zshrc".text = '' - eval "$(direnv hook zsh)" - - download_nixpkgs_cache_index () { - filename="index-$(uname -m | sed 's/^arm64$/aarch64/')-$(uname | tr A-Z a-z)" - mkdir -p ~/.cache/nix-index && cd ~/.cache/nix-index - # -N will only download a new version if there is an update. - wget -q -N https://github.com/Mic92/nix-index-database/releases/latest/download/$filename - ln -f $filename files - } - ''; - - ".lftp/rc".text = '' - alias s32 "mirror -c --use-pget-n=32" - alias p32 "pget -n 32 -c" - alias p16 "pget -n 16 -c" - alias s16 "mirror -c --use-pget-n=16" - alias p8 "pget -n 8 -c" - alias ssl "set ssl:verify-certificate false" - ''; - }; - - home.sessionVariables = { - EDITOR = "nano"; - DOTNET_CLI_TELEMETRY_OPTOUT = "1"; - OPENAI_API_KEY = "\$(cat ${config.age.secrets."openai".path})"; - CURSEFORGE_API_KEY = "\$(cat ${config.age.secrets."cursed".path})"; - ITCHIO_API_KEY = "\$(cat ${config.age.secrets."itchy".path})"; - }; - - home.shellAliases = { - "adb" = "adb.exe"; - "caja" = "explorer.exe"; - "hactoolnet" = "hactoolnet.exe"; - "mpv" = "mpv.com"; - "tailscale" = "tailscale.exe"; - "yt-dlp" = "yt-dlp.exe"; - "7zexe" = "/mnt/c/Program\\ Files/7-Zip/7z.exe"; - "7z" = "7zz"; - }; - - # Let Home Manager install and manage itself. - programs.home-manager.enable = true; } diff --git a/home/pkgs_and_programs.nix b/home/pkgs_and_programs.nix new file mode 100644 index 0000000..f8cdc13 --- /dev/null +++ b/home/pkgs_and_programs.nix @@ -0,0 +1,117 @@ +{ + agenix, + pkgs, + system, + xil, + ... +}: +{ + programs = { + bat = { + enable = true; + }; + direnv = { + enable = true; + enableBashIntegration = true; + enableZshIntegration = true; + nix-direnv.enable = true; + }; + git = { + enable = true; + userName = "Whovian9369"; + userEmail = "Whovian9369@gmail.com"; + extraConfig = { + init = { + defaultBranch = "main"; + }; + }; + }; + jq = { + enable = true; + }; + nix-index = { + enable = false; + }; + ripgrep = { + enable = true; + }; + zsh = { + enable = true; + # Honestly unsure if I should be using `programs.zsh.envExtra` or + # `programs.zsh.localVariables` here. + localVariables = { + DISABLE_MAGIC_FUNCTIONS = true; + }; + # enableAutosuggestions = true; + # enableCompletion = true; + oh-my-zsh = { + enable = true; + plugins = [ + "git" + "sudo" + ]; + theme = "bira"; + }; + }; + }; + + home.packages = [ + pkgs._7zz + pkgs.bat + pkgs.binwalk + pkgs.cdecrypt + pkgs.colorized-logs + pkgs.croc + pkgs.dhex + pkgs.fd + pkgs.file + pkgs.gdrive3 + pkgs.git + pkgs.hactool + pkgs.instaloader + pkgs.internetarchive + pkgs.lynx + pkgs.megatools + pkgs.ncdu + pkgs.nixfmt-classic + pkgs.progress + pkgs.pyrosimple + pkgs.python3 + pkgs.quickbms + pkgs.rclone + pkgs.screen + pkgs.sshfs + pkgs.unrar-wrapper + pkgs.wget + pkgs.xxd + pkgs.yq + + # my_pkgs.irdkit + # my_pkgs.ird_tools + # my_pkgs.rom-properties + + agenix.packages.${system}.default + xil.packages.${system}.xil + ]; + + /* + Disabled + pkgs.binutils + # Instead just do `nix shell nixpkgs#binutils -c strings -- INPUT.ext > INPUT.ext.strings + pkgs.mpv + pkgs.terminator + pkgs.yt-dlp + pkgs.p7zip + # Replaced in favour of nixpkgs#_7zz + Disabled + */ + + /* + # It is sometimes useful to fine-tune packages, for example, by applying + # overrides. You can do that directly here, just don't forget the + # parentheses. Maybe you want to install Nerd Fonts with a limited number of + # fonts? + (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) + */ + +} diff --git a/home/variables.nix b/home/variables.nix new file mode 100644 index 0000000..452d5de --- /dev/null +++ b/home/variables.nix @@ -0,0 +1,14 @@ +{ + agenix, + config, + ... +}: +{ + home.sessionVariables = { + EDITOR = "nano"; + DOTNET_CLI_TELEMETRY_OPTOUT = "1"; + OPENAI_API_KEY = "\$(cat ${config.age.secrets."openai".path})"; + CURSEFORGE_API_KEY = "\$(cat ${config.age.secrets."cursed".path})"; + ITCHIO_API_KEY = "\$(cat ${config.age.secrets."itchy".path})"; + }; +} diff --git a/system/nixos-wsl/configuration.nix b/system/nixos-wsl/configuration.nix new file mode 100644 index 0000000..f5994b3 --- /dev/null +++ b/system/nixos-wsl/configuration.nix @@ -0,0 +1,39 @@ +{ lib, + pkgs, + config, + modulesPath, + nixos-wsl, + ... +}: + +{ + imports = [ + ./packages.nix + ./users.nix + ./wsl.nix + ]; + + networking.hostName = "nixos-wsl"; + + # Enable nix flakes + nix.settings.experimental-features = [ + "nix-command" + "flakes" + ]; + + time.timeZone = "America/New_York"; + + /* + Add environment.pathsToLink for auto-completion for system packages (e.g. systemd). + Appears to be required due to [GitHub - nix-community/home-manager]: + https://github.com/nix-community/home-manager/blob/c781b28add41b74423ab2e64496d4fc91192e13a/modules/programs/zsh.nix#L348-L358 + [/modules/programs/zsh.nix] + https://github.com/nix-community/home-manager/issues/3521#issuecomment-1367197995 + [Issue #3521] + */ + environment.pathsToLink = [ + "/share/zsh" + ]; + + system.stateVersion = "22.05"; +} diff --git a/system/nixos-wsl/packages.nix b/system/nixos-wsl/packages.nix new file mode 100644 index 0000000..7316143 --- /dev/null +++ b/system/nixos-wsl/packages.nix @@ -0,0 +1,52 @@ +{ lib, agenix, pkgs, config, modulesPath, ... }: +{ + environment.systemPackages = [ + pkgs.file + pkgs.xterm + # `agenix` is currently added via + # ".nixos-wsl.modules.environment.systemPackages" + ]; + + + nixpkgs = { + config = { + allowUnfree = true; + }; + }; + + programs = { + zsh = { + enable = true; + }; + nano = { + enable = true; + }; + + # I haven't figured out how to get `cdemu` properly working (in WSL), so + # I'm just going to leave it as `programs.cdemu.enable = false;` for now. + + cdemu = { + enable = false; + group = "cdrom"; + gui = false; + image-analyzer = false; + }; + }; + + # `documentation.man.generateCaches` seems to be mainly useful for `whatis`, + # but I couldn't really get it working well. + # From what I can tell, it depends on a package being installed via + # `environment.systemPackages`, *and* for that package to have a manpage. + # That's kinda useless for me since I've been mostly installing stuff via + # `home-manager`, sooooooooo... + /* + documentation = { + nixos = { + includeAllModules = true; + }; + man = { + generateCaches = true; + }; + }; + */ +} diff --git a/system/nixos-wsl/users.nix b/system/nixos-wsl/users.nix new file mode 100644 index 0000000..cc1664b --- /dev/null +++ b/system/nixos-wsl/users.nix @@ -0,0 +1,22 @@ +{ lib, + pkgs, + config, + modulesPath, + ... +}: +{ + users = { + users = { + whovian = { + name = "whovian"; + description = "Whovian9369"; + extraGroups = [ + "wheel" + "cdrom" + ]; + shell = pkgs.zsh; + initialPassword = "abcde"; # I need to log in somehow + }; + }; + }; +} diff --git a/system/nixos-wsl/wsl.nix b/system/nixos-wsl/wsl.nix new file mode 100644 index 0000000..53ea6d9 --- /dev/null +++ b/system/nixos-wsl/wsl.nix @@ -0,0 +1,12 @@ +{ + wsl = { + enable = true; + defaultUser = "whovian"; + startMenuLaunchers = false; + wslConf = { + automount = { + root = "/mnt"; + }; + }; + }; +}