get sane.packages to work better. still needs cleanup
This commit is contained in:
parent
4ed0a9127c
commit
09cb75319f
|
@ -11,6 +11,7 @@
|
||||||
./machine-id.nix
|
./machine-id.nix
|
||||||
./net.nix
|
./net.nix
|
||||||
./persist.nix
|
./persist.nix
|
||||||
|
./programs.nix
|
||||||
./secrets.nix
|
./secrets.nix
|
||||||
./ssh.nix
|
./ssh.nix
|
||||||
./users.nix
|
./users.nix
|
||||||
|
|
21
hosts/common/programs.nix
Normal file
21
hosts/common/programs.nix
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
sane.programs = {
|
||||||
|
btrfs-progs.enableFor.system = true;
|
||||||
|
# "cacert.unbundled".enableFor.system = true;
|
||||||
|
cryptsetup.enableFor.system = true;
|
||||||
|
dig = {
|
||||||
|
enableFor.system = true;
|
||||||
|
suggestedPrograms = [ "efibootmgr" ];
|
||||||
|
};
|
||||||
|
efibootmgr = {};
|
||||||
|
fatresize = {};
|
||||||
|
|
||||||
|
backblaze-b2.enableFor.user.colin = true;
|
||||||
|
cdrtools = {
|
||||||
|
enableFor.user.colin = true;
|
||||||
|
suggestedPrograms = [ "dmidecode" ];
|
||||||
|
};
|
||||||
|
dmidecode = {};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
{ config, lib, pkgs, sane-lib, ... }:
|
{ config, lib, pkgs, sane-lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) elem map;
|
inherit (builtins) any elem map;
|
||||||
inherit (lib) mapAttrs mapAttrsToList mkDefault mkIf mkMerge mkOption optionalAttrs types;
|
inherit (lib) filterAttrs mapAttrs mapAttrsToList mkDefault mkIf mkMerge mkOption optionalAttrs types;
|
||||||
|
inherit (sane-lib) joinAttrsets;
|
||||||
cfg = config.sane.programs;
|
cfg = config.sane.programs;
|
||||||
pkgSpec = types.submodule ({ name, ... }: {
|
pkgSpec = types.submodule ({ name, ... }: {
|
||||||
options = {
|
options = {
|
||||||
|
@ -10,14 +11,29 @@ let
|
||||||
};
|
};
|
||||||
enableFor.system = mkOption {
|
enableFor.system = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = any (en: en) (
|
||||||
|
mapAttrsToList
|
||||||
|
(otherName: otherPkg:
|
||||||
|
otherName != name && elem name otherPkg.suggestedPrograms && otherPkg.enableSuggested && otherPkg.enableFor.system
|
||||||
|
)
|
||||||
|
cfg
|
||||||
|
);
|
||||||
description = ''
|
description = ''
|
||||||
place this program on the system PATH
|
place this program on the system PATH
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
enableFor.user = mkOption {
|
enableFor.user = mkOption {
|
||||||
type = types.attrsOf types.bool;
|
type = types.attrsOf types.bool;
|
||||||
default = {};
|
# default = mkMerge (mapAttrsToList (_otherName: otherPkg:
|
||||||
|
# optionalAttrs
|
||||||
|
# (otherPkg.enableSuggested && elem name otherPkg.suggestedPrograms)
|
||||||
|
# otherPkg.enableFor.user
|
||||||
|
# ) cfg);
|
||||||
|
default = joinAttrsets (mapAttrsToList (otherName: otherPkg:
|
||||||
|
optionalAttrs
|
||||||
|
(otherName != name && elem name otherPkg.suggestedPrograms && otherPkg.enableSuggested)
|
||||||
|
(filterAttrs (user: en: en) otherPkg.enableFor.user)
|
||||||
|
) cfg);
|
||||||
description = ''
|
description = ''
|
||||||
place this program on the PATH for some specified user(s).
|
place this program on the PATH for some specified user(s).
|
||||||
'';
|
'';
|
||||||
|
@ -49,30 +65,33 @@ let
|
||||||
config = {
|
config = {
|
||||||
# package can be inferred by the attr name, allowing shorthand like
|
# package can be inferred by the attr name, allowing shorthand like
|
||||||
# sane.packages.nano.enable = true;
|
# sane.packages.nano.enable = true;
|
||||||
pkg = mkIf (pkgs ? name) (mkDefault pkgs."${name}");
|
package = mkIf (pkgs ? "${name}") (mkDefault pkgs."${name}");
|
||||||
|
|
||||||
|
# enableFor = mkIf (name == "btrfs-progs") (mkDefault cfg.cryptsetup.enableFor);
|
||||||
|
|
||||||
# enable this package if it's in the `suggestedPrograms` of any other enabled program
|
# enable this package if it's in the `suggestedPrograms` of any other enabled program
|
||||||
enableFor = mkMerge (mapAttrsToList (_otherName: otherPkg:
|
# enableFor = mkMerge (mapAttrsToList (_otherName: otherPkg:
|
||||||
optionalAttrs
|
# optionalAttrs
|
||||||
(otherPkg.enableSuggested && elem name otherPkg.suggestedPrograms)
|
# (otherPkg.enableSuggested && elem name otherPkg.suggestedPrograms)
|
||||||
(mkDefault otherPkg.enableFor)
|
# (mkDefault otherPkg.enableFor)
|
||||||
) cfg);
|
# ) cfg);
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
toPkgSpec = types.coercedTo types.package (p: { pkg = p; }) pkgSpec;
|
toPkgSpec = types.coercedTo types.package (p: { package = p; }) pkgSpec;
|
||||||
|
|
||||||
configs = mapAttrsToList (_name: p: {
|
configs = mapAttrsToList (_name: p: {
|
||||||
# conditionally add to system PATH
|
# conditionally add to system PATH
|
||||||
environment.systemPackages = mkIf p.enableFor.system [ p.package ];
|
environment.systemPackages = mkIf p.enableFor.system [ p.package ];
|
||||||
# conditionally add to user(s) PATH
|
# conditionally add to user(s) PATH
|
||||||
users.users = mapAttrs (user: en: optionalAttrs en {
|
users.users = mapAttrs (user: en: optionalAttrs en {
|
||||||
packages = [ p ];
|
packages = [ p.package ];
|
||||||
}) p.enableFor.users;
|
}) p.enableFor.user;
|
||||||
# conditionally persist relevant user dirs
|
# conditionally persist relevant user dirs
|
||||||
sane.users = mapAttrs (user: en: optionalAttrs en {
|
sane.users = mapAttrs (user: en: optionalAttrs en {
|
||||||
persist.plaintext = p.dir;
|
persist.plaintext = p.dir;
|
||||||
persist.private = p.private;
|
persist.private = p.private;
|
||||||
}) p.enableFor.users;
|
}) p.enableFor.user;
|
||||||
}) cfg;
|
}) cfg;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -88,6 +107,25 @@ in
|
||||||
take = f: {
|
take = f: {
|
||||||
environment.systemPackages = f.environment.systemPackages;
|
environment.systemPackages = f.environment.systemPackages;
|
||||||
users.users = f.users.users;
|
users.users = f.users.users;
|
||||||
|
sane.users = f.sane.users;
|
||||||
};
|
};
|
||||||
in take (sane-lib.mkTypedMerge take configs);
|
in mkMerge [
|
||||||
|
(take (sane-lib.mkTypedMerge take configs))
|
||||||
|
{
|
||||||
|
# sane.programs.cryptsetup.enableFor = mkDefault cfg.btrfs-progs.enableFor;
|
||||||
|
# sane.programs.cryptsetup.enableFor = mkMerge (mapAttrsToList (otherName: otherPkg:
|
||||||
|
# optionalAttrs
|
||||||
|
# (otherName != "cryptsetup")
|
||||||
|
# (mkDefault otherPkg.enableFor)
|
||||||
|
# ) cfg);
|
||||||
|
|
||||||
|
# sane.programs = mapAttrs (myName: _me: optionalAttrs (myName == "btrfs-progs") {
|
||||||
|
# enableFor = mkMerge (mapAttrsToList (otherName: otherPkg:
|
||||||
|
# optionalAttrs
|
||||||
|
# (otherName != "cryptsetup")
|
||||||
|
# (mkDefault otherPkg.enableFor)
|
||||||
|
# ) cfg);
|
||||||
|
# }) cfg;
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user