From 62a2c850ae616349019715f3064cf4c2cfc197fa Mon Sep 17 00:00:00 2001 From: caem Date: Thu, 6 Jun 2024 12:41:31 +0200 Subject: [PATCH] Add support for non-nixos systems I run Debian on my Thinkpad and wanted to take advantage of nix on there without also installing NixOS there, so here is added support for it. --- README.md | 6 ++++ non-nixos-install.sh | 22 ++++++++++++++ users/blank/README.md | 4 +++ users/blank/home-manager/home.nix | 30 +++++++++++++++++++ users/blank/home-manager/packages/nvim | 1 + users/blank/home-manager/packages/zsh | 1 + users/blank/nixpkgs/config.nix | 4 +++ .../zsh/config/conf.d/completions.zsh | 10 ++++--- users/hu/packages/zsh/config/conf.d/path.zsh | 4 +++ users/hu/packages/zsh/zsh-home.nix | 29 +++++++++++++++--- users/hu/packages/zsh/zsh.nix | 13 -------- 11 files changed, 103 insertions(+), 21 deletions(-) create mode 100755 non-nixos-install.sh create mode 100644 users/blank/README.md create mode 100644 users/blank/home-manager/home.nix create mode 120000 users/blank/home-manager/packages/nvim create mode 120000 users/blank/home-manager/packages/zsh create mode 100644 users/blank/nixpkgs/config.nix diff --git a/README.md b/README.md index d0da21f..36e667f 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ modify and share this configuration to your heart's content, no attribution requ ``` ## Installing +### NixOS This configuration uses impermanence with btrfs snapshots so you'll have to partition your system in a certain way. @@ -75,3 +76,8 @@ in the `secrets/{user}` directory as `pass`. Finally, in the config directory run `nixos-install --flake '.#'`, reboot and you're done. +### Non-NixOS +Run the `non-nixos-install.sh` script. It will install both home-manager and nix. +Your user is assumed to be called "blank". You need to replace every instance of it +in case you want to use a different username. + diff --git a/non-nixos-install.sh b/non-nixos-install.sh new file mode 100755 index 0000000..2652119 --- /dev/null +++ b/non-nixos-install.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +# This script sets up nix and home-manager for distributions that are not NixOS. + +set -e +BASE_PATH="$(dirname "$(realpath "$0")")" + +if [ ! -d "/nix" ]; then + # Do multi-user installation + sh <(curl -L https://nixos.org/nix/install) --daemon + nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs +fi + +if [ ! -x "$HOME/.nix-profile/bin/home-manager" ]; then + ln -svf "$BASE_PATH/users/blank/home-manager" "$HOME/.config/home-manager" + ln -svf "$BASE_PATH/users/blank/nixpkgs" "$HOME/.config/nixpkgs" + + nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager + nix-channel --update + nix-shell '' -A install +fi + diff --git a/users/blank/README.md b/users/blank/README.md new file mode 100644 index 0000000..334c220 --- /dev/null +++ b/users/blank/README.md @@ -0,0 +1,4 @@ +This user is a standalone home-manager user which I use for +systems that are not NixOS but still make use of home-manager. +You should not import this user when running NixOS. + diff --git a/users/blank/home-manager/home.nix b/users/blank/home-manager/home.nix new file mode 100644 index 0000000..0501acf --- /dev/null +++ b/users/blank/home-manager/home.nix @@ -0,0 +1,30 @@ +{ config, pkgs, ... }: + +{ + home.username = "blank"; + home.homeDirectory = "/home/blank"; + home.stateVersion = "24.05"; + + /* + home.packages = with pkgs; [ + nvim + ]; + */ + + home.file.".zshenv" = { + text = "source ~/.nix-profile/etc/profile.d/hm-session-vars.sh"; + }; + + home.sessionVariables = { + EDITOR = "nvim"; + ZDOTDIR = "${config.xdg.configHome}/zsh"; + }; + + imports = [ + ./packages/nvim/neovim.nix + ./packages/zsh/zsh-home.nix + ]; + + programs.home-manager.enable = true; +} + diff --git a/users/blank/home-manager/packages/nvim b/users/blank/home-manager/packages/nvim new file mode 120000 index 0000000..9817178 --- /dev/null +++ b/users/blank/home-manager/packages/nvim @@ -0,0 +1 @@ +../../../hu/packages/nvim \ No newline at end of file diff --git a/users/blank/home-manager/packages/zsh b/users/blank/home-manager/packages/zsh new file mode 120000 index 0000000..5e6198f --- /dev/null +++ b/users/blank/home-manager/packages/zsh @@ -0,0 +1 @@ +../../../hu/packages/zsh \ No newline at end of file diff --git a/users/blank/nixpkgs/config.nix b/users/blank/nixpkgs/config.nix new file mode 100644 index 0000000..0ad4e95 --- /dev/null +++ b/users/blank/nixpkgs/config.nix @@ -0,0 +1,4 @@ +{ + allowUnfree = true; +} + diff --git a/users/hu/packages/zsh/config/conf.d/completions.zsh b/users/hu/packages/zsh/config/conf.d/completions.zsh index 02e3d0b..1afdd64 100755 --- a/users/hu/packages/zsh/config/conf.d/completions.zsh +++ b/users/hu/packages/zsh/config/conf.d/completions.zsh @@ -1,9 +1,11 @@ #!/usr/bin/env zsh -if [ -z "$FZF_TAB_FILE" ] && [ ! -d "$HOME/.cache/fzf-tab" ]; then - echo "Installing fzf-tab" - git clone "https://github.com/Aloxaf/fzf-tab" "$HOME/.cache/fzf-tab" - FZF_TAB_FILE="$HOME/.cache/fzf-tab/fzf-tab.plugin.zsh" +if [ -z "$FZF_TAB_FILE" ]; then + if [ ! -d "$HOME/.cache/fzf-tab" ]; then + echo "Installing fzf-tab" + git clone "https://github.com/Aloxaf/fzf-tab" "$HOME/.cache/fzf-tab" + fi + FZF_TAB_FILE="$HOME/.cache/fzf-tab/fzf-tab.plugin.zsh" fi autoload -Uz compinit diff --git a/users/hu/packages/zsh/config/conf.d/path.zsh b/users/hu/packages/zsh/config/conf.d/path.zsh index 3b1e571..c418f2c 100755 --- a/users/hu/packages/zsh/config/conf.d/path.zsh +++ b/users/hu/packages/zsh/config/conf.d/path.zsh @@ -8,6 +8,10 @@ add_to_path() { add_to_path "$HOME/.local/bin" +if [ -f "/etc/profile.d/nix.sh" ]; then + source /etc/profile.d/nix.sh +fi + # Language package mangers if [ -n "$(command -v go)" ]; then export GOPATH="$HOME/.local/share/go" diff --git a/users/hu/packages/zsh/zsh-home.nix b/users/hu/packages/zsh/zsh-home.nix index e8015b8..3eab47c 100644 --- a/users/hu/packages/zsh/zsh-home.nix +++ b/users/hu/packages/zsh/zsh-home.nix @@ -1,15 +1,36 @@ -{ pkgs, ... }: +{ config, pkgs, ... }: { - home.file."/home/hu/.config/zsh/conf.d" = { + home.packages = with pkgs; [ + fzf + zsh-fzf-tab + zsh-completions + zsh-autosuggestions + zsh-syntax-highlighting + nix-zsh-completions + thefuck + ]; + + home.file."${config.xdg.configHome}/zsh/conf.d" = { source = ./config/conf.d; recursive = true; }; - home.file."/home/hu/.config/zsh/.zshrc" = { + + home.file."${config.xdg.configHome}/zsh/.zshrc" = { text = '' #!/usr/bin/env zsh SYNTAX_FILE="${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" - FZF_TAB_FILE="${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh" + + # On systems that are not on glibc 2.38, loading fzf-tab will fail. This prevents that. + if [ -f "/lib/x86_64-linux-gnu/libc.so.6" ]; then + GLIBC_VERSION="$(/lib/x86_64-linux-gnu/libc.so.6 | head -n1 | sed -e 's/.* //g' | rev | cut -c2- | rev)" + if [ "$GLIBC_VERSION" = "2.38" ]; then + FZF_TAB_FILE="${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh" + fi + else + FZF_TAB_FILE="${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh" + fi + AUTOSUGGEST_FILE="${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh" '' + (builtins.readFile config/.zshrc); }; diff --git a/users/hu/packages/zsh/zsh.nix b/users/hu/packages/zsh/zsh.nix index 44d3d8c..d6d564a 100644 --- a/users/hu/packages/zsh/zsh.nix +++ b/users/hu/packages/zsh/zsh.nix @@ -2,18 +2,5 @@ { programs.zsh.enable = true; - environment.variables = { - ZDOTDIR = "${config.users.users.hu.home}/.config/zsh"; - }; - - environment.systemPackages = with pkgs; [ - fzf - zsh-fzf-tab - zsh-completions - zsh-autosuggestions - zsh-syntax-highlighting - nix-zsh-completions - thefuck - ]; }