Browse Source

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/).
nsd-state-dir
Eelco Dolstra 10 years ago
parent
commit
3f6d53cc97
  1. 1
      lib/eval-config.nix
  2. 10
      lib/utils.nix
  3. 15
      modules/config/swap.nix

1
lib/eval-config.nix

@ -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

@ -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);
}

15
modules/config/swap.nix

@ -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 =
''

Loading…
Cancel
Save