Skip to content

Commit

Permalink
nix: refactor + update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kranzes committed Sep 30, 2023
1 parent 63fd3b9 commit c67eec0
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 184 deletions.
32 changes: 27 additions & 5 deletions flake.lock

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

131 changes: 10 additions & 121 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,128 +1,17 @@
{
nixConfig.bash-prompt = "\\[\\033[01;32m\\][nix-flakes \\W] \$\\[\\033[00m\\] ";

inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; };
};
outputs = { self, nixpkgs, ... }:
let
# System types to support.
supportedSystems = [ "x86_64-linux" ];

# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);

# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlays.default ]; });
in
{
overlays.default = (final: prev:
with final.pkgs;
rec {
scaleTests = callPackage ./nix/tests/allTests.nix { };
massflash = callPackage ./nix/pkgs/massflash.nix { };
scaleInventory = callPackage ./nix/pkgs/scaleInventory.nix { };
});

packages = forAllSystems (system: {
inherit (nixpkgsFor.${system}) scaleTests scaleInventory;
});

nixosConfigurations =
let
# All scale common modules
system = "x86_64-linux";
common =
({ modulesPath, ... }: {
imports = [
./nix/modules/bhyve-image.nix
./nix/machines/_common/users.nix
];
});
pkgs = nixpkgsFor.${system};
in
{
loghost = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
common
./nix/machines/loghost.nix
];
};
massflash = nixpkgs.lib.nixosSystem {
inherit system pkgs;
modules = [
({ modulesPath, ... }: {
imports = [
"${toString modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
];
})
./nix/machines/massflash.nix
];
};
coreMaster = nixpkgs.lib.nixosSystem {
inherit system pkgs;
modules = [
common
./nix/machines/core/master.nix
];
specialArgs = { inherit self; };
};
coreSlave = nixpkgs.lib.nixosSystem {
inherit system pkgs;
modules = [
common
./nix/machines/core/slave.nix
];
};
signs = nixpkgs.lib.nixosSystem {
inherit system pkgs;
modules = [
common
./nix/machines/signs.nix
];
};
};

# Like nix-shell
# Good example: https://github.com/tcdi/pgx/blob/master/flake.nix
devShells = forAllSystems
(system:
let
pkgs = nixpkgsFor.${system};
in
{
default = import ./shell.nix { inherit pkgs; };
});

checks =
let
pkgs = nixpkgsFor.x86_64-linux;
in
{
# python tests for the data found in facts
# disabling persistence and cache for py utils to avoid warnings
# since caching is taken care of by nix
pytest-facts = pkgs.runCommand "pytest-facts" { } ''
cp -r ${pkgs.lib.cleanSource self}/* .
cd facts
${pkgs.python3Packages.pylint}/bin/pylint --persistent n *.py
${pkgs.python3Packages.pytest}/bin/pytest -vv -p no:cacheprovider
touch $out
'';
perl-switches = pkgs.runCommand "perl-switches"
{
buildInputs = [ pkgs.gnumake pkgs.perl ];
} ''
cp -r ${pkgs.lib.cleanSource self}/* .
cd switch-configuration
make .lint
make .build-switch-configs
touch $out
'';

};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" ];
imports = [
./nix/flake-module.nix
];
};

# Bold green prompt for `nix develop`
# Had to add extra escape chars to each special char
nixConfig.bash-prompt = "\\[\\033[01;32m\\][nix-flakes \\W] \$\\[\\033[00m\\] ";
}
Empty file added hello
Empty file.
45 changes: 45 additions & 0 deletions nix/dev/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
perSystem = { pkgs, ... }:
let
scale_python = pkgs.python3.withPackages (p: with p ; [ pytest pylint ipdb ]);

# Trying to keep these pkg sets separate for later
global = with pkgs; [
bash
curl
git
jq
kermit
screen
glibcLocales
(pkgs.python3.withPackages (p: with p ; [ pytest pylint ipdb ]))
];
ansible_sub = [
pkgs.ansible
pkgs.ansible-lint
];
openwrt_sub = with pkgs; [
expect
gomplate
magic-wormhole
tftp-hpa
nettools
unixtools.ping
iperf3
ncurses
ncurses.dev
pkg-config
gcc
stdenv
];
network_sub = [ pkgs.perl ];
in
{
devShells.default = pkgs.mkShell {
packages = global
++ ansible_sub
++ openwrt_sub
++ network_sub;
};
};
}
9 changes: 9 additions & 0 deletions nix/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
imports = [
./pkgs/flake-module.nix
./tests/flake-module.nix
./modules/flake-module.nix
./machines/flake-module.nix
./dev/flake-module.nix
];
}
6 changes: 3 additions & 3 deletions nix/machines/core/common.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }:
{ config, lib, pkgs, inputs, ... }:

{
# If not present then warning and will be set to latest release during build
Expand All @@ -22,7 +22,7 @@
ldns
bind
kea
scaleInventory
inputs.self.packages.${pkgs.system}.scaleInventory
vim
git
];
Expand All @@ -49,7 +49,7 @@
kea = {
dhcp4 = {
enable = true;
configFile = "${pkgs.scaleInventory}/config/kea.json";
configFile = "${inputs.self.packages.${pkgs.system}.scaleInventory}/config/kea.json";
};
};
};
Expand Down
12 changes: 6 additions & 6 deletions nix/machines/core/master.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ config, lib, pkgs, self, ... }:
{ config, lib, pkgs, inputs, ... }:
let
zoneSerial = toString self.lastModified;
zoneSerial = toString inputs.self.lastModified;
in
{

Expand All @@ -18,7 +18,7 @@ in
'';
};

# Make sure that the makes of these files are actually lexicographically before 99-default.link provides by systemd defaults since first match wins
# Make sure that the nix/machines/core/master.nixmakes of these files are actually lexicographically before 99-default.link provides by systemd defaults since first match wins
# Ref: https://github.com/systemd/systemd/issues/9227#issuecomment-395500679
systemd.network = {
enable = true;
Expand Down Expand Up @@ -56,7 +56,7 @@ in
IN NS coreexpo.scale.lan.
IN NS coreconf.scale.lan.
''
(builtins.readFile "${pkgs.scaleInventory}/config/db.scale.lan.records")
(builtins.readFile "${inputs.self.packages.${pkgs.system}.scaleInventory}/config/db.scale.lan.records")
]);
};
"10.in-addr.arpa." = {
Expand All @@ -76,7 +76,7 @@ in
IN NS coreexpo.scale.lan.
IN NS coreconf.scale.lan.
''
(builtins.readFile "${pkgs.scaleInventory}/config/db.ipv4.arpa.records")
(builtins.readFile "${inputs.self.packages.${pkgs.system}.scaleInventory}/config/db.ipv4.arpa.records")
]);
};
# 2001:470:f026::
Expand All @@ -97,7 +97,7 @@ in
IN NS coreexpo.scale.lan.
IN NS coreconf.scale.lan.
''
(builtins.readFile "${pkgs.scaleInventory}/config/db.ipv6.arpa.records")
(builtins.readFile "${inputs.self.packages.${pkgs.system}.scaleInventory}/config/db.ipv6.arpa.records")
]);
};
};
Expand Down
63 changes: 63 additions & 0 deletions nix/machines/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{ lib, inputs, ... }:

let
# All scale common modules
system = "x86_64-linux";
common = {
imports = [
inputs.self.nixosModules.bhyve-image
./_common/users.nix
];
};
in
{
flake.nixosConfigurations =
{
loghost = lib.nixosSystem {
inherit system;
modules = [
common
./loghost.nix
];
specialArgs = { inherit inputs; };
};
massflash = lib.nixosSystem {
inherit system;
modules = [
({ modulesPath, ... }: {
imports = [
"${ toString modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
];
})
./massflash.nix
];
specialArgs = { inherit inputs; };
};
coreMaster = lib.nixosSystem {
inherit system;
modules = [
common
./core/master.nix
];
specialArgs = { inherit inputs; };
};
coreSlave = lib.nixosSystem {
inherit system;
modules = [
common
./core/slave.nix
];
specialArgs = { inherit inputs; };
};
signs = lib.nixosSystem {
inherit system;
modules = [
common
./signs.nix
];
specialArgs = { inherit inputs; };
};
};


}
Loading

0 comments on commit c67eec0

Please sign in to comment.