dragnpkgs/flake.nix

183 lines
6.7 KiB
Nix

{
description = "dragnpkgs together with nixpkgs and lix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
lix-module = {
url = "https://git.lix.systems/lix-project/nixos-module/archive/2.91.1-2.tar.gz";
flake = false;
};
lix = {
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 {
# 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 = {
from = { id = "dragnpkgs-unstable"; type = "indirect"; };
to = {
type = "git";
url = "https://git.lain.faith/haskal/dragnpkgs.git";
ref = "main";
} // self.lib.filterAttrs
(n: _: n == "lastModified" || n == "rev" || n == "revCount" || n == "narHash")
self;
};
# the nix path entry for self
meta.path-entry = "dragnpkgs-unstable=flake:dragnpkgs-unstable";
lib = nixpkgs.lib.extend (final: prev: {
licenses = prev.licenses // { fyptl = import ./lib/licenses/fyptl.nix; };
nixosSystem = args:
import "${nixpkgs}/nixos/lib/eval-config.nix" (
{
lib = final;
system = null;
modules = args.modules ++ [
({ config, pkgs, lib, ... }: {
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 flake registry entry for `nixpkgs` to self";
type = lib.types.bool;
default = true;
defaultText = lib.literalExpression "true";
example = lib.literalExpression "false";
};
setTemplatesFlakeAlias = lib.mkOption {
description = "Set flake registry entry for `templates` to self";
type = lib.types.bool;
default = true;
defaultText = lib.literalExpression "true";
example = lib.literalExpression "false";
};
possiblyCommitCrimes = lib.mkOption {
description = "Globally enable usage of packages marked as FYPTL";
type = lib.types.bool;
default = false;
defaultText = lib.literalExpression "false";
example = lib.literalExpression "false";
};
};
config.nix.registry.dragnpkgs-unstable =
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-unstable"; type = "indirect"; };
};
config.nix.registry.templates = lib.mkIf config.dragnpkgs.setTemplatesFlakeAlias {
from = { id = "templates"; type = "indirect"; };
to = { id = "dragnpkgs-unstable"; type = "indirect"; };
};
config.nix.nixPath = lib.mkIf config.dragnpkgs.setNixPath [
self.meta.path-entry
];
# TODO: also enable this for user-level nix, somehow
config.nixpkgs.config = lib.mkIf config.dragnpkgs.possiblyCommitCrimes {
allowlistedLicenses = [ lib.licenses.fyptl ];
};
})
(import ./module.nix)
];
} // builtins.removeAttrs args [ "modules" ]
);
mkFlake = flakeDef:
let
rewritePerSystem = sectionDef: (forAllSystems (system:
builtins.mapAttrs (name: value:
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;
templates = {
default = {
path = ./templates/default;
description = "A very basic flake (with dragnpkgs)";
};
};
defaultTemplate = self.templates.default;
};
}