Skip to content

Commit

Permalink
feat: Re-structure flake
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Nov 9, 2023
1 parent ea5a1b0 commit 60b187f
Show file tree
Hide file tree
Showing 31 changed files with 477 additions and 227 deletions.
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
#
# SPDX-License-Identifier: Apache-2.0

# try to use flake initially, fallback to non-flake use otherwise
if nix flake show &> /dev/null; then
use flake
else
use nix
fi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ result-*
.terraform
.terraform.*
terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.backup
.idea
17 changes: 17 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
#
# SPDX-License-Identifier: Apache-2.0
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{src = ./.;}
)
.defaultNix
101 changes: 96 additions & 5 deletions flake.lock

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

81 changes: 37 additions & 44 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
inputs = {
# Nixpkgs
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
# Allows us to structure the flake with the NixOS module system
flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
# Secrets with sops-nix
sops-nix = {
url = "github:mic92/sops-nix";
Expand All @@ -15,60 +18,50 @@
};
# Binary cache with nix-serve-ng
nix-serve-ng = {
url = github:aristanetworks/nix-serve-ng;
url = "github:aristanetworks/nix-serve-ng";
inputs.nixpkgs.follows = "nixpkgs";
};
# Disko for disk partitioning
disko = {
url = github:nix-community/disko;
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
# Format all the things
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# For preserving compatibility with non-Flake users
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = {
self,

outputs = inputs @ {
flake-parts,
nixpkgs,
disko,
...
} @ inputs: let
inherit (self) outputs;
# Supported systems for your flake packages, shell, etc.
systems = ["x86_64-linux"];
# forEachSystem [ "x86_64-linux" ] { example = true; } -> { x86_64-linux.example = true }
forEachSystem = nixpkgs.lib.genAttrs systems;
# Imports a module expecting a system to be passed in
importExpectingSystem = module: system:
import module {
pkgs = import nixpkgs {inherit system;};
};
ghaf-infra-shell = importExpectingSystem ./shell.nix;
templateTargets = import ./hosts/templates/targets.nix {inherit nixpkgs disko;};
in {
# nix fmt
formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.alejandra);

# Development shells
devShells = forEachSystem (system: {
# nix develop
default = ghaf-infra-shell system;
});

# NixOS configuration entrypoint
nixosConfigurations = {
# Generic template configurations
template-azure-x86_64-linux = templateTargets.azure-x86_64-linux;
template-generic-x86_64-linux = templateTargets.generic-x86_64-linux;

# Hydra host: ghafhydra
ghafhydra = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs outputs;};
modules = [./hosts/ghafhydra/configuration.nix];
}:
flake-parts.lib.mkFlake
{
inherit inputs;
specialArgs = {
inherit (nixpkgs) lib;
};
} {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];

# Builder host: build01
build01 = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs outputs;};
modules = [./hosts/build01/configuration.nix];
};
imports = [
./hosts
./nix
./services
./users
];
};
};
}
8 changes: 1 addition & 7 deletions hosts/azure-common.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
#
# SPDX-License-Identifier: Apache-2.0
{
inputs,
lib,
config,
pkgs,
...
}: {
{inputs, ...}: {
require = [
"${inputs.nixpkgs}/nixos/modules/virtualisation/azure-agent.nix"
];
Expand Down
25 changes: 14 additions & 11 deletions hosts/build01/configuration.nix → hosts/build01/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
#
# SPDX-License-Identifier: Apache-2.0
{
self,
inputs,
lib,
config,
pkgs,
...
}: {
imports = [
inputs.disko.nixosModules.disko
../generic-disk-config.nix
../common.nix
../azure-common.nix
../../services/openssh/openssh.nix
../../users/builder.nix
../../users/hrosten.nix
../../users/bmg.nix
imports = lib.flatten [
[
inputs.disko.nixosModules.disko
]
(with self.nixosModules; [
common
azure-common
generic-disk-config
service-openssh
user-bmg
user-builder
user-hrosten
])
];
networking.hostName = "build01";
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
Expand Down
33 changes: 33 additions & 0 deletions hosts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
#
# SPDX-License-Identifier: Apache-2.0
{
self,
inputs,
lib,
...
}: {
flake.nixosModules = {
# shared modules
azure-common = import ./azure-common.nix;
common = import ./common.nix;
generic-disk-config = import ./generic-disk-config.nix;
# host modules
host-build01 = import ./build01;
host-ghafhydra = import ./ghafhydra;
};

flake.nixosConfigurations = let
# make self and inputs available in nixos modules
specialArgs = {inherit self inputs;};
in {
build01 = lib.nixosSystem {
inherit specialArgs;
modules = [self.nixosModules.host-build01];
};
ghafhydra = lib.nixosSystem {
inherit specialArgs;
modules = [self.nixosModules.host-ghafhydra];
};
};
}
1 change: 0 additions & 1 deletion hosts/generic-disk-config.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
#
# SPDX-License-Identifier: Apache-2.0
# BIOS compatible gpt partition
{lib, ...}: {
disko.devices = {
disk.disk1 = {
Expand Down
Loading

0 comments on commit 60b187f

Please sign in to comment.