Skip to content

Commit

Permalink
Merge pull request #21 from truxnell/module-refactor
Browse files Browse the repository at this point in the history
feat: module refactor go bang crash clatter
  • Loading branch information
truxnell authored Mar 26, 2024
2 parents 3beb1cb + e76cd4a commit 06315d0
Show file tree
Hide file tree
Showing 74 changed files with 1,413 additions and 1,358 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/diff-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ jobs:
with:
extra_nix_config: |
experimental-features = nix-command flakes
extra-platforms = aarch64-linux
- name: Register binfmt
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- name: Garbage collect build dependencies
run: nix-collect-garbage
Expand Down
41 changes: 37 additions & 4 deletions .taskfiles/nix/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"

vars:
host: $HOSTNAME

tasks:
apply:
switch:
desc: Build and apply nix configuration
silent: true
requires:
vars:
- host
cmds:
- task: build
vars:
host: "{{ .host }}"
- echo "This will switch your config."
- task: .prompt_to_continue
- sudo nixos-rebuild switch --flake "{{.ROOT_DIR}}/#{{.host}}" --impure
preconditions:
Expand All @@ -23,13 +22,47 @@ tasks:
- sh: which nixos-rebuild
msg: "nixos-rebuild not found"

test:
desc: Build and apply nix configuration
silent: true
requires:
vars:
- host
cmds:
- echo "This will test your config."
- task: .prompt_to_continue
- sudo nixos-rebuild test --flake "{{.ROOT_DIR}}/#{{.host}}" --impure
preconditions:
- sh: which nix
msg: "nix not found"
- sh: which nixos-rebuild
msg: "nixos-rebuild not found"

dry-run:
desc: Build and apply nix configuration
silent: true
requires:
vars:
- host
cmds:
- echo "This will dry-run your config and add your untracked git files."
- git add .
- nixos-rebuild dry-run --flake "{{.ROOT_DIR}}/#{{.host}}" --impure
preconditions:
- sh: which nix
msg: "nix not found"
- sh: which nixos-rebuild
msg: "nixos-rebuild not found"


build:
desc: Build nix configuration
silent: true
requires:
vars:
- host
cmds:
- git add .
- nixos-rebuild build --flake "{{.ROOT_DIR}}/#{{.host}}" --impure
- nvd diff /run/current-system result
preconditions:
Expand Down
1 change: 1 addition & 0 deletions .taskfiles/pre-commit/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"

vars:
Expand Down
1 change: 1 addition & 0 deletions .taskfiles/sops/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"

tasks:
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ To Install
- [ ] WSL
- [ ] JJY emulator Raspi4
- [ ] Documentation!
- [ ] ssh_config build from computers?
- [ ] Modularise host to allow vm builds and hw builds
- [ ] Add license
- [ ] Add taskfiles

Expand All @@ -66,6 +68,21 @@ cd ~/dotfiles
nixos-rebuild switch --flake .#nameOfMachine --target-host machineToSshInto --use-remote-sudo
```

## Hacking at nix files

Eval config to see what keys are being set.

```bash
nix eval .#nixosConfigurations.rickenbacker.config.security.sudo.WheelNeedsPassword
nix eval .#nixosConfigurations.rickenbacker.config.mySystem.security.wheelNeedsPassword
```

Quickly run a flake to see what the next error message is as you hack.

```bash
nixos-rebuild dry-run --flake . --fast --impure
```

## Links & References

- [Misterio77/nix-starter-config](https://github.com/Misterio77/nix-starter-configs)
Expand Down
3 changes: 3 additions & 0 deletions docs/vm/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Why not recurse the module folder

Imports are special in NIX and its important that they are definet at runtime for lazy evaluation - if you do optional/coded imports not everything is avaliable for evaluating.
131 changes: 75 additions & 56 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,107 +35,124 @@
, sops-nix
, ...
} @ inputs:

let
inherit (self) outputs;
forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-linux"
# "i686-linux"
"x86_64-linux"
# "aarch64-darwin"
# "x86_64-darwin"

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

nixosModules = import ./nixos/modules/nixos;

nixosConfigurations =
with self.lib;
let
defaultModules =
# (builtins.attrValues nixosModules) ++
(builtins.attrValues nixosModules) ++
[
sops-nix.nixosModules.sops
];
specialArgs = {
inherit inputs outputs;
};

# generate a base nixos configuration with the
# specified overlays, hardware modules, and any extraModules applied
mkNixosConfig =
{ hostname
, system ? "x86_64-linux"
, nixpkgs ? inputs.nixpkgs
, hardwareModules ? [ ]
, baseModules ? [
sops-nix.nixosModules.sops
./nixos/profiles/global.nix
./nixos/modules/nixos
./nixos/hosts/${hostname}
]
, profileModules ? [ ]
}:
nixpkgs.lib.nixosSystem {
inherit system;
modules = baseModules ++ hardwareModules ++ profileModules;
specialArgs = { inherit self inputs nixpkgs; };
};
in
{
nixosvm = nixpkgs.lib.nixosSystem {
inherit specialArgs;

"rickenbacker" = mkNixosConfig {
# NixOS laptop (dualboot windows, dunno why i kept it)
hostname = "rickenbacker";
system = "x86_64-linux";
modules = defaultModules ++ [
./nixos/hosts/nixosvm
hardwareModules = [
./nixos/profiles/hw-thinkpad-e14-amd.nix
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-e14-amd
];
};
profileModules = [
./nixos/profiles/role-worstation.nix

rickenbacker = nixpkgs.lib.nixosSystem {
inherit specialArgs;
system = "x86_64-linux";
modules = defaultModules ++ [
./nixos/hosts/rickenbacker
];
};

citadel = nixpkgs.lib.nixosSystem {
inherit specialArgs;
"citadel" = mkNixosConfig {
# Gaming PC (dualboot windows)

hostname = "citadel";
system = "x86_64-linux";
modules = defaultModules ++ [
./nixos/hosts/citadel
hardwareModules = [
./nixos/profiles/hw-gaming-desktop.nix
];
profileModules = [
./nixos/profiles/role-worstation.nix
];

};

dns01 = nixpkgs.lib.nixosSystem {
inherit specialArgs;
"dns01" = mkNixosConfig {
# Rpi for DNS and misc services

hostname = "dns01";
system = "aarch64-linux";
modules = defaultModules ++ [
./nixos/hosts/dns01
hardwareModules = [
./nixos/profiles/hw-rpi4.nix
inputs.nixos-hardware.nixosModules.raspberry-pi-4
];
profileModules = [
./nixos/profiles/role-server.nix
];
};

# dns02 = nixpkgs.lib.nixosSystem {

# # nix build .#images.rpi4
# rpi4 = nixpkgs.lib.nixosSystem {
# inherit specialArgs;
# system = "aarch64-linux";

# modules = defaultModules ++ [
# ./nixos/hosts/dns02
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# ./nixos/hosts/images/sd-image
# ];
# };

# isoimage = nixpkgs.lib.nixosSystem {
# system = "x86_64-linux";
# # nix build .#images.iso
# iso = nixpkgs.lib.nixosSystem {
# inherit specialArgs;

# modules = defaultModules ++ [
# "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-graphical-gnome.nix"
# { isoImage.squashfsCompression = "gzip -Xcompression-level 1"; }
# ./nixos/iso
# "${nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix"
# "${nixpkgs}/nixos/modules/installer/cd-dvd/iso-image.nix"
# ./nixos/hosts/images/cd-dvd
# ];
# };

# 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
images.rpi4 = nixosConfigurations.rpi4.config.system.build.sdImage;
images.iso = nixosConfigurations.iso.config.system.build.isoImage;
# images.rpi4 = nixosConfigurations.rpi4.config.system.build.sdImage;
# images.iso = nixosConfigurations.iso.config.system.build.isoImage;

# deploy-rs
deploy.nodes =
Expand All @@ -147,7 +164,7 @@
inherit (configuration.config.nixpkgs.hostPlatform) system;
in
{
path = deploy-rs.lib."${system}".activate.nixos configuration;
path = inputs.deploy-rs.lib."${system}".activate.nixos configuration;
sshUser = "truxnell";
user = "root";
sshOpts = [ "-t" ];
Expand All @@ -158,11 +175,13 @@
in
{
dns01 = mkDeployConfig "10.8.10.11" self.nixosConfigurations.dns01;
rickenbacker = mkDeployConfig "rickenbacker" self.nixosConfigurations.rickenbacker;

# dns02 = mkDeployConfig "dns02.natallan.com" self.nixosConfigurations.dns02;
};

# deploy-rs: This is highly advised, and will prevent many possible mistakes
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) inputs.deploy-rs.lib;

# Convenience output that aggregates the outputs for home, nixos, and darwin configurations.
# Also used in ci to build targets generally.
Expand Down
Loading

0 comments on commit 06315d0

Please sign in to comment.