Skip to content

Commit

Permalink
working example with blueprint specific nixos module
Browse files Browse the repository at this point in the history
  • Loading branch information
steveej committed Jan 15, 2025
1 parent 74be977 commit e1f45e5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 59 deletions.
22 changes: 4 additions & 18 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
systems.url = "github:nix-systems/default";

extra-container.url = "github:erikarvstedt/extra-container";
# extra-container.inputs.nixpkgs.follows = "nixpkgs";
extra-container.inputs.nixpkgs.follows = "nixpkgs";
};

outputs =
Expand Down
2 changes: 2 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ let

publisherArgs = {
inherit flake inputs;

# TODO: this isn't there.
inherit (flake) perSystem;
};

Expand Down
32 changes: 32 additions & 0 deletions modules/nixos/unrepro.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# handled by injectPublisherArgs
{
flake,

# throws an error; there might be a bug with this
# perSystem,
...
}:

# this is the module that in the real scenario lives outside of the `runTest` caller code
{
config,
pkgs,
lib,
...
}:

{
imports = [ flake.inputs.extra-container.nixosModules.default ];
config =

# (mysteriously) broken:
# pkgs.lib.mkIf true {

# works:
lib.mkIf true {
environment.systemPackages = [
# perSystem.self.packages.hello
flake.packages.${pkgs.stdenv.system}.hello
];
};
}
58 changes: 18 additions & 40 deletions packages/default.nix
Original file line number Diff line number Diff line change
@@ -1,52 +1,30 @@
{ pkgs, flake, ... }:
{
pkgs,
flake,
system,
...
}:

let
lib = pkgs.lib;
nixos = import (lib.path.append pkgs.path "nixos/lib") { inherit lib; };
in
nixos.runTest (
/*
TODO: what are these arguments? if i put pkgs in here i'm getting:
error: infinite recursion encountered
at /nix/store/cb1gs888vfqxawvc65q1dk6jzbayh3wz-source/lib/modules.nix:1016:24:
1015| { _type = "override";
1016| inherit priority content;
| ^
1017| };
*/
{ ... }:
pkgs.testers.runNixOSTest (
{ lib, ... }:
{
name = "nixos-test";

defaults._module.args = {
inherit flake;
};

nodes.machine =
{ ... }:
{ pkgs, ... }:
{
imports = [
(
# this is the module that in the real scenario lives outside of the `runTest` caller code
{ config, pkgs, lib, flake, ... }:

{
imports = [
flake.inputs.extra-container.nixosModules.default
];
config =
# mysteriously broken:
# pkgs.lib.mkIf true { };
imports = [ flake.nixosModules.unrepro ];

# works:
lib.mkIf true { };
}
)
environment.systemPackages = [
(pkgs.writeShellScriptBin "hello2" ''
exec ${lib.getExe flake.packages.${system}.hello}
'')
];
};

testScript = _: '''';
hostPkgs = pkgs;
testScript = _: ''
machine.succeed("hello")
machine.succeed("hello2")
'';
}
)
1 change: 1 addition & 0 deletions packages/hello.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pkgs, ... }: pkgs.hello

0 comments on commit e1f45e5

Please sign in to comment.