Skip to content

Commit

Permalink
treewide cleanups and refactoring for initial tests (#157)
Browse files Browse the repository at this point in the history
- [x] refactor lib into separate files, similar to NixOS/nixpkgs/lib.
- [x] refactor ci to automatically generate derivations from flake outputs
- [x] remove cluttered indirection statements throughout the codebase
- [x] refactor hosts to allow for upcoming integration tests
- [x] improve ambiguity in the existing docs 
- [x] add [BORS](https://bors.tech) support
- [x] add initial integration test
- [x] write tests documentation
- [x] test lib
- [x] improve version string generation, and do so automatically for pkgs/flake.nix sources

Clean up the codebase as best we can in preparation for #152 and add tests. From now on, all PRs will be merged with BORS.
  • Loading branch information
nrdxp committed Mar 14, 2021
1 parent b06adb8 commit c012f2f
Show file tree
Hide file tree
Showing 33 changed files with 758 additions and 447 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
watch_file **/*.nix
watch_file shell/* flake.nix
use flake || use nix
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
[![Build](https://img.shields.io/github/checks-status/divnix/devos/core)](https://hercules-ci.com/github/divnix/devos/jobs)
[![Bors enabled](https://bors.tech/images/badge_small.svg)](https://app.bors.tech/repositories/32678)
[![MIT License](https://img.shields.io/github/license/divnix/devos)][mit]
[![NixOS 20.09](https://img.shields.io/badge/NixOS-v20.09-blue.svg?style=flat&logo=NixOS&logoColor=white)](https://nixos.org)

> #### ⚠ Advisory ⚠
> DevOS leverages the [flakes][flakes] feature available via an _experimental_
> branch of [nix][nix]. Until nix 3.0 is released, this project should be
> considered unstable, though quite usable as flakes have been maturing
> _well_
> [for a while](https://github.com/divnix/devos/tree/17713c22d07c54525c728c62060a0428b76dee3b).
> DevOS requires the [flakes][flakes] feature available via an _experimental_
> branch of [nix][nix]. Until nix 3.0 is released, this project
> should be considered unstable, though quite usable as flakes have been
> maturing _well_ [for a while](https://github.com/divnix/devos/tree/17713c22d07c54525c728c62060a0428b76dee3b).
# Introduction
DevOS grants a simple way to use, deploy and manage [NixOS][nixos] systems for
personal and productive use. It does this by providing a convenient repository
structure, integrating several popular projects like
[home-manager][home-manager], and [devshell][devshell], and offering useful
conveniences like
personal and productive use. A sane repository structure is provided,
integrating several popular projects like [home-manager][home-manager],
[devshell][devshell], and [more](./doc/integrations).

Stiving for ___nix first™___ solutions with unobstrusive implementations,
a [flake centric][flake-doc] approach is taken for useful conveniences such as
[automatic source updates](./pkgs#automatic-source-updates).

Skip the indeterminate nature of other systems, _and_ the perceived difficulty
of Nix. It's easier than you think!
Skip the indeterminate nature of other systems, _and_ the perceived
tedium of bootstrapping Nix. It's easier than you think!

### Status
Alpha. A lot of the implementation is less than perfect, and huge redesigns
_will_ happen. There are unstable versions (0._x_._x_) to help users keep
track of changes and progress.
### Status: Alpha
A lot of the implementation is less than perfect, and huge
[redesigns](https://github.com/divnix/devos/issues/152) _will_ happen. There
are unstable versions (0._x_._x_) to help users keep track of changes and
progress.

## Getting Started
Check out the [guide](https://devos.divnix.com/doc/start) to get up and running.
Expand All @@ -36,8 +38,8 @@ make critical comments about the [code][please]. 😜
NixOS provides an amazing abstraction to manage our environment, but that new
power can sometimes bring feelings of overwhelm and confusion. Having a turing
complete system can easily lead to unlimited complexity if we do it wrong.
Instead, we should have a community consensus on how to manage a NixOS system.
Help us reach that goal!
Instead, we should have a community consensus on how to manage a NixOS system
and its satellite projects, from which best practices can evolve.

___The future is declarative! 🎉___

Expand Down Expand Up @@ -73,6 +75,7 @@ DevOS is licensed under the [MIT License][mit].
[nixos]: https://nixos.org/manual/nixos/stable
[home-manager]: https://nix-community.github.io/home-manager
[flakes]: https://nixos.wiki/wiki/Flakes
[flake-doc]: https://github.com/NixOS/nix/blob/master/src/nix/flake.md
[core]: https://github.com/divnix/devos
[community]: https://github.com/divnix/devos/tree/community
[dotfiles]: https://github.com/hlissner/dotfiles
Expand Down
5 changes: 3 additions & 2 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Profiles](./profiles/README.md)
- [Secrets](./secrets/README.md)
- [Suites](./suites/README.md)
- [Tests](./tests/README.md)
- [Users](./users/README.md)
- [flk](./doc/flk/index.md)
- [up](./doc/flk/up.md)
Expand All @@ -25,6 +26,6 @@
- [install](./doc/flk/install.md)
- [home](./doc/flk/home.md)
- [Integrations](doc/integrations/index.md)
- [deploy-rs](./doc/integrations/deploy.md)
- [hercules-ci](./doc/integrations/hercules.md)
- [Deploy RS](./doc/integrations/deploy.md)
- [Hercules CI](./doc/integrations/hercules.md)
- [Contributing](./doc/README.md)
12 changes: 12 additions & 0 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
status = [
"ci/hercules/evaluation",
"ci/hercules/derivations"
]

required_approvals = 1

up_to_date_approvals = true

delete_merged_branches = true

use_squash_merge = true
4 changes: 2 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let
inherit (default.inputs.nixos.lib) recurseIntoAttrs;
inherit (default.inputs.nixos) lib;

default = (import ./compat).defaultNix;
in
builtins.mapAttrs (_: v: recurseIntoAttrs v) default.packages // {
builtins.mapAttrs (_: v: lib.recurseIntoAttrs v) default.packages // {
shell = import ./shell.nix;
}
1 change: 0 additions & 1 deletion doc/CONTRIBUTING.md

This file was deleted.

2 changes: 2 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ relevant docs. Each directory contains its own README.md, which will
automatically be pulled into the [mdbook](https://devos.divnix.com). The book is
rendered on every change, so the docs should always be up to date.

We also use [BORS](https://bors.tech) to ensure that all pull requests pass the
test suite once at least one review is completed.

## Community PRs
While much of your work in this template may be idiosyncratic in nature. Anything
Expand Down
56 changes: 24 additions & 32 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,57 @@
srcs.url = "path:./pkgs";
};

outputs =
inputs@{ ci-agent
, deploy
, devshell
, home
, nixos
, nixos-hardware
, nur
, override
, self
, utils
, ...
}:
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }:
let
inherit (utils.lib) eachDefaultSystem flattenTreeSystem;
inherit (nixos.lib) recursiveUpdate;
inherit (self.lib) overlays nixosModules genPackages genPkgs
genHomeActivationPackages mkNodes;
inherit (self) lib;
inherit (lib) os;

extern = import ./extern { inherit inputs; };

pkgs' = genPkgs { inherit self; };
pkgs' = os.mkPkgs { inherit self; };

outputs =
let
system = "x86_64-linux";
pkgs = pkgs'.${system};
in
{
inherit nixosModules overlays;

nixosConfigurations =
import ./hosts (recursiveUpdate inputs {
import ./hosts (nixos.lib.recursiveUpdate inputs {
inherit pkgs system extern;
inherit (pkgs) lib;
});

nixosModules =
let moduleList = import ./modules/module-list.nix;
in lib.pathsToImportedAttrs moduleList;

overlay = import ./pkgs;
overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays);

lib = import ./lib { inherit nixos pkgs; };

templates.flk.path = ./.;

templates.flk.description = "flk template";

defaultTemplate = self.templates.flk;

deploy.nodes = mkNodes deploy self.nixosConfigurations;
deploy.nodes = os.mkNodes deploy self.nixosConfigurations;

checks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy)
deploy.lib;
checks =
let
tests = import ./tests { inherit self pkgs; };
deployChecks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy)
deploy.lib;
in
nixos.lib.recursiveUpdate tests deployChecks;
};

systemOutputs = eachDefaultSystem (system:
systemOutputs = utils.lib.eachDefaultSystem (system:
let pkgs = pkgs'.${system}; in
{
packages = flattenTreeSystem system
(genPackages {
packages = utils.lib.flattenTreeSystem system
(os.mkPackages {
inherit self pkgs;
});

Expand All @@ -94,9 +86,9 @@
};

legacyPackages.hmActivationPackages =
genHomeActivationPackages { inherit self; };
os.mkHomeActivation { inherit self; };
}
);
in
recursiveUpdate outputs systemOutputs;
nixos.lib.recursiveUpdate outputs systemOutputs;
}
147 changes: 77 additions & 70 deletions hosts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,96 @@
, home
, lib
, nixos
, nixos-hardware
, override
, pkgs
, self
, system
, ...
}:
let
inherit (lib.flk) recImport nixosSystemExtended defaultImports;
inherit (builtins) attrValues removeAttrs;
inherit (lib) dev;

suites = import ../suites { inherit lib; };

config = hostName:
nixosSystemExtended {
inherit system;

specialArgs = extern.specialArgs // { inherit suites; };

modules =
modules =
let
core = ../profiles/core;
modOverrides = { config, overrideModulesPath, ... }:
let
core = ../profiles/core;

modOverrides = { config, overrideModulesPath, ... }:
let
overrides = import ../overrides;
inherit (overrides) modules disabledModules;
in
{
disabledModules = modules ++ disabledModules;
imports = map
(path: "${overrideModulesPath}/${path}")
modules;
};

global = {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

hardware.enableRedistributableFirmware = lib.mkDefault true;

networking.hostName = hostName;

nix.nixPath = [
"nixpkgs=${nixos}"
"nixos-config=${self}/compat/nixos"
"home-manager=${home}"
];

nixpkgs = { inherit pkgs; };

nix.registry = {
devos.flake = self;
nixos.flake = nixos;
override.flake = override;
};

system.configurationRevision = lib.mkIf (self ? rev) self.rev;
};

local = {
require = [
"${toString ./.}/${hostName}.nix"
];
};

# Everything in `./modules/list.nix`.
flakeModules =
attrValues self.nixosModules;

overrides = import ../overrides;
inherit (overrides) modules disabledModules;
in
flakeModules ++ [
core
global
local
modOverrides
] ++ extern.modules;

{
disabledModules = modules ++ disabledModules;
imports = map
(path: "${overrideModulesPath}/${path}")
modules;
};

global = {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

hardware.enableRedistributableFirmware = lib.mkDefault true;

nix.nixPath = [
"nixpkgs=${nixos}"
"nixos-config=${self}/compat/nixos"
"home-manager=${home}"
];

nixpkgs = { inherit pkgs; };

nix.registry = {
devos.flake = self;
nixos.flake = nixos;
override.flake = override;
};

system.configurationRevision = lib.mkIf (self ? rev) self.rev;
};

# Everything in `./modules/list.nix`.
flakeModules =
builtins.attrValues self.nixosModules;

in
flakeModules ++ [
core
global
modOverrides
] ++ extern.modules;

specialArgs = extern.specialArgs // { inherit suites; };

mkHostConfig = hostName:
let
local = {
require = [
"${toString ./.}/${hostName}.nix"
];

networking = { inherit hostName; };
};
in
dev.os.devosSystem {
inherit system specialArgs;

modules = modules ++ [
local
{
lib = { inherit specialArgs; };
lib.testModule = {
imports = modules;
};
}
];
};

hosts = recImport {
dir = ./.;
_import = config;
};
hosts = dev.os.recImport
{
dir = ./.;
_import = mkHostConfig;
};
in
hosts
Loading

0 comments on commit c012f2f

Please sign in to comment.