Skip to content

Commit

Permalink
Merge pull request #430 from Jovian-Experiments/fix/no-op-oversight
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldr authored Oct 21, 2024
2 parents bb69165 + 0c09446 commit 82bdda1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/no-op.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Module No-Op
on:
pull_request:
push:
jobs:
eval:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4

- name: Verify module is a No-Op
run: nix-instantiate ./support/nix-tests/check-no-ops.nix
5 changes: 3 additions & 2 deletions modules/steamos/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, ... }:
{ lib, config, ... }:

let
inherit (lib)
Expand All @@ -19,7 +19,8 @@ in
jovian.steamos = {
useSteamOSConfig = mkOption {
type = types.bool;
default = true;
default = config.jovian.steam.enable;
defaultText = "config.jovian.steam.enable";
description = ''
Whether to enable opinionated system configuration from SteamOS.
Expand Down
50 changes: 50 additions & 0 deletions support/nix-tests/check-no-ops.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env nix-instantiate
#
# SPDX-License-Identifier: MIT
#
# Author: Samuel Dionne-Riel
#
# What's this? A shebang and +x in my Nix expression??
# ¯\_(ツ)_/¯
#
# Test that eval for unconfigured modules are no-ops.
#
# Origin: https://gitlab.com/samueldr/nixos-configuration/-/blob/cb5c6a1671ebeb1250e4f00e89787f15f45a37f1/modules/tests/check-no-ops.nix
#

let nixpkgs = ../../nixpkgs.nix; in
{ pkgs ? import nixpkgs {} }:

let
baseCfg = {
# Prevent stray warnings
system.stateVersion = "00.00";
# Ignore bootloader asserts
boot.isContainer = true;
# Manual builds will differ since new options are added. This is okay.
documentation.nixos.enable = false;
};
compareEvals = a: b: a.config.system.build.toplevel == b.config.system.build.toplevel;
evalConfig = cfg: (import (pkgs.path + "/nixos")) { configuration = { imports = [ cfg baseCfg ]; }; };
evalModule = module: evalConfig { imports = [ module ]; };
virginEval = evalConfig {};
modules = [
../../modules
];
in
map (modulePath:
let
moduleEval = evalConfig modulePath;
toplevel = moduleEval.config.system.build.toplevel;
vToplevel = virginEval.config.system.build.toplevel;
in
if !(compareEvals moduleEval virginEval)
then
builtins.throw ''
Module '${toString modulePath}' is not a no-op.
${toString modulePath} != virginEval
${toplevel} != ${vToplevel}
''
toplevel
else toplevel
) modules

0 comments on commit 82bdda1

Please sign in to comment.