Skip to content
Open
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
21 changes: 0 additions & 21 deletions flake.lock

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

102 changes: 56 additions & 46 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
Comment on lines 6 to 9
Copy link
Contributor

@roberth roberth Dec 11, 2024

Choose a reason for hiding this comment

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

Instead of removing flake-parts, or in addition to removing it, you could gain some fetching (or really, locking) efficiency by moving these two over to the dev partition instead.

};

outputs =
inputs@{ flake-parts, nix-github-actions, ... }:
{
self,
nix-github-actions,
nixpkgs,
treefmt-nix,
...
}:
let
inherit (inputs.nixpkgs) lib;
inherit (inputs) self;
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
inherit (nixpkgs) lib;

in
flake-parts.lib.mkFlake { inherit inputs; } {
systems = inputs.nixpkgs.lib.systems.flakeExposed;
imports = [
inputs.flake-parts.flakeModules.modules
inputs.flake-parts.flakeModules.partitions
./lib/modules.nix
./templates/flake-module.nix
];
{

flake.githubActions = nix-github-actions.lib.mkGithubMatrix {
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = {
x86_64-linux = builtins.removeAttrs (self.packages.x86_64-linux // self.checks.x86_64-linux) [
Copy link
Member

@Mic92 Mic92 Dec 11, 2024

Choose a reason for hiding this comment

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

Is there actually a better API to this? This will silently ignore conflicts in those two sets. Also mkGithubMatrix should be able to filter out itself by doing a builtins.groupBy

"default"
Expand All @@ -38,63 +36,75 @@
};
};

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

perSystem =
{
config,
pkgs,
self',
...
}:
templates = {
flake-parts = {
description = "Example flake with nix-unit and flake-parts";
path = ./templates/flake-parts;
};
};

# TODO: Figure out how to distribute flake-parts without using flake-parts on the top-level
modules = throw "Dunno lol";
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure how to do this.

Copy link
Member

@Mic92 Mic92 Dec 11, 2024

Choose a reason for hiding this comment

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

$ nix repl .
nix-repl> :p modules
{
  flake = {
    default = {
      _class = "flake";
      _file = "/nix/store/m3z8yiszmgzj9nj921h6frw2jddhxy4q-source/flake.nix#modules.flake.default";
      imports = [
        {
          imports = [
            {
              _file = "/nix/store/m3z8yiszmgzj9nj921h6frw2jddhxy4q-source/lib/modules.nix, via option flake.modules.flake.default";
              imports = [ «lambda default @ /nix/store/m3z8yiszmgzj9nj921h6frw2jddhxy4q-source/lib/modules.nix:26:7» ];
            }
          ];
        }
      ];
    };
    testsOutput = {
      _class = "flake";
      _file = "/nix/store/m3z8yiszmgzj9nj921h6frw2jddhxy4q-source/flake.nix#modules.flake.testsOutput";
      imports = [
        {
          imports = [
            {
              _file = "/nix/store/m3z8yiszmgzj9nj921h6frw2jddhxy4q-source/lib/modules.nix, via option flake.modules.flake.testsOutput";
              imports = [ /nix/store/m3z8yiszmgzj9nj921h6frw2jddhxy4q-source/lib/modules/flakes/tests-output.nix ];
            }
          ];
        }
      ];
    };
  };
}

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like this?

{
  modules.flake.default.imports = [ ./my-module.nix ];
}


packages = forAllSystems (
system:
let
inherit (pkgs) stdenv;
pkgs = nixpkgs.legacyPackages.${system};
drvArgs = {
nix = pkgs.nixVersions.nix_2_24;
};
in
{
packages.nix-unit = pkgs.callPackage ./default.nix drvArgs;
packages.default = self'.packages.nix-unit;
packages.doc = pkgs.callPackage ./doc {
nix-unit = pkgs.callPackage ./default.nix drvArgs;
default = self.packages.${system}.nix-unit;
doc = pkgs.callPackage ./doc {
inherit self;
};
devShells.default =
}
);

formatter = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
(treefmt-nix.lib.evalModule pkgs ./dev/treefmt.nix).config.build.wrapper
Copy link
Member

@Mic92 Mic92 Dec 11, 2024

Choose a reason for hiding this comment

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

This is still missing checks.treefmt in CI.

);

devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) stdenv;
drvArgs = {
nix = pkgs.nixVersions.nix_2_24;
};
in
{
default =
let
pythonEnv = pkgs.python3.withPackages (_ps: [ ]);
in
pkgs.mkShell {
nativeBuildInputs = self'.packages.nix-unit.nativeBuildInputs ++ [
nativeBuildInputs = self.packages.${system}.nix-unit.nativeBuildInputs ++ [
pythonEnv
pkgs.difftastic
pkgs.nixdoc
pkgs.mdbook
pkgs.mdbook-open-on-gh
pkgs.mdbook-cmdrun
config.treefmt.build.wrapper
self.formatter.${system}
];
inherit (self'.packages.nix-unit) buildInputs;
inherit (self.packages.${system}.nix-unit) buildInputs;
shellHook = lib.optionalString stdenv.isLinux ''
export NIX_DEBUG_INFO_DIRS="${pkgs.curl.debug}/lib/debug:${drvArgs.nix.debug}/lib/debug''${NIX_DEBUG_INFO_DIRS:+:$NIX_DEBUG_INFO_DIRS}"
export NIX_UNIT_OUTPATH=${self}
'';
};
};
}
);

# Extra things to load only when accessing development-specific attributes
# such as `checks`
partitionedAttrs.checks = "dev";
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this line disconnects the check derivation for the flake-parts module.

Considering that subflakes still are still quite broken until the next NixOS release, it still has to be wired through /flake.nix.
You'll need flake-compat to load the inputs from dev and then cherry-pick the relevant attributes from a mkFlake call that resembles a combination of module below.

(I guess that's a partial answer to your question about the added value here. flake-parts.flakeModules.partitions is a ready to use solution for this.)

Choose a reason for hiding this comment

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

subflakes still are still quite broken until the next NixOS release

where can I find out about the upcoming improvements? Thanks!

partitionedAttrs.devShells = "dev";
partitionedAttrs.tests = "dev"; # lib/modules/flake/dogfood.nix
partitions.dev.module = {
imports = [
inputs.treefmt-nix.flakeModule
self.modules.flake.default
./lib/modules/flake/dogfood.nix
];
perSystem = {
treefmt.imports = [ ./dev/treefmt.nix ];
};
};
};
}
Loading