From 23f921b4050b97892fa840226cc82130c2319e77 Mon Sep 17 00:00:00 2001 From: Jason Wieringa Date: Wed, 15 Jan 2025 16:10:14 -0500 Subject: [PATCH] A new re-build - a messy state Lot going on in here that I have not yet taken time to understand; however, in this state the build completes. Of note, the homemanager configuration is disabled because it currently fails. This version borrows more from mitchellh/nixos-config even in cases where I know I don't want a package in order to get the build to work. It appears I went my own path on the previous build. This time I wanted to have a working build quickly which meant I needed to start with someone elses build. --- Makefile | 50 +++++--- bootstrap/default.nix | 29 ----- flake.lock | 65 ----------- flake.nix | 66 +++++++---- hardware/vm-aarch64.nix | 34 ------ lib/mksystem.nix | 52 +++++++++ lib/overlays.nix | 7 ++ machines/desktop/gnome.nix | 8 ++ machines/hardware/vm-aarch64.nix | 25 ++++ machines/vm-aarch64.nix | 83 ++------------ machines/vm-shared.nix | 135 ++++++++++++++++++++++ overlays/default.nix | 7 ++ users/jason/home-manager.nix | 191 +++++++++++++++---------------- users/jason/nixos.nix | 27 +++++ users/jason/vim-config.nix | 116 +++++++++++++++++++ users/jason/vim.nix | 159 +++++++++++++++++++++++++ 16 files changed, 715 insertions(+), 339 deletions(-) delete mode 100644 bootstrap/default.nix delete mode 100644 flake.lock delete mode 100644 hardware/vm-aarch64.nix create mode 100644 lib/mksystem.nix create mode 100644 lib/overlays.nix create mode 100644 machines/desktop/gnome.nix create mode 100644 machines/hardware/vm-aarch64.nix create mode 100644 machines/vm-shared.nix create mode 100644 overlays/default.nix create mode 100644 users/jason/nixos.nix create mode 100644 users/jason/vim-config.nix create mode 100644 users/jason/vim.nix diff --git a/Makefile b/Makefile index e09f9a8..bd5808d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -# Connectivity info for Linux VM NIXADDR ?= unset NIXPORT ?= 22 NIXUSER ?= root @@ -7,39 +6,58 @@ NIXUSER ?= root MAKEFILE_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))) # The name of the nixosConfiguration in the flake -NIXNAME ?= vm-intel +NIXNAME ?= vm-aarch64 # SSH options that are used. These aren't meant to be overridden but are # reused a lot so we just store them up here. SSH_OPTIONS=-o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no +vm/bootstrap0: + ssh $(SSH_OPTIONS) -p$(NIXPORT) root@$(NIXADDR) " \ + parted /dev/nvme0n1 -- mklabel gpt; \ + parted /dev/nvme0n1 -- mkpart primary 512MiB -8GiB; \ + parted /dev/nvme0n1 -- mkpart primary linux-swap -8GiB 100\%; \ + parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB; \ + parted /dev/nvme0n1 -- set 3 esp on; \ + sleep 1; \ + mkfs.ext4 -L nixos /dev/nvme0n1p1; \ + mkswap -L swap /dev/nvme0n1p2; \ + mkfs.fat -F 32 -n boot /dev/nvme0n1p3; \ + sleep 1; \ + mount /dev/disk/by-label/nixos /mnt; \ + mkdir -p /mnt/boot; \ + mount /dev/disk/by-label/boot /mnt/boot; \ + nixos-generate-config --root /mnt; \ + sed --in-place '/system\.stateVersion = .*/a \ + nix.extraOptions = \"experimental-features = nix-command flakes\";\n \ + services.openssh.enable = true;\n \ + services.openssh.settings.PasswordAuthentication = true;\n \ + services.openssh.settings.PermitRootLogin = \"yes\";\n \ + users.users.root.initialPassword = \"root\";\n \ + ' /mnt/etc/nixos/configuration.nix; \ + nixos-install --no-root-passwd && reboot; \ + " + # bootstrap the vm. only run again on macos if the secrets change vm/bootstrap: NIXUSER=root $(MAKE) vm/copy - NIXUSER=root $(MAKE) vm/install - $(MAKE) vm/secrets + NIXUSER=root $(MAKE) vm/switch + # $(MAKE) vm/secrets -# copy our secrets into the VM -vm/secrets: - # SSH keys - rsync -av -e 'ssh $(SSH_OPTIONS)' \ - --exclude='environment' \ - $(HOME)/.ssh/ $(NIXUSER)@$(NIXADDR):~/.ssh # copy the Nix configurations into the VM. vm/copy: rsync -av -e 'ssh $(SSH_OPTIONS) -p$(NIXPORT)' \ + --exclude='vendor/' \ --exclude='.git/' \ + --exclude='.git-crypt/' \ + --exclude='iso/' \ --rsync-path="sudo rsync" \ $(MAKEFILE_DIR)/ $(NIXUSER)@$(NIXADDR):/nix-config -# run the nixos-install command. This does NOT copy files so you -# have to run vm/copy before. -vm/install: +vm/switch: ssh $(SSH_OPTIONS) -p$(NIXPORT) $(NIXUSER)@$(NIXADDR) " \ - sudo nix-shell \ - --argstr systemName $(NIXNAME) \ - /nix-config/bootstrap \ + sudo NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nixos-rebuild switch --flake \"/nix-config#${NIXNAME}\" \ " vm/reboot: diff --git a/bootstrap/default.nix b/bootstrap/default.nix deleted file mode 100644 index 1da7447..0000000 --- a/bootstrap/default.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ pkgs ? import {} -, systemName ? "vm-intel" -}: - -pkgs.mkShell { - buildInputs = [ - pkgs.nixUnstable - pkgs.parted - ]; - shellHook = '' - set -e -u -o pipefail - parted /dev/nvme0n1 -- mklabel gpt - parted /dev/nvme0n1 -- mkpart primary 512MiB -8GiB - parted /dev/nvme0n1 -- mkpart primary linux-swap -8GiB 100% - parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB - parted /dev/nvme0n1 -- set 3 esp on - sleep 1 - mkfs.ext4 -L nixos /dev/nvme0n1p1 - mkswap -L swap /dev/nvme0n1p2 - mkfs.fat -F 32 -n boot /dev/nvme0n1p3 - sleep 1 - mount /dev/disk/by-label/nixos /mnt - mkdir -p /mnt/boot - mount /dev/disk/by-label/boot /mnt/boot - # generates hadware configurations - nixos-generate-config --root /mnt - NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nixos-install --flake "/nix-config#${systemName}" --no-root-passwd -v --root /mnt - ''; -} diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 461b53d..0000000 --- a/flake.lock +++ /dev/null @@ -1,65 +0,0 @@ -{ - "nodes": { - "home-manager": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "utils": "utils" - }, - "locked": { - "lastModified": 1670253003, - "narHash": "sha256-/tJIy4+FbsQyslq1ipyicZ2psOEd8dvl4OJ9lfisjd0=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "0e8125916b420e41bf0d23a0aa33fadd0328beb3", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "release-22.11", - "repo": "home-manager", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1670684540, - "narHash": "sha256-9VCEKOOn+LaeWySwO9Xa8kZtaPpfk4xRt1vZ+nC9h8U=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "9c5e57f38db0003f493111b7f6873fca1288d93f", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "release-22.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "home-manager": "home-manager", - "nixpkgs": "nixpkgs" - } - }, - "utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix index a3b0510..33d0f4c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,39 +1,57 @@ -# Credit: https://github.com/mitchellh/nixos-config/blob/501f9aa0a669479c34d8d036f52a15b04002d259/flake.nix +# Credit: https://github.com/mitchellh/nixos-config/blob/06b6eb4aa6f9817605f4d45a33331f4263e02d58/flake.nix { description = "Jason Wieringa's NixOS"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/release-22.11"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; + + neovim-nightly-overlay = { + url = "github:nix-community/neovim-nightly-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; home-manager = { - url = "github:nix-community/home-manager/release-22.11"; + url = "github:nix-community/home-manager/release-24.11"; inputs.nixpkgs.follows = "nixpkgs"; }; + + # Other packages + zig.url = "github:mitchellh/zig-overlay"; }; - outputs = inputs@{ self, nixpkgs, home-manager, ... }: { - # This configuration would produce a vmdx for use in VMware. - # - # I tried to build a VMware image on Github actions, but they do not yet support - # nested virtualization (kvm). I'll need a place in CI to build the VM image to - # enable this workflow. - # - # packages.x86_64-linux = { - # vmwareImage = self.nixosConfigurations.vm-intel.config.system.build.vmwareImage; - # }; - - nixosConfigurations.vm-aarch64 = nixpkgs.lib.nixosSystem { + outputs = { self, nixpkgs, home-manager, ... }@inputs: let + overlays = [ + inputs.zig.overlays.default + + (final: prev: { + # gh CLI on stable has bugs. + gh = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.gh; + }) + ]; + + mkSystem = import ./lib/mksystem.nix { + inherit overlays nixpkgs inputs; + }; + in { + nixosConfigurations.vm-aarch64 = mkSystem "vm-aarch64" { system = "aarch64-linux"; - modules = [ - ./hardware/vm-aarch64.nix - ./machines/vm-aarch64.nix - home-manager.nixosModules.home-manager { - home-manager.users.jason = import ./users/jason/home-manager.nix; - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - } - ]; + user = "jason"; }; }; } + +# nixosConfigurations.vm-aarch64 = nixpkgs.lib.nixosSystem { +# system = "aarch64-linux"; +# modules = [ +# ./hardware/vm-aarch64.nix +# ./machines/vm-aarch64.nix +# home-manager.nixosModules.home-manager { +# home-manager.users.jason = import ./users/jason/home-manager.nix; +# home-manager.useGlobalPkgs = true; +# home-manager.useUserPackages = true; +# } +# ]; +# }; +# }; +# } diff --git a/hardware/vm-aarch64.nix b/hardware/vm-aarch64.nix deleted file mode 100644 index 05d6ca3..0000000 --- a/hardware/vm-aarch64.nix +++ /dev/null @@ -1,34 +0,0 @@ -# Do not modify this file! It was generated by ‘nixos-generate-config’ -# and may be overwritten by future invocations. Please make changes -# to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs, modulesPath, ... }: - -{ - imports = [ ]; - - boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "nvme" "usbhid" "sr_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ ]; - boot.extraModulePackages = [ ]; - - fileSystems."/" = - { device = "/dev/disk/by-uuid/726144cc-045a-4a52-9f81-92c52d782f40"; - fsType = "ext4"; - }; - - fileSystems."/boot" = - { device = "/dev/disk/by-uuid/9A88-5BCC"; - fsType = "vfat"; - }; - - swapDevices = [ ]; - - # Enables DHCP on each ethernet and wireless interface. In case of scripted networking - # (the default) this is the recommended approach. When using systemd-networkd it's - # still possible to use this option, but it's recommended to use it in conjunction - # with explicit per-interface declarations with `networking.interfaces..useDHCP`. - networking.useDHCP = lib.mkDefault true; - # networking.interfaces.ens160.useDHCP = lib.mkDefault true; - - nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux"; -} diff --git a/lib/mksystem.nix b/lib/mksystem.nix new file mode 100644 index 0000000..920fe44 --- /dev/null +++ b/lib/mksystem.nix @@ -0,0 +1,52 @@ +# This function creates a NixOS system based on our VM setup for a +# particular architecture. +{ nixpkgs, overlays, inputs }: + +name: +{ + system, + user, +}: + +let + # The config files for this system. + machineConfig = ../machines/${name}.nix; + userOSConfig = ../users/${user}/nixos.nix; + # userHMConfig = ../users/${user}/home-manager.nix; + + systemFunc = nixpkgs.lib.nixosSystem; + home-manager = inputs.home-manager.nixosModules; +in systemFunc rec { + inherit system; + + modules = [ + # Apply our overlays. Overlays are keyed by system type so we have + # to go through and apply our system type. We do this first so + # the overlays are available globally. + { nixpkgs.overlays = overlays; } + + # Allow unfree packages. + { nixpkgs.config.allowUnfree = true; } + + machineConfig + userOSConfig + # home-manager.home-manager { + # home-manager.useGlobalPkgs = true; + # home-manager.useUserPackages = true; + # home-manager.users.${user} = import userHMConfig { + # inputs = inputs; + # }; + # } + + # We expose some extra arguments so that our modules can parameterize + # better based on these values. + { + config._module.args = { + currentSystem = system; + currentSystemName = name; + currentSystemUser = user; + inputs = inputs; + }; + } + ]; +} diff --git a/lib/overlays.nix b/lib/overlays.nix new file mode 100644 index 0000000..7a31e8b --- /dev/null +++ b/lib/overlays.nix @@ -0,0 +1,7 @@ +/* This configures nixpkgs.overlays to include our overlays/ directory. + */ +let path = ../overlays; in with builtins; +map (n: import (path + ("/" + n))) + (filter (n: match ".*\\.nix" n != null || + pathExists (path + ("/" + n + "/default.nix"))) + (attrNames (readDir path))) diff --git a/machines/desktop/gnome.nix b/machines/desktop/gnome.nix new file mode 100644 index 0000000..3d2ed92 --- /dev/null +++ b/machines/desktop/gnome.nix @@ -0,0 +1,8 @@ +{ config, pkgs, lib, currentSystem, currentSystemName,... }: { + services.xserver = { + enable = true; + xkb.layout = "us"; + desktopManager.gnome.enable = true; + displayManager.gdm.enable = true; + }; +} diff --git a/machines/hardware/vm-aarch64.nix b/machines/hardware/vm-aarch64.nix new file mode 100644 index 0000000..e358ac0 --- /dev/null +++ b/machines/hardware/vm-aarch64.nix @@ -0,0 +1,25 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = [ ]; + + boot.initrd.availableKernelModules = [ "uhci_hcd" "ahci" "xhci_pci" "nvme" "usbhid" "sr_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-label/boot"; + fsType = "vfat"; + }; + + swapDevices = [ ]; +} diff --git a/machines/vm-aarch64.nix b/machines/vm-aarch64.nix index 4e0b69a..28d519c 100644 --- a/machines/vm-aarch64.nix +++ b/machines/vm-aarch64.nix @@ -2,32 +2,28 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, ... }: { +{ config, pkgs, lib, ... }: { imports = [ + ./hardware/vm-aarch64.nix ../modules/vmware-guest.nix + ./vm-shared.nix ]; + # Setup qemu so we can run x86_64 binaries + boot.binfmt.emulatedSystems = ["x86_64-linux"]; + # Disable the default module and import our override. We have # customizations to make this work on aarch64. disabledModules = [ "virtualisation/vmware-guest.nix" ]; - nix = { - # use unstable nix so we can access flakes - package = pkgs.nixUnstable; - extraOptions = '' - experimental-features = nix-command flakes - ''; + # Interface is this on M1 + networking.interfaces.ens160.useDHCP = true; - # public binary cache that I use for all my derivations. You can keep - # this, use your own, or toss it. Its typically safe to use a binary cache - # since the data inside is checksummed. - settings = { - substituters = ["https://jwieringa-nixos-config.cachix.org"]; - trusted-public-keys = ["jwieringa-nixos-config.cachix.org-1:ZR2Yfx0c9A6EQ+i94lgIOwma7LxVIx4eEMEKu5KrX4w="]; - }; - }; + # Lots of stuff that uses aarch64 that claims doesn't work, but actually works. + nixpkgs.config.allowUnfree = true; + nixpkgs.config.allowUnsupportedSystem = true; - # Enable vmware guest tools + # This works through our custom module imported above virtualisation.vmware.guest.enable = true; # Share our host filesystem @@ -43,59 +39,4 @@ "defaults" ]; }; - - # Use the systemd-boot EFI boot loader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - - networking.hostName = "dev"; # Define your hostname. - # Pick only one of the below networking options. - # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default. - - # Set your time zone. - # time.timeZone = "Europe/Amsterdam"; - - # Select internationalisation properties. - # i18n.defaultLocale = "en_US.UTF-8"; - # console = { - # font = "Lat2-Terminus16"; - # keyMap = "us"; - # useXkbConfig = true; # use xkbOptions in tty. - # }; - - # Enable the X11 windowing system. - # services.xserver.enable = true; - - # Configure keymap in X11 - # services.xserver.layout = "us"; - # services.xserver.xkbOptions = { - # "eurosign:e"; - # "caps:escape" # map caps to escape. - # }; - - # Enable CUPS to print documents. - # services.printing.enable = true; - - # Enable touchpad support (enabled default in most desktopManager). - # services.xserver.libinput.enable = true; - - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.jason = { - isNormalUser = true; - home = "/home/jason"; - extraGroups = [ "wheel" ]; - shell = pkgs.fish; - hashedPassword = "$y$j9T$DLNE0B4PSDgwgrob9SPbW0$24ZDYOKxCXpQ/6GrkmRAMCj3EQ1OB6c4acRfKAiSR58"; - openssh.authorizedKeys.keys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBIqztDzifQPfJgEmrfQtE5XNYHOtQne2fiTREkKSC9u jason@radiusnetworks.com" - ]; - }; - - # Start the ssh-agent - programs.ssh.startAgent = true; - - # Enable the OpenSSH daemon. - services.openssh.enable = true; - - system.stateVersion = "22.11"; } diff --git a/machines/vm-shared.nix b/machines/vm-shared.nix new file mode 100644 index 0000000..1bdf2db --- /dev/null +++ b/machines/vm-shared.nix @@ -0,0 +1,135 @@ +{ config, pkgs, lib, currentSystem, currentSystemName,... }: + +let + # The desktop environment we want. Set to one of: + # - gnome + # - kde + # - i3 + desktop = "gnome"; +in { + imports = [ + # TODO: you need to set this up + ./desktop/${desktop}.nix + ]; + + # Be careful updating this. + boot.kernelPackages = pkgs.linuxPackages_latest; + + nix = { + package = pkgs.nixVersions.latest; + extraOptions = '' + experimental-features = nix-command flakes + keep-outputs = true + keep-derivations = true + ''; + + # public binary cache that I use for all my derivations. You can keep + # this, use your own, or toss it. Its typically safe to use a binary cache + # since the data inside is checksummed. + settings = { + substituters = ["https://jwieringa-nixos-config.cachix.org"]; + trusted-public-keys = ["jwieringa-nixos-config.cachix.org-1:ZR2Yfx0c9A6EQ+i94lgIOwma7LxVIx4eEMEKu5KrX4w="]; + }; + }; + + # Use the systemd-boot EFI boot loader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + # VMware, Parallels both only support this being 0 otherwise you see + # "error switching console mode" on boot. + boot.loader.systemd-boot.consoleMode = "0"; + + # Define your hostname. + networking.hostName = "dev"; + + # Set your time zone. + time.timeZone = "Etc/UTC"; + + # The global useDHCP flag is deprecated, therefore explicitly set to false here. + # Per-interface useDHCP will be mandatory in the future, so this generated config + # replicates the default behaviour. + networking.useDHCP = false; + + # Don't require password for sudo + security.sudo.wheelNeedsPassword = false; + + # Virtualization settings + virtualisation.docker.enable = true; + virtualisation.lxd = { + enable = true; + }; + + # Select internationalisation properties. + i18n = { + defaultLocale = "en_US.UTF-8"; + inputMethod = { + enable = true; + type = "fcitx5"; + fcitx5.addons = with pkgs; [ + fcitx5-gtk + ]; + }; + }; + + # Enable tailscale. We manually authenticate when we want with + # "sudo tailscale up". If you don't use tailscale, you should comment + # out or delete all of this. + services.tailscale.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.mutableUsers = false; + + # TODO: Setup fonts + # + # Manage fonts. We pull these from a secret directory since most of these + # fonts require a purchase. + # fonts = { + # fontDir.enable = true; + + # packages = [ + # pkgs.fira-code + # pkgs.jetbrains-mono + # ]; + # }; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + cachix + gnumake + killall + niv + xclip + + # For hypervisors that support auto-resizing, this script forces it. + # I've noticed not everyone listens to the udev events so this is a hack. + (writeShellScriptBin "xrandr-auto" '' + xrandr --output Virtual-1 --auto + '') + ] ++ lib.optionals (currentSystemName == "vm-aarch64") [ + # This is needed for the vmware user tools clipboard to work. + # You can test if you don't need this by deleting this and seeing + # if the clipboard sill works. + gtkmm3 + ]; + + # Enable the OpenSSH daemon. + services.openssh.enable = true; + services.openssh.settings.PasswordAuthentication = true; + services.openssh.settings.PermitRootLogin = "no"; + + # Disable the firewall since we're in a VM and we want to make it + # easy to visit stuff in here. We only use NAT networking anyways. + networking.firewall.enable = false; + + # TODO: Do not set - new system - revisit later + # + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + # system.stateVersion = "20.09"; # Did you read the comment? +} diff --git a/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..c7ba585 --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,7 @@ +/* This contains various packages we want to overlay. Note that the + * other ".nix" files in this directory are automatically loaded. + */ +final: prev: { + # Fix 1password not working properly on Linux arm64. + #_1password = final.callPackage ../pkgs/1password.nix {}; +} diff --git a/users/jason/home-manager.nix b/users/jason/home-manager.nix index 044eae5..19af246 100644 --- a/users/jason/home-manager.nix +++ b/users/jason/home-manager.nix @@ -1,10 +1,18 @@ +{ inputs, ... }: + { config, lib, pkgs, ... }: -# TODO: Do I need/use sources.nix? -let sources = import ../../nix/sources.nix; in { - home.stateVersion = "22.11"; +let + sources = import ../../nix/sources.nix; - # xdg.enable = true; + # For our MANPAGER env var + # https://github.com/sharkdp/bat/issues/1145 + manpager = (pkgs.writeShellScriptBin "manpager" '' + cat "$1" | col -bx | bat --language man --style plain + ''); +in { + home.stateVersion = "22.11"; + xdg.enable = true; #--------------------------------------------------------------------- # Packages @@ -14,16 +22,19 @@ let sources = import ../../nix/sources.nix; in { # per-project flakes sourced with direnv and nix-shell, so this is # not a huge list. home.packages = [ - pkgs.which + pkgs._1password-cli pkgs.bat pkgs.fd pkgs.fzf + pkgs.git pkgs.htop pkgs.jq + pkgs.ripgrep + pkgs.tfswitch pkgs.tree pkgs.watch - pkgs.git - pkgs.tfswitch + pkgs.which + pkgs.firefox ]; #--------------------------------------------------------------------- @@ -34,74 +45,48 @@ let sources = import ../../nix/sources.nix; in { LANG = "en_US.UTF-8"; LC_CTYPE = "en_US.UTF-8"; LC_ALL = "en_US.UTF-8"; - EDITOR = "vim"; + EDITOR = "nvim"; PAGER = "less -FirSwX"; - MANPAGER = "sh -c 'col -bx | ${pkgs.bat}/bin/bat -l man -p'"; + MANPAGER = "${manpager}/bin/manpager"; }; + # TODO - fill out xdf settings + # xdg.configFile = {}; + #--------------------------------------------------------------------- # Programs #--------------------------------------------------------------------- programs.fish = { enable = true; + interactiveShellInit = lib.strings.concatStrings (lib.strings.intersperse "\n" ([ + "source ${sources.theme-bobthefish}/functions/fish_prompt.fish" + "source ${sources.theme-bobthefish}/functions/fish_right_prompt.fish" + "source ${sources.theme-bobthefish}/functions/fish_title.fish" + (builtins.readFile ./config.fish) + "set -g SHELL ${pkgs.fish}/bin/fish" + ])); - interactiveShellInit = '' -# Credit: https://github.com/mitchellh/nixos-config/blob/9015bdc23b6b372abcad709c0b0e3c59820c5a54/users/mitchellh/config.fish - -#------------------------------------------------------------------------------- -# SSH Agent -#------------------------------------------------------------------------------- -function __ssh_agent_is_started -d "check if ssh agent is already started" - if begin; test -f $SSH_ENV; and test -z "$SSH_AGENT_PID"; end - source $SSH_ENV > /dev/null - end - - if test -z "$SSH_AGENT_PID" - return 1 - end - - ssh-add -l > /dev/null 2>&1 - if test $status -eq 2 - return 1 - end -end - -function __ssh_agent_start -d "start a new ssh agent" - ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV - chmod 600 $SSH_ENV - source $SSH_ENV > /dev/null - ssh-add -end - -if not test -d $HOME/.ssh - mkdir -p $HOME/.ssh - chmod 0700 $HOME/.ssh -end - -if test -d $HOME/.gnupg - chmod 0700 $HOME/.gnupg -end - -if test -z "$SSH_ENV" - set -xg SSH_ENV $HOME/.ssh/environment -end - -if not __ssh_agent_is_started - __ssh_agent_start -end - -#------------------------------------------------------------------------------- -# nixos -#------------------------------------------------------------------------------- - -set -l nix_shell_info ( - if test -n "$IN_NIX_SHELL" - echo -n " " - end -) - ''; + shellAliases = { + ga = "git add"; + gc = "git commit"; + gco = "git checkout"; + gcp = "git cherry-pick"; + gdiff = "git diff"; + gl = "git prettylog"; + gp = "git push"; + gs = "git status"; + gt = "git tag"; + }; + plugins = map (n: { + name = n; + src = sources.${n}; + }) [ + "fish-fzf" + "fish-foreign-env" + "theme-bobthefish" + ]; }; programs.bash = { @@ -119,9 +104,6 @@ set -l nix_shell_info ( gp = "git push"; gs = "git status"; gt = "git tag"; - - pbcopy = "xclip"; - pbpaste = "xclip -o"; }; }; @@ -133,11 +115,6 @@ set -l nix_shell_info ( enable = true; userName = "Jason Wieringa"; userEmail = "jason@wieringa.io"; - # TODO: Add signing key - # signing = { - # key = ""; - # signByDefault = true; - # }; aliases = { hist = "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(r) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"; }; @@ -152,34 +129,48 @@ set -l nix_shell_info ( }; }; - programs.vim = { + programs.neovim = { enable = true; - plugins = with pkgs.vimPlugins; [ - vim-airline - vim-terraform - vim-nix - vim-markdown - nerdtree - vim-gitgutter + package = inputs.neovim-nightly-overlay.packages.${pkgs.system}.default; + + withPython3 = true; + + plugins = with pkgs; [ + # Copied plugins - curious but needs review + customVim.vim-copilot + customVim.vim-cue + customVim.vim-glsl + customVim.vim-misc + customVim.vim-tla + customVim.vim-zig + customVim.pigeon + customVim.AfterColors + + customVim.vim-nord + customVim.nvim-comment + customVim.nvim-conform + customVim.nvim-dressing + customVim.nvim-gitsigns + customVim.nvim-lualine + customVim.nvim-lspconfig + customVim.nvim-nui + customVim.nvim-plenary # required for telescope + customVim.nvim-telescope + + customVim.vim-pgsql + customVim.vim-fish + + customVim.nvim-treesitter + customVim.nvim-treesitter-playground + customVim.nvim-treesitter-textobjects + + vimPlugins.nvim-treesitter-parsers.elixir + vimPlugins.vim-markdown + vimPlugins.vim-nix + vimPlugins.vim-eunuch + vimPlugins.typescript-vim ]; - settings = { ignorecase = true; }; - extraConfig = '' -" General Settings -set nocompatible " Running Vim, not Vi -set number " Always show line numbers - -" Status Bar -set statusline=%t\ %r\ %y\ format:\ %{&ff};\ [%c,%l] " Format statusbar http://vim.runpaint.org/display/changing-status-line/ - -" NerdTREE settings -let NERDTreeShowHidden=1 " Show hidden files - -" " Mappings -let mapleader = "," " Set leader key -map nt :NERDTree " Set NERDTree shortcut -map ev :e $MYVIMRC " Quickly edit the vimrc file -map sv :so $MYVIMRC " Quickly reload the vimrc file -map cs :noh - ''; - }; + + extraConfig = (import ./vim-config.nix) { inherit sources; }; + }; } diff --git a/users/jason/nixos.nix b/users/jason/nixos.nix new file mode 100644 index 0000000..2bab603 --- /dev/null +++ b/users/jason/nixos.nix @@ -0,0 +1,27 @@ +{ pkgs, inputs, ... }: + +{ + # https://github.com/nix-community/home-manager/pull/2408 + environment.pathsToLink = [ "/share/fish" ]; + + # Add ~/.local/bin to PATH + environment.localBinInPath = true; + + # Since we're using fish as our shell + programs.fish.enable = true; + + users.users.jason = { + isNormalUser = true; + home = "/home/jason"; + extraGroups = [ "docker" "lxd" "wheel" ]; + shell = pkgs.fish; + hashedPassword = "$6$2Xl8HyXvIvvKz72N$tH05lpPXk1MiZofDkhZs8W6K.0Xs0p3Xlwh4FO/x.3N.R/BluK3zB/IzrgtPiU9/jm2jPctiEBCLOJs8aFudo."; + openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBIqztDzifQPfJgEmrfQtE5XNYHOtQne2fiTREkKSC9u jason" + ]; + }; + + nixpkgs.overlays = import ../../lib/overlays.nix ++ [ + (import ./vim.nix { inherit inputs; }) + ]; +} diff --git a/users/jason/vim-config.nix b/users/jason/vim-config.nix new file mode 100644 index 0000000..dd46ca6 --- /dev/null +++ b/users/jason/vim-config.nix @@ -0,0 +1,116 @@ +{ sources }: +'' +"-------------------------------------------------------------------- +" Fix vim paths so we load the vim-misc directory +let g:vim_home_path = "~/.vim" + +" This works on NixOS 21.05 +let vim_misc_path = split(&packpath, ",")[0] . "/pack/home-manager/start/vim-misc/vimrc.vim" +if filereadable(vim_misc_path) + execute "source " . vim_misc_path +endif + +" This works on NixOS 21.11 +let vim_misc_path = split(&packpath, ",")[0] . "/pack/home-manager/start/vimplugin-vim-misc/vimrc.vim" +if filereadable(vim_misc_path) + execute "source " . vim_misc_path +endif + +" This works on NixOS 22.11 +let vim_misc_path = split(&packpath, ",")[0] . "/pack/myNeovimPackages/start/vimplugin-vim-misc/vimrc.vim" +if filereadable(vim_misc_path) + execute "source " . vim_misc_path +endif + +lua <