fs: allow specifying text for a symlink directly
This commit is contained in:
@@ -21,7 +21,7 @@ let
|
|||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
symlink = mkOption {
|
symlink = mkOption {
|
||||||
type = types.nullOr symlinkEntry;
|
type = types.nullOr (symlinkEntryFor name);
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
generated = mkOption {
|
generated = mkOption {
|
||||||
@@ -111,15 +111,25 @@ let
|
|||||||
# takes no special options
|
# takes no special options
|
||||||
dirEntry = types.submodule propagatedGenerateMod;
|
dirEntry = types.submodule propagatedGenerateMod;
|
||||||
|
|
||||||
symlinkEntry = types.submodule {
|
symlinkEntryFor = path: types.submodule ({ config, ...}: {
|
||||||
options = {
|
options = {
|
||||||
inherit (propagatedGenerateMod.options) acl;
|
inherit (propagatedGenerateMod.options) acl;
|
||||||
target = mkOption {
|
target = mkOption {
|
||||||
type = types.str;
|
type = types.coercedTo types.package toString types.str;
|
||||||
description = "fs path to link to";
|
description = "fs path to link to";
|
||||||
};
|
};
|
||||||
|
text = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = "create a file in the /nix/store with the provided text and use that as the target";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
config = {
|
||||||
|
target = lib.mkIf (config.text != null) (
|
||||||
|
pkgs.writeText (path-lib.leaf path) config.text
|
||||||
|
);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
generatedEntry = types.submodule {
|
generatedEntry = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@@ -6,14 +6,14 @@ let
|
|||||||
known_hosts_text = builtins.concatStringsSep
|
known_hosts_text = builtins.concatStringsSep
|
||||||
"\n"
|
"\n"
|
||||||
(builtins.attrValues (import ../pubkeys.nix).hosts);
|
(builtins.attrValues (import ../pubkeys.nix).hosts);
|
||||||
mkSymlink = target: {
|
mkSymlink = text: {
|
||||||
symlink.target = target;
|
symlink.text = text;
|
||||||
wantedBeforeBy = [ "multi-user.target" ];
|
wantedBeforeBy = [ "multi-user.target" ];
|
||||||
};
|
};
|
||||||
in lib.mkIf config.sane.home-manager.enable {
|
in lib.mkIf config.sane.home-manager.enable {
|
||||||
# ssh key is stored in private storage
|
# ssh key is stored in private storage
|
||||||
sane.persist.home.private = [ ".ssh/id_ed25519" ];
|
sane.persist.home.private = [ ".ssh/id_ed25519" ];
|
||||||
sane.fs."/home/colin/.ssh/id_ed25519.pub" = mkSymlink (builtins.toString (pkgs.writeText "id_ed25519.pub" user_pubkey));
|
sane.fs."/home/colin/.ssh/id_ed25519.pub" = mkSymlink user_pubkey;
|
||||||
|
|
||||||
home-manager.users.colin = {
|
home-manager.users.colin = {
|
||||||
programs.ssh.enable = true;
|
programs.ssh.enable = true;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
{ lib, utils, ... }:
|
{ lib, utils, ... }:
|
||||||
|
|
||||||
let path = rec {
|
let path = rec {
|
||||||
|
|
||||||
# split the string path into a list of string components.
|
# split the string path into a list of string components.
|
||||||
# root directory "/" becomes the empty list [].
|
# root directory "/" becomes the empty list [].
|
||||||
# implicitly performs normalization so that:
|
# implicitly performs normalization so that:
|
||||||
@@ -19,6 +20,10 @@ let path = rec {
|
|||||||
hasParent = str: (path.parent str) != (path.norm str);
|
hasParent = str: (path.parent str) != (path.norm str);
|
||||||
# return the path from `from` to `to`, but keeping absolute form
|
# return the path from `from` to `to`, but keeping absolute form
|
||||||
# e.g. `pathFrom "/home/colin" "/home/colin/foo/bar"` -> "/foo/bar"
|
# e.g. `pathFrom "/home/colin" "/home/colin/foo/bar"` -> "/foo/bar"
|
||||||
|
|
||||||
|
# return the last path component; error on the empty path
|
||||||
|
leaf = str: lib.last (split str);
|
||||||
|
|
||||||
from = start: end: let
|
from = start: end: let
|
||||||
s = path.norm start;
|
s = path.norm start;
|
||||||
e = path.norm end;
|
e = path.norm end;
|
||||||
|
Reference in New Issue
Block a user