Coder Social home page Coder Social logo

hugoreeves / elemental Goto Github PK

View Code? Open in Web Editor NEW
51.0 3.0 6.0 88 KB

Elemental, the component parts of a Nix/OS development system.

License: MIT License

Nix 18.02% Shell 14.58% Vim Script 0.38% Python 40.76% Lua 26.26%
nix nixos nixos-configuration nixos-config home-manager dotfiles dotfiles-macos dotfiles-linux

elemental's Introduction

Elemental

The component parts of a Nix/OS development system.

Elemental is my attempt to create a configurable development environment built atop Nix and Home Manager. Elemental is currently setup for userspace configuration using Home Manager, I'm working on integrating my NixOS system configuration into the same repo using the same configuration techniques.

Configuration in Elemental is dividided into three sections, Machine Configuration, Role Configuration and User Configuration. Custom derivations are stored under these three sections, the objective is to allow as much configuration to be shared where possible, whilst keeping configuration compartmentalised so that changing the machine, role or user is easily possible without rewritting configuration files.

Machine

The machine configuration is specific to the individual host system, generally speaking, for each non-homogenous device you manage with Elemental, you should have a separate machine configuration. Currently I maintain machine specific configurations for my NixOS workstation, a Intel Hades Canyon NUC, and my Darwin/MacOS laptop, a 2017 Macbook Pro running Big Sur. Configuration that should be considered 'machine specific' includes things like backup configuration that is depenedent on the systems disk layout, and custom networking software that is specific to the system's hardware.

Role

The majority of Elemental configuration fits into the role category. Currently I maintain two separate role configurations, one for a NixOS workstation and one for a Darwin laptop. Configuration that should be considered 'role' specific includes anything that touches GUI tools, the desktop environment, and shells or prompts. The idea here is that two separate machines could me made to use the same role configuration, if you wanted the same desktop environment and general configuration on both machines.

In some situations, it makes sense to also consider the machine type within some of the Role configurations. An example where this may occur is if you need to reference a machine specific wifi network interface in a desktop status bar configuration. The component being configured here, the desktop status bar, is definitely a part of the role but it is also neccesary to reference the machine being targeted. Some situations like this are unavoidable.

User

User configuration primarily consists of installing the command line utilities the user should have access to, and configuring things like SSH, GPG and Git. I share the same user, 'x', across all my systems. By listing the commandline tools I need installed within the 'x' user configuration, I am able to keep the same tools installed on both my NixOS and MacOS machines.

Usage and Installation

If you would like to adapt Elemental for your own purposes, I would encourage you to fork the repo and begin building your own machine, role and user configurations.

Before installing Elemental, you must install Home Manager, see here for instructions.

Elemental should be installed to ~/.config/nixpkgs. I generally like to have my Elemental repo appear at ~/elemental, so I choose to symlink it into ~/.config/nixpkgs.

You will need to manually add a file called home.nix into the top level of your elemental repo. This file is where you will set the Machine, Role and User to be used in your configuration, it will be ignored by git by default. Within this file you should import ./elemental.nix which defines elemental's configuration options. You should also import ./home/default.nix which imports the individual machine, role and user configuration files. If deploying to a linux system, you should also import ./home/linux-only.nix which imports configurations only available on Linux installations of Nix.

MacOS Example

The following home.nix configuration is for my NixOS desktop.

{ config, pkgs, lib,... }:

{
  imports = [
    ./elemental.nix

    ./home/default.nix

    # Import the linux only derivations
    ./home/linux-only.nix
  ];

  # Let Home Manager install itself
  programs.home-manager.enable = true;
  # Allow unfree
  nixpkgs.config.allowUnfree = true;

  elemental.machine = "boron";
  elemental.role = "workstation";
  elemental.user = "x";
}

MacOS Example

The following home.nix configuration is for my Macbook Pro running MacOS Big Sur.

# ./elemental.nix
{ config, pkgs, lib,... }:

{
  imports = [
    ./elemental.nix

    ./home/default.nix
  ];

  # Let Home Manager install itself
  programs.home-manager.enable = true;
  # Allow unfree
  nixpkgs.config.allowUnfree = true;

  elemental.machine = "osmium";
  elemental.role = "darwin-laptop";
  elemental.user = "x";
}

elemental's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

elemental's Issues

Adapting elemental to distributed configurations

Hello! I really like the style of this repo! Especially the part where you store nix configuration for the program in the same folder as this program's config files. And by simply importing it, you build up your dotfiles.

I'm wondering if I can achieve the same. I have my dotfiles spread across multiple repositories though. Is it possible to follow your approach in this scenario? For instance, you have:

{
  imports = [
    ./admin/restic/default.nix
    ./admin/topgrade/default.nix
    ./dev/git/default.nix
    ./editor/neovim/default.nix
    ./file-manager/ranger/default.nix
    ./networking/nmap/default.nix
    ./networking/ssh/default.nix
    ./scripts/index.nix
    ./shell/fish/default.nix
    ./shell/starship/default.nix
    ./terminal/alacritty/default.nix
    ./terminal/tmux/default.nix
  ];
}

But I have my NeoVim config in a separate repo. Can I cook up something like this?

{
  imports = [
    ...
    ./dev/git/default.nix
-    ./editor/neovim/default.nix
+   https://github.com/DeadlySquad13/NeoVim_config/default.nix
    ./file-manager/ranger/default.nix
    ...
  ];
}

While in NeoVim repo there will be a nix file with instruction how to symlink and install this piece of software on my machine. Right now it's not super important for me how to fetch this repo automagically but rather how to build my home-manager config in a distributed way (in multiple repos).

I have read a lot about derivations and flakes which seem up to task but all the examples I have seen are about packaging software, not parts of dotfiles. So I'm not sure how to integrate these flakes with home-manager...

I tried git-submodules in the past but for me they seem a pain to manage. You always end up with a huge main repo - as for me, it kind of breaks the whole point of separating these configs.

I'm a complete newbie in nix ecosystem so I would highly appreciate if you can share your knowledge with me!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.