Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "chore: re-do home-manager" #44

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .taskfiles/nix/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ tasks:
- host
cmds:
- git add .
- nixos-rebuild build --flake "{{.ROOT_DIR}}/#{{.host}}" --impure --fast
- nixos-rebuild build --flake "{{.ROOT_DIR}}/#{{.host}}" --impure
- nvd diff /run/current-system result
preconditions:
- sh: which nix
Expand Down
108 changes: 41 additions & 67 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
{
description = "My nixos homelab";
description = "My machines";

inputs = {
# Nixpkgs and unstable
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";

# nix-community hardware quirks
# https://github.com/nix-community
nixos-hardware.url = "github:NixOS/nixos-hardware/master";

# home-manager - home user+dotfile manager
# https://github.com/nix-community/home-manager
# home-manager
home-manager = {
url = "github:nix-community/home-manager/release-23.11";
inputs.nixpkgs.follows = "nixpkgs";
};

# sops-nix - secrets with mozilla sops
# https://github.com/Mic92/sops-nix
# sops-nix
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# deploy-rs - Remote deployment
# https://github.com/serokell/deploy-rs
# deploy-rs
deploy-rs = {
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs";
};

# VSCode community extensions
# https://github.com/nix-community/nix-vscode-extensions
nix-vscode-extensions = {
url = "github:nix-community/nix-vscode-extensions";
inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -41,7 +33,6 @@
{ self
, nixpkgs
, sops-nix
, home-manager
, ...
} @ inputs:

Expand All @@ -52,18 +43,27 @@
"x86_64-linux"
];

# import overlays, ready for wrapping in nixossystem

in
rec {
# Use nixpkgs-fmt for 'nix fmt'
formatter = forAllSystems (system: nixpkgs.legacyPackages."${system}".nixpkgs-fmt);

nixosModules = import ./nixos/modules/nixos;


nixosConfigurations =
# with self.lib;
with self.lib;
let
defaultModules =
(builtins.attrValues nixosModules) ++
[
sops-nix.nixosModules.sops
];
specialArgs = {
inherit inputs outputs;
};
# Import overlays for building nixosconfig with them.
overlays = import ./nixos/overlays { inherit inputs; };

# generate a base nixos configuration with the
Expand All @@ -73,14 +73,11 @@
, system ? "x86_64-linux"
, nixpkgs ? inputs.nixpkgs
, hardwareModules ? [ ]
# basemodules is the base of the entire machine building
# here we import all the modules and setup home-manager
, baseModules ? [
sops-nix.nixosModules.sops
home-manager.nixosModules.home-manager
./nixos/profiles/global.nix # all machines get a global profile
./nixos/modules/nixos # all machines get nixos modules
./nixos/hosts/${hostname} # load this host's config folder for machine-specific config
./nixos/profiles/global.nix
./nixos/modules/nixos
./nixos/hosts/${hostname}
]
, profileModules ? [ ]
}:
Expand Down Expand Up @@ -159,49 +156,26 @@
];
};

# # nix build .#images.rpi4
# rpi4 = nixpkgs.lib.nixosSystem {
# inherit specialArgs;

# modules = defaultModules ++ [
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# ./nixos/hosts/images/sd-image
# ];
# };
# # nix build .#images.iso
# iso = nixpkgs.lib.nixosSystem {
# inherit specialArgs;

# modules = defaultModules ++ [
# "${nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix"
# "${nixpkgs}/nixos/modules/installer/cd-dvd/iso-image.nix"
# ./nixos/hosts/images/cd-dvd
# ];
# };
};


homeConfigurations = {

# For servers (no gui)
server = { pkgs, lib, username, ... }: {
imports = [
./nixos/home/profiles/global.nix
./nixos/home/profiles/server.nix
./nixos/home/modules
];
};

# For workstations (X11 + awesome)
desktop = { pkgs, lib, username, ... }: {
imports = [
./nixos/home/profiles/global.nix
./nixos/home/profiles/workstation.nix
./nixos/home/modules
];
};

# # nix build .#images.rpi4
# rpi4 = nixpkgs.lib.nixosSystem {
# inherit specialArgs;

# modules = defaultModules ++ [
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# ./nixos/hosts/images/sd-image
# ];
# };
# # nix build .#images.iso
# iso = nixpkgs.lib.nixosSystem {
# inherit specialArgs;

# modules = defaultModules ++ [
# "${nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix"
# "${nixpkgs}/nixos/modules/installer/cd-dvd/iso-image.nix"
# ./nixos/hosts/images/cd-dvd
# ];
# };
};
# simple shortcut to allow for easier referencing of correct
# key for building images
# > nix build .#images.rpi4
Expand Down Expand Up @@ -246,11 +220,11 @@
nixtop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.nixosConfigurations)
(attr: inputs.self.nixosConfigurations.${attr}.config.system.build.toplevel);
hometop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.homeConfigurations)
(attr: inputs.self.homeManagerConfigurations.${attr}.activationPackage);
# hometop = genAttrs
# (builtins.attrNames inputs.self.homeManagerConfigurations)
# (attr: inputs.self.homeManagerConfigurations.${attr}.activationPackage);
in
nixtop // hometop;
nixtop; # // hometop
};

}
59 changes: 59 additions & 0 deletions nixos/home-manager/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
My home infrastructure,

![](https://imgur.com/ISNnzgN.png)

## Structure

- [flake.nix](flake.nix) (Entrypoint for rebuilding via nixos-rebuild or home-manager)
- [flake.lock](flake.lock) (lockfile for current nix flake state, updated daily via [github action](.github/workflows/main.yml))
- [home-manager](home-manager) (User level configuration per machine via home-manager)
- [hosts](hosts/README.md) - (Definition of physical/virutal hosts)
- [common](hosts/common) (Role definitions [Desktop, Laptop, Server])
- [darwin](hosts/common/darwin) (global host configuration used across all darwin hosts)
- [nixos](hosts/common/nixos) (global host configuration used across all NixOS hosts)
- [optional](hosts/common/optional) (optional host configuration used as-needed per host)
- [nas](hosts/nas/README.md) (NixOS NAS server)
- [home](hosts/home/README.md) (NixOS VM running in NAS)
- [cloud](hosts/cloud/README.md) (NixOS VM running in Oracle Cloud)
- [k3s-f](hosts/k3s-f/README.md) (NixOS running on an N100 tiny PC as a k3s node)
- [k3s-g](hosts/k3s-g/README.md) (NixOS running on an N100 tiny PC as a k3s node)
- [k3s-h](hosts/k3s-h/README.md) (NixOS running on an N100 tiny PC as a k3s node)
- [jeffs_laptop](hosts/jeffs_laptop/README.md) (nix-darwin running on a MacBook Pro)
- [jens_laptop](hosts/jens_laptop/README.md) (nix-darwin running on a MacBook Air)
- [work_laptop](hosts/work_laptop/README.md) (nix-darwin running on a MacBook Pro)
- [modules](modules) (Custom NixOS and home-manager modules)
- [overlays](overlays) (Custom overlays, primarily used for packages currently)
- [pkgs](pkgs) (Custom Packages, mainly items not yet in official nixpkgs)
- [shell.nix](shell.nix) (Shell for bootstrapping flake-enabled nix and home-manager)
- [nixpkgs.nix](nixpkgs.nix) (Used by shell.nix - useful to avoid using channels when using legacy nix commands)

## Background

Everyone keeps gushing about how amazing Nix is and I want to get in on the hype cycle

## Goals

- [x] Learn nix
- [x] Mostly reproduce features from my existing [dotfiles](https://github.com/billimek/dotfiles)
- [x] Replace existing ubunut-based 'home VM'
- [x] Expand usage to other shell environments such as WSL, Macbook, etc
- [x] handle secrets - ideally using 1Password and not SOPS - using git-crypt for now
- [x] try agenix for secrets handling
- [ ] introduce the concept of [impermanence](https://github.com/nix-community/impermanence) where appropriate

## References

- [Misterio77/nix-starter-config](https://github.com/Misterio77/nix-starter-configs)
- [How to learn Nix](https://ianthehenry.com/posts/how-to-learn-nix/)
- [home-manager](https://github.com/nix-community/home-manager)
- [Zero to Nix: Everything I Know About Nix & NixOS](https://chetanbhasin.com/articles/zero-to-nix-everything-i-know-about-nix-nixos)
- [Walkthrough of Nix Install and Setup on MacOS (YouTube)](https://www.youtube.com/watch?v=LE5JR4JcvMg)
- [NixOS as a server, part 1: Impermanence](https://guekka.github.io/nixos-server-1/)
- [budimanjojo/dotfiles](https://github.com/budimanjojo/dotfiles/tree/master/nixos)
- [wrmilling/nixos-configuration](https://github.com/wrmilling/nixos-configuration)
- [gshpychka/dotfiles-nix](https://github.com/gshpychka/dotfiles-nix)
- [wimpysworld/nix-config](https://github.com/wimpysworld/nix-config)

## Old Dotfiles

Old dotfiles are still accessible in [archive branch](https://github.com/billimek/dotfiles/tree/archive)
25 changes: 0 additions & 25 deletions nixos/home/modules/default.nix

This file was deleted.

5 changes: 0 additions & 5 deletions nixos/home/modules/shell/default.nix

This file was deleted.

Loading
Loading