Manage configs/dotfiles with git repositories

Hello! I recently found out about NixOS and I absolutely fell in love with the premises. I am, as a complete noob, testing in a VM to check if I could use it as my daily driver, but I am right now in a hard moment of the learning curve.

I have my Emacs configuration in a git repository, that I would like to include in my nix configuration so that it is alway present. Right now the closest thing that I found is home-manager, which I am almost sure is the way to go. Using the first functions declared in the linked example of the wiki (yrashk/nix-home), especially fetchLatestGit I am able to get the configuration exactly in the location I wanted to automatically. However, this function just gets the source code - I am more interesting in actually cloning the repository for this. I am constantly tweaking the configuration and I need to push the changes upstream in any case. I was not able to find the proper way to do this, is there function for something like this?

I am also interested: how have you solved problems similar to this? I feel like a little bit of creativity could work around it just fine, but I am still not savvy enough in nix to find the proper way to do it.

6 Likes

I would recommend the following collection of NixOS users managing their homes/machines:
https://nixos.wiki/wiki/Configuration_Collection
e.g. afaik John Wiegley is using home manager: GitHub - jwiegley/nix-config: My local Nix configuration
from my behalf i resist to use home-manager and do everything with the activation scripts of nix-darwin: GitHub - periklis/nix-config: My personal declarative macOS machine configuration

1 Like

I keep my home-manager config in Seafile and also on GitHub - manveru/dotfiles: Just my dotfiles for home-manager
That makes sure that they’re always synced across my machines, but also in case of something going horribly wrong I have a backup on GitHub.

1 Like

On this subject, I’d like people’s opinions, how silly is it to attempt remplacing nixos-config=/etc/nixos/configuration.nix by nixos-config=git@git:myrepo in the NIX_PATH ?
I recently installed NixOS on all family computers and I’d like to share software and user profiles across them, possibly have them auto-update with the system.autoUpdate config
However I’m kind of anxious about any safeties I’d be losing by not using /etc/nixos/configuration.nix ?
How should I handle per-machine settings, just read hostname?

1 Like

Reading the hostname may cause an initial bootstrapping issue.

A random idea, nothing stops you from having a state file which could be as simple as having the name of the machine in it.

/etc/nixos/machine.nix

"my-machine"

And your repo would know to load this from its well-known path. Alternatively, you could also add another entry to NIX_PATH machine-config=/etc/nixos/machine.nix and import it through <machine-config>.


Here’s an example transcript with adding to NIX_PATH:

~ $ cat /etc/nixos/machine.nix
"duffman"
~ $ nix repl '<nixpkgs>' -I machine-config=/etc/nixos/machine.nix
Welcome to Nix version 2.1pre6148_a4aac7f. Type :? for help.
Loading '<nixpkgs>'...
Added 8636 variables.
nix-repl> import <machine-config>
"duffman"

Adding to NIX_PATH has one drawback: you cannot use builtins.pathExists to check file existence:

nix-repl> builtins.pathExists <machine-config>
warning: Nix search path entry '/etc/nixos/machine.nix' does not exist, ignoring
error: file 'machine-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:21
1 Like

I was thinking of something similar, I’ll probably be headed that way, thanks.

I read somewhere, once, about using nixops to deploy to local machines instead of spinning up VPSes, is that possible ? Should I read into it more?

Hi,

I read somewhere, once, about using nixops to deploy to local machines
instead of spinning up VPSes, is that possible ? Should I read into it
more?

Absolutely - we’re using that with great success! If you have other means to get the VMs or bare metal running NixOS, then simply point nixops at the hosts and everything is sorted. We are using different state files per deployment (one per customer) although those are technically not needed when resources are not provisioned using nixops.

1 Like

I’m surprised I managed to miss that reading the NixOps documentation the first time, I’m a lot more confident about this now, thanks very much all