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

[READY] - nix: refactor and update #625

Merged
merged 3 commits into from
Oct 12, 2023
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
41 changes: 0 additions & 41 deletions .github/workflows/switches.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/validate-datafiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ jobs:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix build -L .#checks.pytest-facts
- run: nix build -L .#checks.x86_64-linux.pytest-facts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you run nix flake check it will evaluate all the code in the repo, even nixos configurations and build all derivations under the checks output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, but I think itll have an issue running all tests due to the need for qemu in github actions

- run: nix build -L .#checks.x86_64-linux.perl-switches
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.

120 changes: 10 additions & 110 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,117 +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
'';
};
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
Loading
Loading