dragnpkgs/flake.nix

144 lines
5.1 KiB
Nix
Raw Normal View History

{
description = "dragnpkgs together with nixpkgs and lix";
inputs = {
2024-11-21 17:34:53 +00:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
2024-10-21 21:31:19 +00:00
lix-module = {
2024-11-28 03:49:12 +00:00
url = "https://git.lix.systems/lix-project/nixos-module/archive/2.91.1-2.tar.gz";
flake = false;
};
2024-12-02 04:17:48 +00:00
lix = {
2024-11-13 06:09:12 +00:00
url = "https://git.lix.systems/lix-project/lix/archive/2.91.1.tar.gz";
flake = false;
};
};
outputs = { self, nixpkgs, lix, lix-module }:
let
overlays = [
(import ./overlay.nix)
(import "${lix-module}/overlay.nix" { inherit lix; })
];
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
in {
2024-12-02 04:17:48 +00:00
# we don't just use nix.registry.whatever.flake = self
# the reason for this is to be able to handle a flake.lock containing an entry for this
# flake -- setting .flake makes it a path entry in the registry, whereas we want our
# self reference in the registry to be downloadable by URL in case it makes it into a
# flake.lock
meta.registry-entry = {
2024-12-02 04:20:24 +00:00
from = { id = "dragnpkgs"; type = "indirect"; };
2024-12-02 04:17:48 +00:00
to = {
type = "git";
url = "https://git.lain.faith/haskal/dragnpkgs.git";
2024-12-02 05:24:10 +00:00
ref = "nixos-24.11";
2024-12-02 04:17:48 +00:00
} // self.lib.filterAttrs
(n: _: n == "lastModified" || n == "rev" || n == "revCount" || n == "narHash")
self;
};
# the nix path entry for self
2024-12-02 04:20:24 +00:00
meta.path-entry = "dragnpkgs=flake:dragnpkgs";
2024-12-02 04:17:48 +00:00
lib = nixpkgs.lib.extend (final: prev: {
2024-10-21 21:37:02 +00:00
nixosSystem = args:
import "${nixpkgs}/nixos/lib/eval-config.nix" (
{
lib = final;
system = null;
modules = args.modules ++ [
({ config, pkgs, lib, ... }: {
2024-12-02 04:17:48 +00:00
config.nixpkgs = {
# we remove nixpkgs' machinery for setting self flake references and
# replace it with our own (in the next inline module)
flake = {
source = self.outPath;
setNixPath = false;
setFlakeRegistry = false;
};
overlays = overlays;
};
# this is in the flake rather than in module.nix so there's still control over
# channels if you're not using a flake based config. but for flake based
# configs, we're not doing channels anymore
config.nix = {
channel.enable = false;
};
})
({ options, config, pkgs, lib, ...}: {
options.dragnpkgs = {
setFlakeRegistry = lib.mkOption {
description = "Set flake registry option pointing to self";
type = lib.types.bool;
default = true;
defaultText = lib.literalExpression "true";
example = lib.literalExpression "false";
};
setNixPath = lib.mkOption {
description = "Set nix path entry pointing to self";
type = lib.types.bool;
default = true;
defaultText = lib.literalExpression "true";
example = lib.literalExpression "false";
};
setNixpkgsFlakeAlias = lib.mkOption {
description = "Set nix path entry for `nixpkgs` to self";
type = lib.types.bool;
default = true;
defaultText = lib.literalExpression "true";
example = lib.literalExpression "false";
};
2024-12-02 04:17:48 +00:00
};
config.nix.registry.dragnpkgs = lib.mkIf config.dragnpkgs.setFlakeRegistry self.meta.registry-entry;
config.nix.registry.nixpkgs = lib.mkIf config.dragnpkgs.setNixpkgsFlakeAlias {
from = { id = "nixpkgs"; type = "indirect"; };
to = { id = "dragnpkgs"; type = "indirect"; };
2024-12-02 04:17:48 +00:00
};
config.nix.nixPath = lib.mkIf config.dragnpkgs.setNixPath [
self.meta.path-entry
];
2024-10-21 21:37:02 +00:00
})
2024-12-02 04:17:48 +00:00
2024-10-21 21:56:47 +00:00
(import ./module.nix)
2024-10-21 21:37:02 +00:00
];
} // builtins.removeAttrs args [ "modules" ]
);
2024-12-02 04:17:48 +00:00
mkFlake = flakeDef:
let
rewritePerSystem = sectionDef: (forAllSystems (system:
builtins.mapAttrs (name: value:
2024-11-28 04:03:12 +00:00
if final.isDerivation value then
value
else
self.legacyPackages.${system}.callPackage value {}
) sectionDef
));
in
builtins.mapAttrs (name: value:
if name == "packages" || name == "legacyPackages" || name == "devShells" then
rewritePerSystem value
else
value
) flakeDef;
});
legacyPackages = forAllSystems (system:
nixpkgs.legacyPackages.${system}.appendOverlays overlays
);
nixosModules = nixpkgs.nixosModules;
};
}