Skip to content

l-lin/dotfiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dotfiles

❄️ NixOS

🐧 Ubuntu

Getting started

# list all available operations
make help
$ # folder description
$ nix-shell -p tree --run 'tree -d -L 1'
.
β”œβ”€β”€ home-manager # Install and configure package at user level.
β”œβ”€β”€ nixos        # Install and configure package at system level.
β”œβ”€β”€ pkgs         # Contains Nix custom packages that are not present in nixpkgs.
β”œβ”€β”€ scripts      # Contains some Nix scripts to be use in home-manager or NixOS configuration files, as well as some shell scripts to use outside of Nix.
└── stow         # Configuration files that need to be writeable are symlinked in this folder.

Fresh installation

❄️ NixOS

# Clone dotfiles.
nix-shell -p git just
cd ~/.config
git clone https://github.com/l-lin/dotfiles
cd dotfiles

# Install.
just import-keys import-secrets
just update-nixos
just update-home
reboot

# Add navi cheatsheets.
unleash-the-keys
just install-cheatsheets

# Fix dotfiles git remote to use ssh.
wd dotfiles
git remote remove origin && git remote add origin git@github.com:l-lin/dotfiles && git fetch

🐧 Ubuntu

# install curl to install nix: https://zero-to-nix.com/start/install
sudo apt install curl
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

# Clone dotfiles.
nix-shell -p git just
cd ~/.config
git clone https://github.com/l-lin/dotfiles
cd dotfiles

# Install.
just import-keys import-secrets
just install-home-standalone
just update-home
reboot

# Add navi cheatsheets.
unleash-the-keys
just install-cheatsheets

# Fix dotfiles git remote to use ssh.
wd dotfiles
git remote remove origin && git remote add origin git@github.com:l-lin/dotfiles && git fetch

Notes to my future self

πŸ‘‹ Hello, my future self. Yes, you! Here are some notes for you, as I know you are forgetful.

Some packages are broken after an upgrade

If you are living dangerously, i.e. you are using the unstable version of nixpkgs, each package may be upgraded to their latest version. So you may have some packages that are not behaving the same as you wanted or are just broken.

Here's a tutorial of someone that used git bisect to find and fix his issue: https://ipetkov.dev/blog/bisecting-nix-configurations/.

Symlink configuration files whenever you can

There's a "Nix way" of configuring package. It is like a good abstraction, but you will prefer to have your configuration in the original format and create symlinks on them.

There are several advantages of doing like this:

  • you can refer to the package documentation to make your modification
  • you can use linter/treesitter/lsp/whatever on the configuration file
  • in case you change your OS (once again), you will still be able to re-use your dotfiles

However, you will not be able to use Nix variables. So if the package does not need to have any Nix variable, you can configure your package like this:

# Create symlink on the whole config/ folder on `~/.config/nvim`.
xdg.configFile.nvim = {
  source = ./config;
  recursive = true;
};

# Create a symlink on a single file at `~`.
home.file.".gitconfig".source = ./config/.gitconfig;

# If you need to use some Nix option along with the configuration file, you
# can use the Nix builtin function `builtins.readFile`
programs.tmux = {
  enable = true;
  shell = "${pkgs.zsh}/bin/zsh";
  extraConfig = ''
    ${builtins.readFile ./.tmux.conf}
  '';
};

# If you need to write text directly in the nix file, because you need to use
# some nix variable:
xdg.configFile."waybar/colorscheme.css".text = ''
@define-color fg #${palette.base05};
@define-color fg-alt #${palette.base00};
@define-color bg #${palette.base00};
@define-color bg-alt #${palette.base0D};
'';

I know you will think there's no consistency, sometimes I'm using Nix to configure applications, sometimes, I use symlink... I wonder if I should just use Nix / home-manager to handle all the package installation stuff and symlink the configuration files... Only time will tell.

LazyVim configuration

Note

LazyVim is a plugin manager that will download the plugins at "runtime". So it does not quite stick to the NixOS philosophy. It's recommended to migrate to something else, like configuring directly in home-manager, or using NixVim instead.

I'm using a symlink to the ${XDG_CONFIG_HOME}/nvim folder, so LazyVim works without much issue, i.e. it will download the plugins, but I can't say the same about plugins that use downloaded binaries, e.g. LSP servers installed by mason.nvim.

I installed and configured nix-ld, so most binaries should work without any problem. If not please check below on how to configure it.

I still don't know if I want to migrate NeoVim to be fully Nix compliant or keep it like this...

Note

I moved all my NeoVim configuration to the stow/ folder, as updating a NeoVim Lua file through home-manager resulted in slow feedback (~20s).

Styling

I used stylix to manage color schemes and themes. So it should be easy to add new themes without much hassle.

You can add them at the themes folder.

Creating a new secret

You need to put some secret and use it in some configuration?

Check your secrets private repository.

Adding new zsh completion scripts

Sometimes, some commands are not available in the default zsh completions.

However, some tools provide a completion script that is generated for you, e.g.:

just --completion zsh
helm completion zsh

So after adding the completion script in your ${XDG_CONFIG_HOME}/zsh/completions folder, you will notice that the completion does not work yet. It's because we are using a plugin that caches the completion script. So you will need to refresh the cache by calling the following:

refresh-zsh-completions

Then, open a new terminal session, and you are good to go!


Resources

There are lots of Nix documentation, but it's quite hard to find the "right" one depending on your level of understanding of Nix. The official Nix documentation delves a bit too much on the concepts (for the right reasons), whereas I just want to make something work fast.

I found Evertras introduction to home-manager is the best documentation to start with Nix, along with zero-to-nix.

Where to search?

Most of the documentation you will search are the following:

References

Tutorials

Interesting topics

Inspirations