diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 43 | ||||
-rw-r--r-- | lib/types/populate.nix | 91 |
2 files changed, 121 insertions, 13 deletions
diff --git a/lib/default.nix b/lib/default.nix index 48e005e..3bbd754 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -28,13 +28,23 @@ let { # This function's return value can be used as pkgs.populate input. source: sanitize (eval source).config.source; - getHostName = let + maybeHostName = default: let # We're parsing /etc/hostname here because reading # /proc/sys/kernel/hostname yields "" - y = lib.filter lib.types.label.check (lib.splitString "\n" (lib.readFile /etc/hostname)); + path = "/etc/hostname"; + lines = lib.splitString "\n" (lib.readFile path); + hostNames = lib.filter lib.types.label.check lines; in - if lib.length y != 1 then throw "malformed /etc/hostname" else - lib.elemAt y 0; + if lib.pathExists path then + if lib.length hostNames == 1 then + lib.head hostNames + else + lib.trace "malformed ${path}" default + else + default; + + firstWord = s: + lib.head (lib.match "^([^[:space:]]*).*" s); isLocalTarget = let origin = lib.mkTarget ""; @@ -43,15 +53,26 @@ let { lib.elem target.host [origin.host "localhost"]; mkTarget = s: let - default = defVal: val: if val != null then val else defVal; - parse = lib.match "(([^@]+)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s; + parse = lib.match "(([^@]*)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s; elemAt' = xs: i: if lib.length xs > i then lib.elemAt xs i else null; + filterNull = lib.filterAttrs (n: v: v != null); in { - user = default (lib.getEnv "LOGNAME") (elemAt' parse 1); - host = default (lib.maybeEnv "HOSTNAME" lib.getHostName) (elemAt' parse 3); - port = default "22" /* "ssh"? */ (elemAt' parse 5); - path = default "/var/src" /* no default? */ (elemAt' parse 6); - }; + user = lib.maybeEnv "LOGNAME" null; + host = lib.maybeEnv "HOSTNAME" (lib.maybeHostName "localhost"); + port = null; + path = "/var/src"; + sudo = false; + extraOptions = []; + } // (if lib.isString s then filterNull { + user = elemAt' parse 1; + host = elemAt' parse 3; + port = elemAt' parse 5; + path = elemAt' parse 6; + } else s); + + mkUserPortSSHOpts = target: + (lib.optionals (target.user != null) ["-l" target.user]) ++ + (lib.optionals (target.port != null) ["-p" target.port]); shell = let isSafeChar = lib.testString "[-+./0-9:=A-Z_a-z]"; diff --git a/lib/types/populate.nix b/lib/types/populate.nix index 49996f6..6264f99 100644 --- a/lib/types/populate.nix +++ b/lib/types/populate.nix @@ -21,11 +21,15 @@ }; file = lib.mkOption { apply = x: - if lib.types.absolute-pathname.check x + if lib.types.absolute-pathname.check x || lib.types.package.check x then { path = x; } else x; default = null; - type = lib.types.nullOr (lib.types.either lib.types.absolute-pathname source-types.file); + type = lib.types.nullOr (lib.types.oneOf [ + lib.types.absolute-pathname + lib.types.package + source-types.file + ]); }; git = lib.mkOption { default = null; @@ -35,6 +39,17 @@ default = null; type = lib.types.nullOr source-types.pass; }; + passage = lib.mkOption { + apply = x: + if lib.types.pathname.check x + then { dir = x; } + else x; + default = null; + type = lib.types.nullOr (lib.types.oneOf [ + lib.types.pathname + source-types.passage + ]); + }; pipe = lib.mkOption { apply = x: if lib.types.absolute-pathname.check x @@ -54,6 +69,18 @@ }; }); + filter = lib.types.submodule { + options = { + type = lib.mkOption { + type = lib.types.enum ["include" "exclude"]; + default = "exclude"; + }; + pattern = lib.mkOption { + type = lib.types.str; + }; + }; + }; + source-types = { derivation = lib.types.submodule { options = { @@ -71,6 +98,43 @@ default = false; type = lib.types.bool; }; + exclude = lib.mkOption { + apply = x: + if x != [] then + lib.warn + "file.*.exclude is deprecated in favor of file.*.filters" + x + else + x; + description = '' + DEPRECATED, use `filters`. + ''; + type = lib.types.listOf lib.types.str; + default = []; + example = [".git"]; + }; + filters = lib.mkOption { + type = lib.types.listOf filter; + default = []; + example = [ + { + type = "include"; + pattern = "*.nix"; + } + { + type = "include"; + pattern = "*/"; + } + { + type = "exclude"; + pattern = "*"; + } + ]; + }; + deleteExcluded = lib.mkOption { + default = true; + type = lib.types.bool; + }; }; }; git = lib.types.submodule { @@ -81,12 +145,20 @@ type = lib.types.listOf lib.types.str; }; }; + fetchAlways = lib.mkOption { + type = lib.types.bool; + default = false; + }; ref = lib.mkOption { type = lib.types.str; # TODO lib.types.git.ref }; url = lib.mkOption { type = lib.types.str; # TODO lib.types.git.url }; + shallow = lib.mkOption { + default = false; + type = lib.types.bool; + }; }; }; pass = lib.types.submodule { @@ -99,6 +171,21 @@ }; }; }; + passage = lib.types.submodule { + options = { + age = lib.mkOption { + default = "age"; + type = lib.types.pathname; + }; + dir = lib.mkOption { + type = lib.types.pathname; + }; + identities_file = lib.mkOption { + default = toString ~/.passage/identities; + type = lib.types.pathname; + }; + }; + }; pipe = lib.types.submodule { options = { command = lib.mkOption { |