forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
joinPath = p: | ||
builtins.concatStringsSep "/" ([ "" ] ++ p); | ||
joinLines = | ||
builtins.concatStringsSep "\n"; | ||
|
||
mkScript = links: joinLines (forEach links (link: let | ||
source = link.source; | ||
target = "/${link.target}"; | ||
in | ||
'' | ||
mkdir -p "$(dirname ${escapeShellArg target})" | ||
ln -s ${escapeShellArgs [source target]} | ||
'')); | ||
in | ||
{ | ||
options = { | ||
environment.links = mkOption { | ||
description = "Links to create"; | ||
default = {}; | ||
|
||
type = with types; loaOf (submodule ( | ||
{ name, config, ... }: | ||
{ options = { | ||
enable = mkOption { | ||
type = types.bool; | ||
default = true; | ||
description = '' | ||
Whether this link should be generated. This | ||
option allows specific links to be disabled. | ||
''; | ||
}; | ||
|
||
target = mkOption { | ||
type = types.str; | ||
description = '' | ||
Path of the symlink. Defaults to the | ||
attribute name. | ||
''; | ||
}; | ||
|
||
source = mkOption { | ||
type = types.path; | ||
description = "Path of the source file."; | ||
}; | ||
}; | ||
|
||
config = { | ||
target = mkDefault name; | ||
}; | ||
|
||
})); | ||
}; | ||
}; | ||
|
||
config = (let | ||
links' = filter (f: f.enable) (attrValues config.environment.links); | ||
in | ||
mkIf (links' != []) | ||
{ | ||
system.activationScripts.links = { | ||
text = mkScript links'; | ||
deps = [ ]; # FIXME: add correct deps | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters