From cd0b7debd428f5fa6bb61c5f823e7b67be63af86 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sat, 8 Mar 2025 18:08:17 -0500 Subject: [PATCH] running vm that mostly works --- flake.nix | 112 +++++++++--------- hosts-by-platform/x86_64-linux/staff.nix | 13 ++ overlays/pkgs.nix | 11 -- pkgs/tools/misc/osc/package.nix | 1 - .../nmasur/presets/programs/dotfiles.nix | 8 +- .../nmasur/presets/programs/nix-index.nix | 40 +++++++ .../nmasur/presets/programs/nixpkgs.nix | 60 ---------- .../nmasur/presets/services/loadkey.nix | 15 ++- .../modules/nmasur/presets/services/nix.nix | 62 ++++++++++ .../nmasur/presets/services/polybar.nix | 1 + .../modules/nmasur/profiles/common.nix | 1 + .../modules/nmasur/profiles/power-user.nix | 1 + .../nmasur/presets/services/lightdm.nix | 7 +- .../nixos/modules/nmasur/profiles/base.nix | 7 ++ .../nixos/modules/nmasur/profiles/gui.nix | 4 +- 15 files changed, 204 insertions(+), 139 deletions(-) create mode 100644 platforms/home-manager/modules/nmasur/presets/programs/nix-index.nix create mode 100644 platforms/home-manager/modules/nmasur/presets/services/nix.nix diff --git a/flake.nix b/flake.nix index 39a636b..aa91c69 100644 --- a/flake.nix +++ b/flake.nix @@ -344,8 +344,6 @@ darwinModules = aarch64-darwin-hosts; inherit buildDarwin pkgsBySystem; - # buildDarwin = buildDarwin; - # pkgsBySystem = pkgsBySystem; # Contains my full system builds, including home-manager # nixos-rebuild switch --flake .#tempest @@ -390,60 +388,64 @@ root = import ./disks/root.nix; }; - packages = - let - staff = - system: - import ./hosts/staff { - inherit - inputs - globals - overlays - system - ; - }; - neovim = - system: - let - pkgs = import nixpkgs { inherit system overlays; }; - in - import ./modules/common/neovim/package { - inherit pkgs; - colors = (import ./colorscheme/gruvbox-dark).dark; - }; - in - { - x86_64-linux.staff = staff "x86_64-linux"; - x86_64-linux.arrow = inputs.nixos-generators.nixosGenerate rec { - system = "x86_64-linux"; - format = "iso"; - modules = import ./hosts/arrow/modules.nix { inherit inputs globals overlays; }; - }; - x86_64-linux.arrow-aws = inputs.nixos-generators.nixosGenerate rec { - system = "x86_64-linux"; - format = "amazon"; - modules = import ./hosts/arrow/modules.nix { inherit inputs globals overlays; } ++ [ - ( - { ... }: - { - boot.kernelPackages = inputs.nixpkgs.legacyPackages.x86_64-linux.linuxKernel.packages.linux_6_6; - amazonImage.sizeMB = 16 * 1024; - permitRootLogin = "prohibit-password"; - boot.loader.systemd-boot.enable = inputs.nixpkgs.lib.mkForce false; - boot.loader.efi.canTouchEfiVariables = inputs.nixpkgs.lib.mkForce false; - services.amazon-ssm-agent.enable = true; - users.users.ssm-user.extraGroups = [ "wheel" ]; - } - ) - ]; - }; + # packages = + # let + # staff = + # system: + # import ./hosts/staff { + # inherit + # inputs + # globals + # overlays + # system + # ; + # }; + # neovim = + # system: + # let + # pkgs = import nixpkgs { inherit system overlays; }; + # in + # import ./modules/common/neovim/package { + # inherit pkgs; + # colors = (import ./colorscheme/gruvbox-dark).dark; + # }; + # in + # { + # x86_64-linux.staff = staff "x86_64-linux"; + # x86_64-linux.arrow = inputs.nixos-generators.nixosGenerate rec { + # system = "x86_64-linux"; + # format = "iso"; + # modules = import ./hosts/arrow/modules.nix { inherit inputs globals overlays; }; + # }; + # x86_64-linux.arrow-aws = inputs.nixos-generators.nixosGenerate rec { + # system = "x86_64-linux"; + # format = "amazon"; + # modules = import ./hosts/arrow/modules.nix { inherit inputs globals overlays; } ++ [ + # ( + # { ... }: + # { + # boot.kernelPackages = inputs.nixpkgs.legacyPackages.x86_64-linux.linuxKernel.packages.linux_6_6; + # amazonImage.sizeMB = 16 * 1024; + # permitRootLogin = "prohibit-password"; + # boot.loader.systemd-boot.enable = inputs.nixpkgs.lib.mkForce false; + # boot.loader.efi.canTouchEfiVariables = inputs.nixpkgs.lib.mkForce false; + # services.amazon-ssm-agent.enable = true; + # users.users.ssm-user.extraGroups = [ "wheel" ]; + # } + # ) + # ]; + # }; - # Package Neovim config into standalone package - x86_64-linux.neovim = neovim "x86_64-linux"; - x86_64-darwin.neovim = neovim "x86_64-darwin"; - aarch64-linux.neovim = neovim "aarch64-linux"; - aarch64-darwin.neovim = neovim "aarch64-darwin"; - }; + # # Package Neovim config into standalone package + # x86_64-linux.neovim = neovim "x86_64-linux"; + # x86_64-darwin.neovim = neovim "x86_64-darwin"; + # aarch64-linux.neovim = neovim "aarch64-linux"; + # aarch64-darwin.neovim = neovim "aarch64-darwin"; + # }; + + mypackages = forAllSystems (system: pkgsBySystem.${system}.nmasur); + + packages = mypackages; # Programs that can be run by calling this flake apps = forAllSystems ( diff --git a/hosts-by-platform/x86_64-linux/staff.nix b/hosts-by-platform/x86_64-linux/staff.nix index 4df102e..f33d822 100644 --- a/hosts-by-platform/x86_64-linux/staff.nix +++ b/hosts-by-platform/x86_64-linux/staff.nix @@ -16,6 +16,19 @@ rec { gui.enable = true; }; nmasur.presets.services.cloudflared.enable = false; + nmasur.presets.services.kanata.enable = false; + nmasur.presets.services.openssh.enable = true; + + virtualisation.vmVariant = { + home-manager.users."noah".nmasur.presets.programs.nix-index.enable = false; + virtualisation.forwardPorts = [ + { + from = "host"; + host.port = 2222; + guest.port = 22; + } + ]; + }; home-manager.users."noah" = { nmasur.settings = { diff --git a/overlays/pkgs.nix b/overlays/pkgs.nix index b78a862..2d6fce3 100644 --- a/overlays/pkgs.nix +++ b/overlays/pkgs.nix @@ -1,16 +1,6 @@ _inputs: _final: prev: let - # TODO: Remove - # listToAttrsByField = - # field: list: - # builtins.listToAttrs ( - # map (v: { - # name = v.${field}; - # value = v; - # }) list - # ); - listToAttrsByPnameOrName = list: builtins.listToAttrs ( @@ -20,7 +10,6 @@ let }) list ); lib = prev.lib; - # packagesDirectory = lib.filesystem.listFilesRecursive ../pkgs; # [ package1/package.nix package2/package.nix package2/hello.sh ] packages = lib.pipe (lib.filesystem.listFilesRecursive ../pkgs) [ # Get only files called package.nix diff --git a/pkgs/tools/misc/osc/package.nix b/pkgs/tools/misc/osc/package.nix index da5ee90..c743353 100644 --- a/pkgs/tools/misc/osc/package.nix +++ b/pkgs/tools/misc/osc/package.nix @@ -1,7 +1,6 @@ # Clipboard over SSH { - lib, buildGoModule, fetchFromGitHub, ... diff --git a/platforms/home-manager/modules/nmasur/presets/programs/dotfiles.nix b/platforms/home-manager/modules/nmasur/presets/programs/dotfiles.nix index 4cee933..00f786e 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/dotfiles.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/dotfiles.nix @@ -36,9 +36,11 @@ in # Always clone dotfiles repository if it doesn't exist cloneDotfiles = config.lib.dag.entryAfter [ "writeBoundary" "loadkey" ] '' - if [ ! -d "${cfg.path}" ]; then - run mkdir --parents $VERBOSE_ARG $(dirname "${cfg.path}") - run ${lib.getExe pkgs.git} clone ${cfg.repo} "${cfg.path}" + if [ -f ~/.ssh/id_ed25519 ]; then + if [ ! -d "${cfg.path}" ]; then + run mkdir --parents $VERBOSE_ARG $(dirname "${cfg.path}") + run ${lib.getExe pkgs.git} clone ${cfg.repo} "${cfg.path}" + fi fi ''; }; diff --git a/platforms/home-manager/modules/nmasur/presets/programs/nix-index.nix b/platforms/home-manager/modules/nmasur/presets/programs/nix-index.nix new file mode 100644 index 0000000..479b16e --- /dev/null +++ b/platforms/home-manager/modules/nmasur/presets/programs/nix-index.nix @@ -0,0 +1,40 @@ +{ + config, + pkgs, + lib, + ... +}: + +let + cfg = config.nmasur.presets.programs.nix-index; +in + +{ + + options.nmasur.presets.programs.nix-index.enable = + lib.mkEnableOption "nix-index caching for command line"; + + config = lib.mkIf cfg.enable { + + # Provides "command-not-found" options + programs.nix-index = { + enable = true; + enableFishIntegration = true; + }; + + # Create nix-index if doesn't exist + home.activation.createNixIndex = + let + cacheDir = "${config.xdg.cacheHome}/nix-index"; + in + lib.mkIf config.programs.nix-index.enable ( + config.lib.dag.entryAfter [ "writeBoundary" ] '' + if [ ! -d ${cacheDir} ]; then + run ${pkgs.nix-index}/bin/nix-index -f ${pkgs.path} + fi + '' + ); + + }; + +} diff --git a/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix b/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix index 876f168..2a16041 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix @@ -90,66 +90,6 @@ in bind -M default \x11F nix-fzf ''; - # Provides "command-not-found" options - programs.nix-index = { - enable = true; - enableFishIntegration = true; - }; - - # Create nix-index if doesn't exist - home.activation.createNixIndex = - let - cacheDir = "${config.xdg.cacheHome}/nix-index"; - in - lib.mkIf config.programs.nix-index.enable ( - config.lib.dag.entryAfter [ "writeBoundary" ] '' - if [ ! -d ${cacheDir} ]; then - $DRY_RUN_CMD ${pkgs.nix-index}/bin/nix-index -f ${pkgs.path} - fi - '' - ); - - nix = { - - # Set channel to flake packages, used for nix-shell commands - nixPath = [ "nixpkgs=${pkgs.path}" ]; - - # For security, only allow specific users - settings.allowed-users = [ - "@wheel" # Anyone in the wheel group - config.home.username # The current user - ]; - - # Enable features in Nix commands - extraOptions = '' - experimental-features = nix-command flakes - warn-dirty = false - ''; - - # Set automatic generation cleanup for home-manager - gc = { - automatic = true; - options = "--delete-older-than 10d"; - }; - - settings = { - - # Add community Cachix to binary cache - # Don't use at work because blocked by corporate firewall - builders-use-substitutes = true; - substituters = lib.mkIf (!config.nmasur.profiles.work.enable) [ - "https://nix-community.cachix.org" - ]; - trusted-public-keys = lib.mkIf (!config.nmasur.profiles.work.enable) [ - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - ]; - - # Scans and hard links identical files in the store - # Not working with macOS: https://github.com/NixOS/nix/issues/7273 - auto-optimise-store = lib.mkIf (!pkgs.stdenv.isDarwin) true; - }; - - }; }; } diff --git a/platforms/home-manager/modules/nmasur/presets/services/loadkey.nix b/platforms/home-manager/modules/nmasur/presets/services/loadkey.nix index 0070391..c715fd6 100644 --- a/platforms/home-manager/modules/nmasur/presets/services/loadkey.nix +++ b/platforms/home-manager/modules/nmasur/presets/services/loadkey.nix @@ -22,12 +22,15 @@ in if [ ! -d ~/.ssh ]; then run mkdir --parents $VERBOSE_ARG ~/.ssh/ fi - if [ ! -f ~/.ssh/id_ed25519 ]; then - printf "\nEnter the seed phrase for your SSH key...\n" - printf "\nThen press ^D when complete.\n\n" - mkdir -p ~/.ssh/ - ${pkgs.melt}/bin/melt restore ~/.ssh/id_ed25519 - printf "\n\nContinuing activation.\n\n" + # But only load if using interactive mode + if [[ $- == *i* ]]; then + if [ ! -f ~/.ssh/id_ed25519 ]; then + printf "\nEnter the seed phrase for your SSH key...\n" + printf "\nThen press ^D when complete.\n\n" + mkdir -p ~/.ssh/ + ${pkgs.melt}/bin/melt restore ~/.ssh/id_ed25519 + printf "\n\nContinuing activation.\n\n" + fi fi ''; }; diff --git a/platforms/home-manager/modules/nmasur/presets/services/nix.nix b/platforms/home-manager/modules/nmasur/presets/services/nix.nix new file mode 100644 index 0000000..216f8c2 --- /dev/null +++ b/platforms/home-manager/modules/nmasur/presets/services/nix.nix @@ -0,0 +1,62 @@ +{ + config, + pkgs, + lib, + ... +}: + +let + cfg = config.nmasur.presets.services.nix; +in + +{ + + options.nmasur.presets.services.nix.enable = lib.mkEnableOption "Nix settings and presets"; + + config = lib.mkIf cfg.enable { + + nix = { + + # Set channel to flake packages, used for nix-shell commands + nixPath = [ "nixpkgs=${pkgs.path}" ]; + + # For security, only allow specific users + settings.allowed-users = [ + "@wheel" # Anyone in the wheel group + config.home.username # The current user + ]; + + # Enable features in Nix commands + extraOptions = '' + experimental-features = nix-command flakes + warn-dirty = false + ''; + + # Set automatic generation cleanup for home-manager + gc = { + automatic = true; + options = "--delete-older-than 10d"; + }; + + settings = { + + # Add community Cachix to binary cache + # Don't use at work because blocked by corporate firewall + builders-use-substitutes = true; + substituters = lib.mkIf (!config.nmasur.profiles.work.enable) [ + "https://nix-community.cachix.org" + ]; + trusted-public-keys = lib.mkIf (!config.nmasur.profiles.work.enable) [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + + # Scans and hard links identical files in the store + # Not working with macOS: https://github.com/NixOS/nix/issues/7273 + auto-optimise-store = lib.mkIf (!pkgs.stdenv.isDarwin) true; + }; + + }; + + }; + +} diff --git a/platforms/home-manager/modules/nmasur/presets/services/polybar.nix b/platforms/home-manager/modules/nmasur/presets/services/polybar.nix index 4967e18..3ab31e7 100644 --- a/platforms/home-manager/modules/nmasur/presets/services/polybar.nix +++ b/platforms/home-manager/modules/nmasur/presets/services/polybar.nix @@ -213,6 +213,7 @@ in label = "%date%"; label-foreground = config.theme.colors.base06; # format-background = colors.background; + click-right = lib.getExe config.nmasur.presets.services.i3.terminal; }; "module/power" = { type = "custom/text"; diff --git a/platforms/home-manager/modules/nmasur/profiles/common.nix b/platforms/home-manager/modules/nmasur/profiles/common.nix index 0bd15f5..1a19e7b 100644 --- a/platforms/home-manager/modules/nmasur/profiles/common.nix +++ b/platforms/home-manager/modules/nmasur/profiles/common.nix @@ -35,6 +35,7 @@ in nixpkgs.enable = lib.mkDefault true; }; services = { + nix.enable = lib.mkDefault true; loadkey.enable = lib.mkDefault true; }; }; diff --git a/platforms/home-manager/modules/nmasur/profiles/power-user.nix b/platforms/home-manager/modules/nmasur/profiles/power-user.nix index 3cb69e7..0aa35c3 100644 --- a/platforms/home-manager/modules/nmasur/profiles/power-user.nix +++ b/platforms/home-manager/modules/nmasur/profiles/power-user.nix @@ -57,6 +57,7 @@ in fd.enable = lib.mkDefault true; fish.enable = lib.mkDefault true; fzf.enable = lib.mkDefault true; + nix-index.enable = lib.mkDefault true; nixpkgs.enable = lib.mkDefault true; prettyping.enable = lib.mkDefault true; ripgrep.enable = lib.mkDefault true; diff --git a/platforms/nixos/modules/nmasur/presets/services/lightdm.nix b/platforms/nixos/modules/nmasur/presets/services/lightdm.nix index c078258..55ddf23 100644 --- a/platforms/nixos/modules/nmasur/presets/services/lightdm.nix +++ b/platforms/nixos/modules/nmasur/presets/services/lightdm.nix @@ -6,6 +6,7 @@ }: let + inherit (config.nmasur.settings) username; cfg = config.nmasur.presets.services.lightdm; in @@ -13,10 +14,10 @@ in options.nmasur.presets.services.lightdm = { enable = lib.mkEnableOption "Lightdm display manager"; - wallpaper = { + wallpaper = lib.mkOption { type = lib.types.nullOr lib.types.path; description = "Wallpaper background image file"; - default = "${pkgs.wallpapers}/gruvbox/road.jpg"; + default = "${pkgs.nmasur.wallpapers}/gruvbox/road.jpg"; }; gtk.theme = { name = lib.mkOption { @@ -29,6 +30,8 @@ in config = lib.mkIf cfg.enable { + programs.fish.enable = lib.mkIf (config.home-manager.users.${username}.programs.fish.enable) true; # Needed for LightDM to remember username + services.xserver = { enable = true; diff --git a/platforms/nixos/modules/nmasur/profiles/base.nix b/platforms/nixos/modules/nmasur/profiles/base.nix index e02bc8f..10981f3 100644 --- a/platforms/nixos/modules/nmasur/profiles/base.nix +++ b/platforms/nixos/modules/nmasur/profiles/base.nix @@ -29,6 +29,8 @@ in # Define a user account. Don't forget to set a password with ‘passwd’. users.users.${username} = { + # Use fish by default if enabled in home-manager + shell = lib.mkIf (config.home-manager.users.${username}.programs.fish.enable) pkgs.fish; # Create a home directory for human user isNormalUser = lib.mkDefault true; @@ -59,6 +61,11 @@ in }; + # Extending time for home-manager build for things like nix-index cache + systemd.services."home-manager-${username}" = { + serviceConfig.TimeoutStartSec = lib.mkForce "45m"; + }; + allowUnfreePackages = config.home-manager.users.${username}.allowUnfreePackages; }; diff --git a/platforms/nixos/modules/nmasur/profiles/gui.nix b/platforms/nixos/modules/nmasur/profiles/gui.nix index 6ddfa8e..7e53603 100644 --- a/platforms/nixos/modules/nmasur/profiles/gui.nix +++ b/platforms/nixos/modules/nmasur/profiles/gui.nix @@ -17,6 +17,7 @@ in config = lib.mkIf cfg.enable { nmasur.presets.services.kanata.enable = lib.mkDefault true; + nmasur.presets.services.lightdm.enable = lib.mkDefault true; # Mouse customization services.ratbagd.enable = lib.mkDefault true; @@ -34,10 +35,11 @@ in }; # Enable touchpad support - services.libinput.enable = true; + services.libinput.enable = lib.mkDefault true; services.xserver = { + enable = lib.mkDefault true; xkb.layout = lib.mkDefault "us"; # Keyboard responsiveness