dragnpkgs/flake.nix

232 lines
8.7 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-12-17 06:45:42 +00:00
licenses = prev.licenses // { fyptl = import ./lib/licenses/fyptl.nix; };
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 {
2024-12-02 07:11:19 +00:00
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";
};
2024-12-17 06:41:31 +00:00
possiblyCommitCrimes = lib.mkOption {
2024-12-21 20:52:58 +00:00
description = ''
Globally enable usage of packages marked as FYPTL. This installs a nix
plugin, which is widely considered to be a nix crime, and it also might
be an actual crime to use these packages depending on you jurisdiction. Use
at your own risk
'';
2024-12-17 06:41:31 +00:00
type = lib.types.bool;
default = false;
defaultText = lib.literalExpression "false";
example = lib.literalExpression "false";
};
2024-12-02 04:17:48 +00:00
};
2024-12-02 07:11:19 +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
};
2024-12-02 07:11:19 +00:00
config.nix.registry.templates = lib.mkIf config.dragnpkgs.setTemplatesFlakeAlias {
from = { id = "templates"; 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-12-17 06:41:31 +00:00
config.nixpkgs.config = lib.mkIf config.dragnpkgs.possiblyCommitCrimes {
2024-12-17 06:49:54 +00:00
allowlistedLicenses = [ lib.licenses.fyptl ];
2024-12-17 06:41:31 +00:00
};
2024-12-17 07:30:25 +00:00
2024-12-21 20:52:58 +00:00
config.nix.settings.plugin-files =
lib.optionals config.dragnpkgs.possiblyCommitCrimes [
"${pkgs.lix-plugins}/lib/liblix-plugins.so"
];
config.nix.settings.extra-builtins-file =
lib.mkIf config.dragnpkgs.possiblyCommitCrimes (
lib.mkForce "/etc/nix/extra-builtins.nix"
);
config.environment.etc."nix/extra-builtins.nix".source =
lib.mkIf config.dragnpkgs.possiblyCommitCrimes
''
{ ... }: {
dragnpkgs = {
2024-12-21 20:55:12 +00:00
possiblyCommitCrimes = ${config.dragnpkgs.possiblyCommitCrimes};
2024-12-21 20:52:58 +00:00
};
}
'';
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:
2024-12-21 20:52:58 +00:00
let
unsafeConf = if builtins.hasAttr "extraBuiltins" builtins then (
let conf = builtins.extraBuiltins; in
if builtins.isAttrs conf then conf else {}
) else {};
possiblyCommitCrimes =
if
builtins.hasAttr "dragnpkgs" unsafeConf &&
builtins.isAttrs unsafeConf.dragnpkgs &&
builtins.hasAttr "possiblyCommitCrimes" unsafeConf.dragnpkgs &&
builtins.isBool unsafeConf.dragnpkgs.possiblyCommitCrimes
then
unsafeConf.dragnpkgs.possiblyCommitCrimes
else
false;
in
nixpkgs.legacyPackages.${system}.appendOverlays (overlays ++
2024-12-21 20:56:29 +00:00
[(final: prev: {
2024-12-21 20:52:58 +00:00
stdenv = prev.stdenv.override {
config = prev.config // {
allowlistedLicenses = final.lib.optionals
possiblyCommitCrimes
[ final.lib.licenses.fyptl ];
};
};
2024-12-21 20:56:29 +00:00
})])
);
nixosModules = nixpkgs.nixosModules;
2024-12-02 07:11:19 +00:00
templates = {
default = {
path = ./templates/default;
description = "A very basic flake (with dragnpkgs)";
};
};
defaultTemplate = self.templates.default;
};
}