Skip to content

Commit

Permalink
refactor: per host config
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Sep 5, 2024
1 parent 7288f00 commit d7de9d7
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 78 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CI for Nammayatri
In the nix shell, run:

```
just deploy
just deploy ny-ci-nixos
```

>[!NOTE]
Expand All @@ -15,5 +15,5 @@ just deploy
## Progress

- [ ] NixOS CI: Running GitHub runners
- [ ] Refactor to prepare for multiple hosts
- [x] Refactor to prepare for multiple hosts
- [ ] macOS CI: nix-darwin
38 changes: 0 additions & 38 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 21 additions & 36 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,36 @@
inputs = {
# Principle inputs (updated by `nix run .#update`)
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
home-manager.url = "github:nix-community/home-manager/release-24.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";

flake-parts.url = "github:hercules-ci/flake-parts";
nixos-flake.url = "github:srid/nixos-flake";
};

outputs = inputs@{ self, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-darwin" ];
imports = [ inputs.nixos-flake.flakeModule ];

flake =
flake.om.ci.default =
let
myUserName = "admin";
hostsConfig =
let
inherit (inputs.nixpkgs.lib) listToAttrs nameValuePair attrNames;
inherit (builtins) map readDir;
#overrideInputs = {
# common = ./common;
#};
hosts = attrNames (readDir ./hosts);
systems = {
ny-ci-nixos = [ "x86_64-linux" ];
};
configForHost = name: {
# inherit overrideInputs;
systems = systems.${name};
dir = "./hosts/${name}";
};
in
listToAttrs (map (name: nameValuePair name (configForHost name)) hosts);
in
{
# Configurations for Linux (NixOS) machines
nixosConfigurations.ny-ci-nixos = self.nixos-flake.lib.mkLinuxSystem {
nixpkgs.hostPlatform = "x86_64-linux";
nixos-flake.sshTarget = "admin@ny-ci-nixos";
imports = [
./nixos/hardware-configuration.nix
./nixos/configuration.nix
{
system.stateVersion = "24.05";
}
# Setup home-manager in NixOS config
self.nixosModules.home-manager
{
home-manager.users.${myUserName} = {
imports = [ self.homeModules.default ];
home.stateVersion = "24.05";
};
}
];
};

# home-manager configuration goes here.
homeModules.default = { pkgs, ... }: {
imports = [ ];
programs.git.enable = true;
programs.starship.enable = true;
programs.bash.enable = true;
};
hostsConfig // {
root.dir = ".";
};

perSystem = { pkgs, ... }: {
Expand Down
96 changes: 96 additions & 0 deletions hosts/ny-ci-nixos/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions hosts/ny-ci-nixos/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
inputs = {
# Principle inputs (updated by `nix run .#update`)
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
home-manager.url = "github:nix-community/home-manager/release-24.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";

flake-parts.url = "github:hercules-ci/flake-parts";
nixos-flake.url = "github:srid/nixos-flake";
};

outputs = inputs@{ self, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-darwin" ];
imports = [ inputs.nixos-flake.flakeModule ];

flake = {
# Configurations for Linux (NixOS) machines
nixosConfigurations.ny-ci-nixos = self.nixos-flake.lib.mkLinuxSystem {
nixpkgs.hostPlatform = "x86_64-linux";
nixos-flake.sshTarget = "admin@ny-ci-nixos";
imports = [
./nixos/hardware-configuration.nix
./nixos/configuration.nix
{
system.stateVersion = "24.05";
}
# Setup home-manager in NixOS config
self.nixosModules.home-manager
{
home-manager.users.admin = {
imports = [ self.homeModules.default ];
home.stateVersion = "24.05";
};
}
];
};

# home-manager configuration goes here.
homeModules.default = { pkgs, ... }: {
imports = [ ];
programs.git.enable = true;
programs.starship.enable = true;
programs.bash.enable = true;
};
};
};
}
File renamed without changes.
File renamed without changes.
12 changes: 10 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
default:
@just --list

deploy:
nix run .#activate ny-ci-nixos
# List hosts
hosts:
ls ./hosts

# Auto-format source tree
fmt:
nix fmt

# Deploy the given host (e.g.: `just deploy sambar`)
deploy HOST:
nix run --override-input common ./common ./hosts/{{HOST}}#activate {{HOST}}

0 comments on commit d7de9d7

Please sign in to comment.