1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-25 07:00:43 +00:00

Move escapeSystemdPath to lib/utils.nix

The new file ‘utils.nix’ is intended for NixOS-specific library
functions (i.e. stuff that shouldn't go into Nixpkgs' lib/).
This commit is contained in:
Eelco Dolstra 2012-10-12 17:01:49 -04:00
parent e8de4455ab
commit 3f6d53cc97
3 changed files with 19 additions and 7 deletions

View file

@ -31,6 +31,7 @@ rec {
inherit pkgs modules baseModules;
modulesPath = ../modules;
pkgs_i686 = import <nixpkgs> { system = "i686-linux"; };
utils = import ./utils.nix pkgs;
};
# Import Nixpkgs, allowing the NixOS option nixpkgs.config to

10
lib/utils.nix Normal file
View file

@ -0,0 +1,10 @@
pkgs: with pkgs.lib;
rec {
# Escape a path according to the systemd rules, e.g. /dev/xyzzy
# becomes dev-xyzzy. FIXME: slow.
escapeSystemdPath = s:
replaceChars ["/" "-"] ["-" "\\x2d"] (substring 1 (stringLength s) s);
}

View file

@ -1,6 +1,7 @@
{ config, pkgs, ... }:
{ config, pkgs, utils, ... }:
with pkgs.lib;
with utils;
{
@ -84,13 +85,13 @@ with pkgs.lib;
boot.systemd.services =
let
escapePath = s: # FIXME: slow
replaceChars ["/" "-"] ["-" "\\x2d"] (substring 1 (stringLength s) s);
createSwapDevice = sw: assert sw.device != ""; nameValuePair "mkswap-${escapePath sw.device}"
createSwapDevice = sw:
assert sw.device != "";
let device' = escapeSystemdPath sw.device; in
nameValuePair "mkswap-${escapeSystemdPath sw.device}"
{ description = "Initialisation of Swapfile ${sw.device}";
wantedBy = [ "${escapePath sw.device}.swap" ];
before = [ "${escapePath sw.device}.swap" ];
wantedBy = [ "${device'}.swap" ];
before = [ "${device'}.swap" ];
path = [ pkgs.utillinux ];
script =
''