-
Notifications
You must be signed in to change notification settings - Fork 2
/
use-from-nixos.nix
40 lines (34 loc) · 1.71 KB
/
use-from-nixos.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{pkgs ? import <nixpkgs> {}, nixos ? import <nixpkgs/nixos>}:
rec {
nixosFun = config: (nixos {configuration = config // { system = {stateVersion = "99.99"; }//(config.system or {}); };});
serviceScript = name: config:
(builtins.getAttr name (nixosFun config).config.systemd.services).runner;
etcSelectTarget = filename: config:
let
nixosInstance = nixosFun config;
selected = (pkgs.lib.filterAttrs (k: v: v.target == filename) nixosInstance.config.environment.etc);
source = if selected == {} then null else (builtins.getAttr (builtins.head (builtins.attrNames selected)) selected).source;
in (if source == null then null else if pkgs.lib.isString source then source else source.outPath);
etcSelectRenamed = newName: filename: config:
let target = etcSelectTarget filename config; in
if target == null then {} else builtins.listToAttrs [{name= newName; value= target;}];
etcSelectComponent = filename: config:
etcSelectRenamed filename filename config;
etcSelectComponents = filenames: config:
if filenames == [] then {} else
pkgs.lib.foldr (a: b: a//b) {}
(builtins.map (fn: etcSelectComponent fn config) filenames);
etcSelectPrefix = filenamePrefix: config:
let
nixosInstance = nixosFun config;
selected = (pkgs.lib.filterAttrs
(k: v: pkgs.lib.hasPrefix filenamePrefix v.target)
nixosInstance.config.environment.etc);
in (pkgs.lib.mapAttrs'
(k: v: let source = v.source; in
{
value = (if pkgs.lib.isString source then source else source.outPath);
name = v.target;
})
selected);
}